Skip to content
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

Deprecate create_dataset_from_collector_env #169

Merged

Conversation

avjmachine
Copy link
Contributor

@avjmachine avjmachine commented Nov 24, 2023

Description

  • Move the function `minari.create_dataset_from_collector_env() to env.create_dataset(). Add deprecation warning for the same.
  • Add deprecation warning for making env.save_to_disk private.
    Both changes planned for release 0.5.0

Fixes # (issue), Depends on # (pull request)

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Screenshots

N/A

Checklist:

  • I have run the pre-commit checks with pre-commit run --all-files (see CONTRIBUTING.md instructions to set it up)
  • I have run pytest -v and no errors are present.
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I solved any possible warnings that pytest -v has generated that are related to my code to the best of my knowledge.
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@avjmachine
Copy link
Contributor Author

@younik Faced a circular import issue due to DataCollectorV0 being still used in the create_dataset_from_collector_env argument type, while env.create_data() uses functions from utils.py.
So, I currently changed the argument type to Any to ensure tests run properly. Another option is to move the required functions and their dependencies to data_collector.py and change imports in all other files. Please suggest if there is a better option than both of these.

Copy link
Member

@younik younik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good thanks, I suggested some minor changes

@@ -10,7 +10,7 @@ minari_dataset/episode_data
## Create Minari Dataset

```{eval-rst}
.. autofunction:: minari.create_dataset_from_collector_env
.. autofunction:: env.create_dataset
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this generates the documentation properly
Can you check? You can build the doc locally

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't spot it since I had failures in building the docs. Now removed it since it is no longer required due to the deprecation.

@@ -22,6 +22,7 @@ data_collector_callbacks/episode_metadata_callback
.. autofunction:: minari.DataCollectorV0.step
.. autofunction:: minari.DataCollectorV0.reset
.. autofunction:: minari.DataCollectorV0.close
.. autofunction:: minari.DataCollectorV0.create_dataset
.. autofunction:: minari.DataCollectorV0.save_to_disk
Copy link
Member

@younik younik Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove save_to_disk from doc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -52,7 +52,7 @@ In this example, the :class:`minari.DataCollectorV0` wraps the `'CartPole-v1'` e
```{eval-rst}
To create a Minari dataset first we need to step the environment with a given policy to allow the :class:`minari.DataCollectorV0` to record the data that will comprise the dataset. This is as simple as just looping through the Gymansium MDP API. For our example we will loop through ``100`` episodes of the ``'CartPole-v1'`` environment with a random policy.

Finally, we need to create the Minari dataset and give it a name id. This is done by calling the :func:`minari.create_dataset_from_collector_env` Minari function which will move the temporary data recorded in the :class:`minari.DataCollectorV0` environment to a permanent location in the `local Minari root path </content/dataset_standards>`_ with the Minari dataset standard structure.
Finally, we need to create the Minari dataset and give it a name id. This is done by calling the :func:`env.create_dataset` Minari function which will move the temporary data recorded in the :class:`minari.DataCollectorV0` environment to a permanent location in the `local Minari root path </content/dataset_standards>`_ with the Minari dataset standard structure.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the doc, maybe you should write DataCollectorV0.create_dataset? As env can be unclear what it means

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[there are multiple places where this comment is valid]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified in all the instances in the docs.

@@ -396,8 +395,7 @@ def __call__(

obs, rew, terminated, truncated, info = collector_env.step(action)

dataset = minari.create_dataset_from_collector_env(
collector_env=collector_env,
dataset = env.create_dataset(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to fix tests, env -> collector_env here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

minari/utils.py Outdated
@@ -567,7 +566,7 @@ def create_dataset_from_buffers(

def create_dataset_from_collector_env(
dataset_id: str,
collector_env: DataCollectorV0,
collector_env: Any,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid circular import, in DataCollectorV0, you can import from minari.utils import _generate_dataset_metadata, _generate_dataset_path inside the create_dataset function (please also add a #TODO comment saying to move it on top with 0.5.0 release)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is also done.

call DataCollectorV0.create_dataset from create_dataset_from_collector_env to avoid duplicate code

shift imports  for _generate_dataset_metadata and _generate_dataset_path down to create_dataset method to avoid circular imports
Copy link
Member

@younik younik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@younik younik merged commit 320d3fc into Farama-Foundation:main Nov 25, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants