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

Registry #204

Merged
merged 10 commits into from
Sep 26, 2019
Merged

Registry #204

merged 10 commits into from
Sep 26, 2019

Conversation

erikwijmans
Copy link
Contributor

@erikwijmans erikwijmans commented Sep 11, 2019

Motivation and Context

With PR #189 adding another thing that makes sense to also use a registry for, it is time to swap to a proper registry pattern!

This registry is slightly different than the one in habitat-api as it's just a class instead of a global singleton instance. The global singleton instance was hard to generate proper docs for while generating docs for a class was super simple. I don't believe there is any functional difference between the two.

How Has This Been Tested

Via the existing tests.

Note that the CI is expected to fail for this PR as habitat-api has an example which uses habitat-sim's registry that will need to be updated.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Sep 11, 2019
@erikwijmans erikwijmans mentioned this pull request Sep 11, 2019
6 tasks
@@ -20,8 +20,8 @@ actuation_spec contains any parameters needed by that control function.
See ``habitat_sim/agent/controls/default_controls.py`` for more example
controls.

Controls are registered using the `habitat_sim.agent.register_move_fn()`
function. This function takes the functor to register and, optionally, the name
Controls are registered using `habitat_sim.registry.register_move_fn`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I was always appending the () to function references (to distinguish them from variables/properties/modules)... and I did that for the soon-to-be-PR'd habitat-api docs rework as well. Please let me know if I should stop doing that :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like that! I didn't realize that's why you had done that so it didn't register that I should keep it.

r"""registry is a central source of truth in Habitat-Sim

Taken from Pythia, it is inspired from Redux's
concept of global store. registry maintains mappings of various information
Copy link
Collaborator

Choose a reason for hiding this comment

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

This registry is slightly different than the one in habitat-api

AH, that's why this docstring felt like a deja vu to me :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep :)

Copy link
Contributor

@apsdehal apsdehal left a comment

Choose a reason for hiding this comment

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

LGTM to go.

from habitat_sim.nav import *
from habitat_sim.agent import *
from habitat_sim.simulator import *
from habitat_sim.bindings import *
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe at some point it will be good to move away from * imports.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As the comment above says :) I kept this for backwards compatibility and docs already show the names inside the nav / agen / ... submodules, so it's "just" about gradually moving the code to do that as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, missed the comment, sorry :)

return re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower()


class registry:
Copy link
Contributor

Choose a reason for hiding this comment

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

In Pythia, I actually annotated the registry file for documentation on registry. See https://github.com/facebookresearch/pythia/blob/master/pythia/common/registry.py. Singleton pattern also saves from PEP8 violations of lowercase class names. Though, this will also work. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried annotating the file, but the docs where fighting with me :/ This made the docs happy

Copy link
Contributor

Choose a reason for hiding this comment

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

https://learnpythia.readthedocs.io/en/latest/common/registry.html seems to render fine. Maybe some difference in sphinx configurations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah. I remember now what the main thing was. habitat_sim.registry.register_move_fn cross-links correctly with the class but not the instance.

Copy link
Collaborator

Choose a reason for hiding this comment

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

in any case, if there's something the docs aren't handling correctly (or could handle better), please complain loudly ;)

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 is kinda a strange case where I want to document a singleton and the cross-link to the methods on it. I am not sure if any doc engine current supports that :)

Copy link
Contributor Author

@erikwijmans erikwijmans Sep 12, 2019

Choose a reason for hiding this comment

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

Adding habitat_sim.registry = type(habitat_sim.registry) to docs/conf.py let's me use a singleton and have the docs get generated for it almost exactly as they should (it says that habitat_sim.registry is a class, but whatevs)


return controller

if controller is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice.

docs/docs.rst Outdated
@@ -82,11 +82,19 @@
We currently have the following actions added by default. Any action not
registered with an explict name is given the snake case version of the
class name, i.e. ``MoveForward`` can be accessed with the name
``move_forward``.
``move_forward``. See `habitat_sim.registry.register_move_fn`, `habitat_sim.agent.SceneNodeControl`,
and `habitat_sim.agent.ActuationSpec`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just FYI: the referencing works also relatively to currently documented name -- so in this case it could be a (shorter)

See `registry.register_move_fn`, `SceneNodeControl`, and `ActuationSpec`

as well -- of course the longer the displayed prefix is, the less potentially confusing the name is, so whichever feels best for you :) But generally omitting habitat_sim wouldn't hurt readability at all I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense!

@erikwijmans erikwijmans merged commit bef3e3e into master Sep 26, 2019
@erikwijmans erikwijmans deleted the registry branch September 26, 2019 19:53
eundersander pushed a commit to eundersander/habitat-sim that referenced this pull request Aug 6, 2020
Ram81 pushed a commit to Ram81/habitat-web-sim that referenced this pull request Dec 10, 2020
Switch to a proper registry pattern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants