scvi.autotune.AutotuneExperiment#

class scvi.autotune.AutotuneExperiment(model_cls, data, metrics, mode, search_space, num_samples, scheduler='asha', searcher='hyperopt', seed=None, resources=None, experiment_name=None, logging_dir=None, save_checkpoints=False, scheduler_kwargs=None, searcher_kwargs=None, scib_stage='train_end', scib_subsample_rows=5000, scib_indices_list=None, n_jobs=1, solver='arpack', mudata_file_name='mydata.h5mu')[source]#

Track hyperparameter tuning experiments.

Parameters:
model_cls BaseModelClass

Model class on which to tune hyperparameters. Must implement a constructor and a train method.

data AnnData | MuData | LightningDataModule

AnnData or MuData that has been set up with model_cls or a LightningDataModule.

metrics str | list[str]

Either a single metric or a list of metrics to track during the experiment. If a list is provided, the primary metric will be the first element in the list.

mode Literal['min', 'max']

Optimization mode for the primary metric. One of "min" or "max".

search_space dict[str, dict[Literal['model_params', 'train_params'], dict[str, Any]]]

Dictionary of hyperparameter names and their respective search spaces. See the API for available search specifications. Must only contain the following top-level keys:

  • "model_params": parameters to pass to the model constructor.

  • "train_params": parameters to pass to the model’s train method.

Passed into Tuner as param_space.

num_samples int

Total number of hyperparameter configurations to sample from the search space. Passed into TuneConfig.

scheduler Literal['asha', 'hyperband', 'median', 'fifo'] (default: 'asha')

Ray Tune scheduler to use. One of the following:

Configured with reasonable defaults, which can be overridden with scheduler_kwargs.

searcher Literal['hyperopt', 'random'] (default: 'hyperopt')

Ray Tune search algorithm to use. One of the following:

Configured with reasonable defaults, which can be overridden with searcher_kwargs.

seed int | None (default: None)

Random seed to use for the experiment. Propagated to scvi.settings.seed and search algorithms. If not provided, defaults to scvi.settings.seed.

resources dict[Literal['cpu', 'gpu', 'memory'], float] | None (default: None)

Dictionary of resources to allocate per trial in the experiment. Available keys include:

  • "cpu": number of CPU cores

  • "gpu": number of GPUs

  • "memory": amount of memory

Passed into with_resources().

experiment_name str | None (default: None)

Name of the experiment, used for logging purposes. Defaults to a unique ID.

logging_dir str | None (default: None)

Base directory to store experiment logs. Defaults to logging_dir.

save_checkpoints bool (default: False)

If True, checkpoints will be saved and reported to Ray. Default False.

scheduler_kwargs dict | None (default: None)

Additional keyword arguments to pass to the scheduler.

searcher_kwargs dict | None (default: None)

Additional keyword arguments to pass to the search algorithm.

scib_stage str | None (default: 'train_end')

Used when performing scib-metrics tune, select whether to perform on validation (default) or training end.

scib_subsample_rows int | None (default: 5000)

Used when performing scib-metrics tune, select the number of rows to subsample (100 default). This is important to save computation time

scib_indices_list list | None (default: None)

If not empty will be used to select the indices to calc the scib metric on, otherwise will use the random indices selection in size of scib_subsample_rows

n_jobs int (default: 1)

Number of jobs to use for parallelization of neighbor search.

solver str (default: 'arpack')

SVD solver to use during PCA. It can help stability issues. Choose from: “arpack”, “randomized” or “auto”

mudata_file_name str (default: 'mydata.h5mu')

name of the mudata file. can be a full path, but will not create folders

Notes

Lifecycle: beta

See also

run_autotune()

Attributes table#

data

Data on which to tune hyperparameters.

experiment_name

Name of the experiment.

id

Unique identifier for the experiment.

logging_dir

Base directory to store experiment logs.

metrics

Metrics to track during the experiment.

metrics_callback

mode

Optimization mode for the primary metric.

model_cls

Model class on which to tune hyperparameters.

num_samples

Total number of hyperparameter configurations to sample.

resources

Resources to allocate per trial in the experiment.

result_grid

Result grid for the experiment.

scheduler

Ray Tune scheduler to use.

scheduler_kwargs

Additional keyword arguments to pass to the scheduler.

scib_metrics_callback

search_space

Search space for hyperparameters.

searcher

Ray Tune search algorithm to use.

searcher_kwargs

Additional keyword arguments to pass to the search algorithm.

seed

Random seed to use for the experiment.

setup_method_args

Keyword arguments for the setup method.

setup_method_name

Either "setup_anndata" or "setup_mudata".

Methods table#

get_logger(trial_name)

Configure TensorBoard logger for a trial in this experiment.

get_tuner()

Configure a Tuner from this experiment.

Attributes#

AutotuneExperiment.data#

Data on which to tune hyperparameters.

AutotuneExperiment.experiment_name#

Name of the experiment.

AutotuneExperiment.id#

Unique identifier for the experiment.

AutotuneExperiment.logging_dir#

Base directory to store experiment logs.

AutotuneExperiment.metrics#

Metrics to track during the experiment.

AutotuneExperiment.metrics_callback#
AutotuneExperiment.mode#

Optimization mode for the primary metric.

AutotuneExperiment.model_cls#

Model class on which to tune hyperparameters.

AutotuneExperiment.num_samples#

Total number of hyperparameter configurations to sample.

AutotuneExperiment.resources#

Resources to allocate per trial in the experiment.

AutotuneExperiment.result_grid#

Result grid for the experiment.

AutotuneExperiment.scheduler#

Ray Tune scheduler to use.

AutotuneExperiment.scheduler_kwargs#

Additional keyword arguments to pass to the scheduler.

AutotuneExperiment.scib_metrics_callback#
AutotuneExperiment.search_space#

Search space for hyperparameters.

AutotuneExperiment.searcher#

Ray Tune search algorithm to use.

AutotuneExperiment.searcher_kwargs#

Additional keyword arguments to pass to the search algorithm.

AutotuneExperiment.seed#

Random seed to use for the experiment.

AutotuneExperiment.setup_method_args#

Keyword arguments for the setup method.

AutotuneExperiment.setup_method_name#

Either "setup_anndata" or "setup_mudata".

Methods#

AutotuneExperiment.get_logger(trial_name)[source]#

Configure TensorBoard logger for a trial in this experiment.

Return type:

TensorBoardLogger

AutotuneExperiment.get_tuner()[source]#

Configure a Tuner from this experiment.

Return type:

Tuner