New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add evaluation environment specs to dataset metadata #155
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good @rodrigodelazcano, thank you also for refactoring the utils file!
I just added few minors comments
docs/_scripts/gen_dataset_md.py
Outdated
env_spec = EnvSpec.from_json(dataset_spec["env_spec"]) | ||
env = gym.make(env_spec.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we support env_spec = None here? You can do a similar workflow you did for eval_env_spec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we can. Will it be more helpful to wait for this PR #137 to be merged and then I can try to rebase the functionality in this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, never mind, this is for the docs only. I'll start working on the env_spec=None case as well
docs/_scripts/gen_dataset_md.py
Outdated
|ID| `{env_id}`| | ||
| Action Space | `{re.sub(' +', ' ', action_space_table)}` | | ||
|ID| `{env_spec.id}`| | ||
| Observation Space | `{re.sub(' +', ' ', observation_space_table)}` | | ||
|
||
| Action Space | `{re.sub(' +', ' ', action_space_table)}` | | ||
| entry_point | `{env_spec.entry_point}` | | ||
| max_episode_steps | `{env_spec.max_episode_steps}` | | ||
| reward_threshold | `{env_spec.reward_threshold}` | | ||
| nondeterministic | `{env_spec.nondeterministic}` | | ||
| order_enforce | `{env_spec.order_enforce}`| | ||
| autoreset | `{env_spec.autoreset}` | | ||
| disable_env_checker | `{env_spec.disable_env_checker}` | | ||
| kwargs | `{env_spec.kwargs}` | | ||
| additional_wrappers | `{env_spec.additional_wrappers}` | | ||
| vector_entry_point | `{env_spec.vector_entry_point}` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can probably factorize this to a function describe_env
, to use for env_spec and eval_env_spec. This can also handle the None case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea! I'll refactorize this part
minari/dataset/minari_dataset.py
Outdated
if eval_env and self._eval_env_spec is not None: | ||
return gym.make(self._eval_env_spec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a message to the logger (INFO level?) in case eval_env and _eval_env_spec=None.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeap, agree. I will add this.
44ae214
to
069b635
Compare
I've removed flake8:E272 in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; I think there are just two typos, then we can merge
9f0356b
to
063cf65
Compare
Description
NOTE: this PR might have conflicts with this one: #137
Some datasets can be targeted for evaluation in an environment with different specifications than the environment used to collect the episodes of the dataset. This is the case of the Maze environments in D4RL (Ant/Point).
This PR adds an additional and optional metadata key to store separate specifications for the evaluation environment,
eval_env_spec
. Main changes are:eval_env
is an argument that can be passed during dataset creation (collector env and buffer) as astr
dataset id,gym.Env
orEnvSpec
.eval_env
will also be used to computeref_min_score
orref_max_score
when required.create_dataset_from_buffers()
andcreate_dataset_from_collector_env()
have been merged into two separate functions:_generate_dataset_path()
and_generate_dataset_metadata()
.recover_environment()
function in everyMinariDataset
,eval_env
. Ifeval_env
is set toTrue
and theeval_env_spec
metadata key is present in the dataset, agym.Env
instance of the evaluation environment will be returned. Otherwise, the environment used for collecting the dataset is returned.eval_env
with the different allowed types.Dataset updates
In this PR I'm also including the AntMaze datasets and updating PointMaze to include
eval_env
(these datasets have been already uploaded to GCP). The scripts will be updated to add the evaluation environments in both sets of datasets in the following PR's:AntMaze - rodrigodelazcano/d4rl-minari-dataset-generation#4
PointMaze - rodrigodelazcano/d4rl-minari-dataset-generation#3
Doc updates
Aside from adding the documentation for AntMaze datasets, this PR expands the documentation of each individual dataset by including in the table all of the specifications of a Gymnasium environment , another table for the evaluation environment specs, and notes to explain how to recover the environments. All of these docs are generated automatically. Example of the docs environment specs and note if no evaluation environment is found for the dataset:
Checklist:
pre-commit
checks withpre-commit run --all-files
(seeCONTRIBUTING.md
instructions to set it up)pytest -v
and no errors are present.pytest -v
has generated that are related to my code to the best of my knowledge.