Skip to content

Commit

Permalink
[Feature] Usability improvement in ExperimentConfig (#174)
Browse files Browse the repository at this point in the history
* Add experiment config validation and doc.

Ensure user can only define one of max_n_frames or max_n_iters when
validating an experiment config.

* fix formatting
  • Loading branch information
itwasabhi authored Feb 11, 2025
1 parent 49c1c17 commit b07f070
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions benchmarl/experiment/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ def validate(self, on_policy: bool):
if self.keep_checkpoints_num is not None and self.keep_checkpoints_num <= 0:
raise ValueError("keep_checkpoints_num must be greater than zero or null")
if self.max_n_frames is None and self.max_n_iters is None:
raise ValueError("n_iters and total_frames are both not set")
raise ValueError("max_n_frames and max_n_iters are both not set")
if self.max_n_frames is not None and self.max_n_iters is not None:
raise ValueError("max_n_frames and max_n_iters cannot both be set")


class Experiment(CallbackNotifier):
Expand All @@ -309,7 +311,10 @@ class Experiment(CallbackNotifier):
algorithm_config (AlgorithmConfig): the algorithm configuration
model_config (ModelConfig): the policy model configuration
seed (int): the seed for the experiment
config (ExperimentConfig): the experiment config
config (ExperimentConfig): The experiment config. Note that some of the parameters
of this config may go un-consumed based on the provided algorithm or model config.
For example, all parameters off-policy algorithm would not be used when running
an experiment with an on-policy algorithm.
critic_model_config (ModelConfig, optional): the policy model configuration.
If None, it defaults to model_config
callbacks (list of Callback, optional): callbacks for this experiment
Expand Down
1 change: 1 addition & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def experiment_config(tmp_path) -> ExperimentConfig:
experiment_config: ExperimentConfig = ExperimentConfig.get_from_yaml()
experiment_config.save_folder = str(save_dir)
experiment_config.max_n_iters = 3
experiment_config.max_n_frames = None

experiment_config.on_policy_n_minibatch_iters = 1
experiment_config.on_policy_minibatch_size = 2
Expand Down

0 comments on commit b07f070

Please sign in to comment.