Skip to content

--Support stand alone Metadata Mediator, and building Simulator from MM#1099

Merged
jturner65 merged 6 commits intofacebookresearch:masterfrom
jturner65:MM_BuildSimFromMM
Feb 19, 2021
Merged

--Support stand alone Metadata Mediator, and building Simulator from MM#1099
jturner65 merged 6 commits intofacebookresearch:masterfrom
jturner65:MM_BuildSimFromMM

Conversation

@jturner65
Copy link
Copy Markdown
Contributor

Motivation and Context

This PR adds the ability to construct a Metadata Mediator in python, either from an existing Simulator Configuration or using a default, without requiring a Simulator to exist. It also adds the ability to pass an existing Metadata Mediator into Simulator as a constructor default, as well as to retrieve a reference to the Metadata Mediator currently in use from Simulator.

The purpose of this is that Metadata Mediator maintains all the configuration files that have been loaded into the system, which can be expensive for large datasets. By enabling the MM to be created and accessed independent of a Simulator instance, this loading process can be performed once, and then maintained through multiple simulator lifetimes.

How Has This Been Tested

Existing C++ and python tests. Simtest.cpp has been modified to test Simulators constructed using MM as well as those constructed from SimulatorConfiguration. TODO : python test is pending.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • [ x I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Feb 17, 2021
Copy link
Copy Markdown
Contributor

@mosra mosra left a comment

Choose a reason for hiding this comment

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

Just commenting on the test-related things.

Comment thread src/tests/SimTest.cpp Outdated
Comment thread src/tests/SimTest.cpp
Comment on lines 337 to 336
Corrade::Utility::Debug()
<< "Starting Test : getCustomLightingRGBAObservation ";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why this? :)

(I'm aware that if you get a crash, it won't print what test case it started, but that shouldn't mean you have to suffer like this ;) On my list of things to fix.)

Comment thread src/tests/SimTest.cpp

auto stateFinal = AgentState::create();
agent->getState(stateFinal);
CORRADE_VERIFY(stateOrig->position == stateFinal->position);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
CORRADE_VERIFY(stateOrig->position == stateFinal->position);
CORRADE_COMPARE(stateOrig->position, stateFinal->position);

assuming those are Magnum vectors and not Eigen vectors (which don't have a debug output), same below

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah. Ty

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oops, those are eigen vecs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CORRADE_COMPARE(Mn::Vector3{stateOrig->position}, Mn::Vector3{stateFinal->position}); ? 😅

Comment thread src/tests/SimTest.cpp
}

void SimTest::reset() {
auto testReset = [&](Simulator& simulator) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Because all test macros (which take care of extracting the function name) are inside the lambda, the function won't be marked correctly in the output. I'd do

void SimTest::reset() {
  CORRADE_VERIFY(true);

  auto testReset = [&](Simulator& simulator) {

to work around that :)

/* --- Template Manager accessors --- */
.def_property(
"metadata_mediator", &Simulator::getMetadataMediator,
&Simulator::setMetadataMediator, py::return_value_policy::copy,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interesting, you really want to return a copy?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

copy of smart pointer. want to increment holder count

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please document in a comment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's what happens by default for smart pointers with pybind

Copy link
Copy Markdown
Contributor Author

@jturner65 jturner65 Feb 18, 2021

Choose a reason for hiding this comment

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

That's what I thought but I wasn't sure. Should I remove the return value policy specifier? Serves as a nice doc -shrug-

Comment thread src/esp/bindings/SimBindings.cpp Outdated
// ==== Simulator ====
py::class_<Simulator, Simulator::ptr>(m, "Simulator")
// add constructor to build Simulator from existing MetadataMediator
.def(py::init<esp::metadata::MetadataMediator::ptr>())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mind adding a pytest test case somewhere. It will serve as documentation too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

working on it now

Comment thread src/esp/bindings/SimBindings.cpp Outdated
R"(The currently active dataset being used. Will attempt to load
configuration files specified if does not already exist.)")
/* --- Template Manager accessors --- */
// We wish a copy of the metadata mediator smart poitner so that we
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

typo:

Comment thread habitat_sim/simulator.py Outdated
sim_cfg: SimulatorConfiguration
agents: List[AgentConfiguration]
# An existing Metadata Mediator can also be used to construct a SimulatorBackend
metadata_mediator: MetadataMediator = attr.ib(default=None)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
metadata_mediator: MetadataMediator = attr.ib(default=None)
metadata_mediator: Optional[MetadataMediator] = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can sim_cfg and metadata_mediator override each other? Do we print a warning if that's the case? Or assert that one is None? We may want to add a validator to the effect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Can sim_cfg and metadata_mediator override each other? Do we print a warning if that's the case? Or assert that one is None? We may want to add a validator to the effect.

Yes, let's discuss this further in slack.

Comment thread habitat_sim/simulator.py Outdated
sim_cfg: SimulatorConfiguration
agents: List[AgentConfiguration]
# An existing Metadata Mediator can also be used to construct a SimulatorBackend
metadata_mediator: MetadataMediator = attr.ib(default=None)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can sim_cfg and metadata_mediator override each other? Do we print a warning if that's the case? Or assert that one is None? We may want to add a validator to the effect.

Copy link
Copy Markdown
Contributor

@aclegg3 aclegg3 left a comment

Choose a reason for hiding this comment

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

Looks good. 👍

Comment thread habitat_sim/simulator.py
def _config_backend(self, config: Configuration) -> None:
if not self._initialized:
super().__init__(config.sim_cfg)
super().__init__(config.sim_cfg, config.metadata_mediator)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should still give a warning / info via the logger that the MetadataMediator is overriding stuff though. Is this handled on the C++ side?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nothing is being overridden. The config.sim_cfg is the primary datasource. The existing MM is passed in, and then config.sim_cfg is queried for the dataset and scene, just as if it wasn't passed at all. The MM will get its dataset changed to match the dataset specified in the config.sim_cfg. This is non-destructive, and any loaded dataset information the existing MM will be retained, and can be specified separately.

@jturner65 jturner65 merged commit 61138e6 into facebookresearch:master Feb 19, 2021
@jturner65 jturner65 deleted the MM_BuildSimFromMM branch February 19, 2021 19:02
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.

6 participants