cambrian.ml.callbacks

Callbacks used during training and/or evaluation.

Classes

MjCambrianPlotMonitorCallback

Should be used with an EvalCallback to plot the evaluation results.

MjCambrianEvalCallback

Overwrites the default EvalCallback to support saving visualizations at the same

MjCambrianGPUUsageCallback

This callback will log the GPU usage at the end of each evaluation.

MjCambrianSavePolicyCallback

Should be used with an EvalCallback to save the policy.

MjCambrianProgressBarCallback

Overwrite the default progress bar callback to flush the pbar on deconstruct.

MjCambrianCallbackListWithSharedParent

Class for chaining callbacks.

MjCambrianSaveConfigCallback

This callback will save the resolved hydra config to the logdir.

Module Contents

class MjCambrianPlotMonitorCallback(logdir, filename, n_episodes=1)[source]

Bases: stable_baselines3.common.callbacks.BaseCallback

Should be used with an EvalCallback to plot the evaluation results.

This callback will take the monitor.csv file produced by the VecMonitor and plot the results and save it as an image. Should be passed as the callback_after_eval for the EvalCallback.

Parameters:
  • logdir (Path | str) – The directory where the evaluation results are stored. The evaluations.npz file is expected to be at <logdir>/<filename>.csv. The resulting plot is going to be stored at <logdir>/evaluations/<filename>.png.

  • filename (Path | str) – The filename of the monitor file. The saved file will be <logdir>/<filename>.csv. And the resulting plot will be saved as <logdir>/evaluations/<filename>.png.

class MjCambrianEvalCallback(eval_env, callback_on_new_best=None, callback_after_eval=None, n_eval_episodes=5, eval_freq=10000, log_path=None, best_model_save_path=None, deterministic=True, render=False, verbose=1, warn=True)[source]

Bases: stable_baselines3.common.callbacks.EvalCallback

Overwrites the default EvalCallback to support saving visualizations at the same time as the evaluation.

Note

Only the first environment is visualized

class MjCambrianGPUUsageCallback(logdir, logfile='gpu_usage.csv', *, verbose=0)[source]

Bases: stable_baselines3.common.callbacks.BaseCallback

This callback will log the GPU usage at the end of each evaluation. We’ll log to a csv.

class MjCambrianSavePolicyCallback(logdir, *, verbose=0)[source]

Bases: stable_baselines3.common.callbacks.BaseCallback

Should be used with an EvalCallback to save the policy.

This callback will save the policy at the end of each evaluation. Should be passed as the callback_after_eval for the EvalCallback.

Parameters:

logdir (Path | str) – The directory to store the generated visualizations. The resulting visualizations are going to be stored at <logdir>/evaluations/visualization.gif.

class MjCambrianProgressBarCallback[source]

Bases: stable_baselines3.common.callbacks.ProgressBarCallback

Overwrite the default progress bar callback to flush the pbar on deconstruct.

__del__()[source]

This string will restore the terminal back to its original state.

class MjCambrianCallbackListWithSharedParent(callbacks)[source]

Bases: stable_baselines3.common.callbacks.CallbackList

Class for chaining callbacks.

Parameters:

callbacks – A list of callbacks that will be called sequentially.

class MjCambrianSaveConfigCallback[source]

Bases: hydra.experimental.callbacks.Callback

This callback will save the resolved hydra config to the logdir.

on_run_start(config, **kwargs)[source]

Called in RUN mode before job/application code starts. config is composed with overrides. Some hydra.runtime configs are not populated yet. See hydra.core.utils.run_job for more info.

on_multirun_start(config, **kwargs)[source]

Called in MULTIRUN mode before any job starts. When using a launcher, this will be executed on local machine before any Sweeper/Launcher is initialized.