--Support stand alone Metadata Mediator, and building Simulator from MM#1099
Conversation
mosra
left a comment
There was a problem hiding this comment.
Just commenting on the test-related things.
| Corrade::Utility::Debug() | ||
| << "Starting Test : getCustomLightingRGBAObservation "; |
There was a problem hiding this comment.
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.)
|
|
||
| auto stateFinal = AgentState::create(); | ||
| agent->getState(stateFinal); | ||
| CORRADE_VERIFY(stateOrig->position == stateFinal->position); |
There was a problem hiding this comment.
| 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
There was a problem hiding this comment.
oops, those are eigen vecs
There was a problem hiding this comment.
CORRADE_COMPARE(Mn::Vector3{stateOrig->position}, Mn::Vector3{stateFinal->position}); ? 😅
| } | ||
|
|
||
| void SimTest::reset() { | ||
| auto testReset = [&](Simulator& simulator) { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Interesting, you really want to return a copy?
There was a problem hiding this comment.
copy of smart pointer. want to increment holder count
There was a problem hiding this comment.
Please document in a comment.
There was a problem hiding this comment.
That's what happens by default for smart pointers with pybind
There was a problem hiding this comment.
That's what I thought but I wasn't sure. Should I remove the return value policy specifier? Serves as a nice doc -shrug-
| // ==== Simulator ==== | ||
| py::class_<Simulator, Simulator::ptr>(m, "Simulator") | ||
| // add constructor to build Simulator from existing MetadataMediator | ||
| .def(py::init<esp::metadata::MetadataMediator::ptr>()) |
There was a problem hiding this comment.
Mind adding a pytest test case somewhere. It will serve as documentation too.
There was a problem hiding this comment.
working on it now
| 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 |
| 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) |
There was a problem hiding this comment.
| metadata_mediator: MetadataMediator = attr.ib(default=None) | |
| metadata_mediator: Optional[MetadataMediator] = None |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
a6a6f87 to
aa7d743
Compare
| def _config_backend(self, config: Configuration) -> None: | ||
| if not self._initialized: | ||
| super().__init__(config.sim_cfg) | ||
| super().__init__(config.sim_cfg, config.metadata_mediator) |
There was a problem hiding this comment.
We should still give a warning / info via the logger that the MetadataMediator is overriding stuff though. Is this handled on the C++ side?
There was a problem hiding this comment.
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.
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
Checklist