Skip to main content

Variables

  • INTEGRATION_VERSION_KEY: Key under which the version of the Neptune-Optuna integration is logged in Neptune. Set to the value of source_code/integrations/neptune-optuna.

log_study_metadata

log_study_metadata(
    study: optuna.study.study.Study,
    run: neptune.metadata_containers.run.Run,
    base_namespace='',
    log_plots=True,
    log_study=True,
    log_all_trials=True,
    log_distributions=True,
    visualization_backend='plotly',
    log_plot_contour=True,
    log_plot_edf=True,
    log_plot_parallel_coordinate=True,
    log_plot_param_importances=True,
    log_plot_pareto_front=True,
    log_plot_slice=True,
    log_plot_intermediate_values=True,
    log_plot_optimization_history=True,
    target_names: List[str| None = None,
)
Logs the metadata from the Optuna study to Neptune. With this function, you can log and display:
  • Values and params for each trial.
  • Current best values and params for the study.
  • Visualizations from the optuna.visualizations module.
  • Parameter distributions for each trial.
  • The study object itself, to load it later.
Parameters:
NameTypeDefaultDescription
studyoptuna.Study--Optuna study object.
runneptune.Run--Neptune run.
base_namespacestr""Namespace inside the run where your study metadata is logged.
log_plotsboolTrueIf True, the visualizations from optuna.visualizations will be logged to Neptune.
log_studyboolTrueIf True, the study will be logged to Neptune. The objects that are logged depend
log_all_trialsboolTrueIf True, all trials are logged.
log_distributionsboolTrueIf True, the distributions for all trials are logged.
visualization_backendstr"plotly"Which visualization backend is used for ‘optuna.visualizations’ plots.
log_plot_contourboolTrueIf True the optuna.visualizations.plot_contour visualization will be logged to Neptune.
log_plot_edfboolTrueIf True the optuna.visualizations.plot_edf visualization will be logged to Neptune.
log_plot_parallel_coordinateboolTrueIf True the optuna.visualizations.plot_parallel_coordinate visualization will be logged to Neptune.
log_plot_param_importancesboolTrueIf True the optuna.visualizations.plot_param_importances visualization will be logged to Neptune.
log_plot_pareto_frontboolTrueIf True the optuna.visualizations.plot_pareto_front visualization will be logged to Neptune.
log_plot_sliceboolTrueIf True, the optuna.visualizations.plot_slice visualization will be logged to Neptune.
log_plot_intermediate_valuesboolTrueIf True, the optuna.visualizations.plot_intermediate_values visualization will be logged to Neptune.
log_plot_optimization_historyboolTrueIf True, the optuna.visualizations.plot_optimization_history visualization will be logged to Neptune.
target_nameslist--of str, default None List of one or more study objective names to log (see example).
Examples: Initialize a Neptune run and log Optuna study metadata:
>>> import neptune
>>> run = neptune.init_run()
Create and run the study:
>>> study = optuna.create_study(direction="maximize")
>>> study.optimize(objective, n_trials=5)
Log single and multi-objective study metadata to Neptune:
>>> import neptune.integrations.optuna as npt_utils
>>> npt_utils.log_study_metadata(study, run)
Or optionally pass a list of one or more objective names:
... npt_utils.log_study_metadata(
...     study,
...     run,
...     target_names=["FLOPS", "accuracy"],
... )
For more, see the Neptune-Optuna Integration Guide.

load_study_from_run

load_study_from_run(
    run: neptune.metadata_containers.run.Run,
)
Loads Optuna study from an existing Neptune run. Loading mechanics depend on the study storage type used during the run:
  • If the study used ‘InMemoryStorage’, it will be loaded from the logged pickled study object.
  • If the study used database storage, it will be loaded from the logged database URL.
To resume an existing run, you need the run ID. It is stored in the run’s “sys/id” field. Parameters:
NameTypeDefaultDescription
runneptune.Run--Neptune run.
Examples: Initialize an existing run by passing the run ID:
>>> import neptune
>>> run = neptune.init_run(with_id="PRO-123")
Load study from the run and continue optimization:
>>> import neptune.integrations.optuna as npt_utils
>>> study = npt_utils.load_study_from_run(run)
>>> study.optimize(objective, n_trials=20)
For more, see the Neptune-Optuna Integration Guide.

NeptuneCallback

NeptuneCallback(
    run: neptune.metadata_containers.run.Run | neptune.handler.Handler,
    base_namespace: str = '',
    plots_update_freq: int | str = 1,
    study_update_freq: int | str = 1,
    visualization_backend: str = 'plotly',
    log_plot_contour: bool = True,
    log_plot_edf: bool = True,
    log_plot_parallel_coordinate: bool = True,
    log_plot_param_importances: bool = True,
    log_plot_pareto_front: bool = True,
    log_plot_slice: bool = True,
    log_plot_intermediate_values: bool = True,
    log_plot_optimization_history: bool = True,
    target_names: List[str| None = None,
    log_all_trials: bool = True,
)
A callback that logs metadata from an Optuna Study to Neptune. With this callback, you can log and display:
  • Values and parameters for each trial.
  • Current best values and parameters for the study.
  • Visualizations from the optuna.visualizations module.
  • Parameter distributions for each trial.
  • The study object itself, to load it later.
Parameters:
NameTypeDefaultDescription
runneptune.Run--Neptune run object. You can also pass a namespace handler object; for example, run["test"], in which case all metadata is logged under the “test” namespace.
base_namespacestr""Namespace inside the run where your study metadata is logged.
plots_update_freqint1Frequency at which plots are logged and updated in Neptune. If you pass an integer k, plots will be updated every k iterations. If you pass the string ‘never’, plots will not be logged.
study_update_freqint1Frequency at which a study object is logged and updated in Neptune. If you pass an integer k, the study will be updated every k iterations. If you pass the string ‘never’, the study will not be logged.
visualization_backendstrplotlyWhich visualization backend is used for optuna.visualizations plots. Can be either ‘matplotlib’ or ‘plotly’.
log_plot_contourboolTrueIf True, the optuna.visualizations.plot_contour visualization will be logged to Neptune.
log_plot_edfboolTrueIf True, the optuna.visualizations.plot_edf visualization will be logged to Neptune.
log_plot_parallel_coordinateboolTrueIf True, the optuna.visualizations.plot_parallel_coordinate visualization will be logged to Neptune.
log_plot_param_importancesboolTrueIf True, the optuna.visualizations.plot_param_importances visualization will be logged to Neptune.
log_plot_pareto_frontboolTrueIf True, the optuna.visualizations.plot_pareto_front visualization will be logged to Neptune. If your optuna.study is not multi-objective, this plot is not logged.
log_plot_sliceboolTrueIf True, the optuna.visualizations.plot_slice visualization will be logged to Neptune.
log_plot_intermediate_valuesboolTrueIf True, the plot_intermediate_values visualization will be logged to Neptune. If your optuna.study is not using pruners, this plot is not logged.
log_plot_optimization_historyboolTrueIf True, the plot_optimization_history visualization will be logged to Neptune.
target_namestp.List[str]NoneList of one or more study objective names to log (see example).
log_all_trialsboolTrueIf `True, all trials are logged. Defaults to True.
Examples: Initialize a Neptune run and log Optuna study metadata.
>>> import neptune
>>> run = neptune.init_run()
Initialize a NeptuneCallback:
>>> import neptune.integrations.optuna as npt_utils
>>> neptune_callback = npt_utils.NeptuneCallback(run)
Or optionally pass a list of one or more objective names:
... neptune_callback = npt_utils.NeptuneCallback(
...     run,
...     target_names=["FLOPS", "accuracy"],
... )
Log single and multi-objective study metadata to Neptune by passing the callback to the Optuna Study:
>>> study = optuna.create_study(direction="maximize")
>>> study.optimize(objective, n_trials=5, callbacks=[neptune_callback])
For more, see the Neptune-Optuna Integration Guide.

Descendants

  • systematica.tuners.base.BaseCustomNeptuneCallback