code: def write_h5ad(
          self,
          filename: Optional[PathLike] = None,
          compression: Optional[str] = None,
          compression_opts: Union[int, Any] = None,
          force_dense: Optional[bool] = None
      ):
          
          from .readwrite.write import _write_h5ad
  
          if filename is None and not self.isbacked:
              raise ValueError('Provide a filename!')
          if filename is None:
              filename = self.filename
          if force_dense is None:
              force_dense = self.isbacked
  
          _write_h5ad(filename, self, compression=compression,
                      compression_opts=compression_opts, force_dense=force_dense)
  
          if self.isbacked:
              self.file.close()
docs: Write ``.h5ad``-formatted hdf5 file.
  
          .. note::
  
              Setting compression to ``'gzip'`` can save disk space but
              will slow down writing and subsequent reading. Prior to
              v0.6.16, this was the default for parameter
              ``compression``.
  
          Generally, if you have sparse data that are stored as a dense
          matrix, you can dramatically improve performance and reduce
          disk space by converting to a :class:`~scipy.sparse.csr_matrix`::
  
              from scipy.sparse import csr_matrix
              adata.X = csr_matrix(adata.X)
  
          Parameters
          ----------
          filename
              Filename of data file. Defaults to backing file.
          compression : ``None``,  {``'gzip'``, ``'lzf'``} (default: ``None``)
              See the h5py :ref:`dataset_compression`.
          compression_opts
              See the h5py :ref:`dataset_compression`.
          force_dense
              Write sparse data as a dense matrix. Defaults to ``True`` if object is
              backed, otherwise to ``False``.