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

Add Type Annotations #13

Open
10 tasks
frederikschubert opened this issue Dec 31, 2021 · 0 comments
Open
10 tasks

Add Type Annotations #13

frederikschubert opened this issue Dec 31, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@frederikschubert
Copy link
Collaborator

frederikschubert commented Dec 31, 2021

This issue tracks the progress of adding type annotations to coax.

  • _core
  • experience_replay
  • model_updaters
  • policy_objectives
  • proba_dists
  • reward_tracing
  • td_learning
  • utils
  • value_transforms
  • wrappers

The types are added by utilising pyannotate and adding the following snippet to the coax._base.TestCase class:

...
@classmethod
    def setUpClass(cls) -> None:
        collect_types.init_types_collection()
        collect_types.start()

    @classmethod
    def tearDownClass(cls) -> None:
        collect_types.stop()
        type_replacements = {
            "jaxlib.xla_extension.DeviceArray": "jax.numpy.ndarray",
            "haiku._src.data_structures.FlatMapping": "typing.Mapping",
            "coax._core.policy_test": "gym.Env"
        }
        types_str = collect_types.dumps_stats()
        for inferred_type, replacement in type_replacements.items():
            types_str = types_str.replace(inferred_type, replacement)
        with open(sys.modules[cls.__module__].__file__.replace(".py", "_types.json"), "w") as f:
            f.write(types_str)
...

and the types are added automatically

for t in coax/**/*_test_types.json
do
    pyannotate --type-info $t -3 coax/* -w
done
@frederikschubert frederikschubert added the enhancement New feature or request label Dec 31, 2021
@frederikschubert frederikschubert self-assigned this Dec 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant