Fixes configclass shared references to keep compound objects independent...
Fixes configclass shared references to keep compound objects independent across subclass instances (#528) # Description There is currently an issue with `configclass.py`'s function `_return_f`, which produces `default_factory` functions for `configclass` classes. `configclass` instances which have member variables that are compound objects, (such as `BaseEnvCfg` and its member `SimulationCfg`) currently share a reference to a common members (in the example of `BaseEnvCfg`, its inheriting classes would share a common reference to `self.sim.dt`) When such classes are inherited, compound objects which have their member variables changed in the __post_init__ function will be changed for all subclass instances. I have solved this by changing the non-field return to be a `deepcopy` The issue was observed in orbit.eval_sim and was reported this way on the Institute's JIRA: > EvalSim will hold the Environment parameters that are set from the first environment that is loaded in unless it is otherwise explicitly overridden in the post init or reset EnvCfg member fields by the next environment. > > Example: > >If EnvironmentCfg A gets loaded first and sets sim.dt = 0.1 followed by loading EnvironmentCfg B, then Environment B will get the sim.dt set in Environment A if it does not explicitly set sim.dt in the post_init. Any fields defined inside BaseEnvCfg that are not redefined inside the Cfg inheriting BaseEnvCfg will take after the configuration set in the first environment that gets loaded. I have added a condition to the test `test_configclass.test_config_inheritance` which tests this value. Those wishing to demonstrate that this issue exists can simply change the line in `configclass.py` back to an assignment and observe the test failing. ## Type of change <!-- As you go through the list, delete the ones that are not applicable. --> - Bug fix (non-breaking change which fixes an issue) ## Checklist - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./orbit.sh --format` - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have run all the tests with `./orbit.sh --test` and they pass - [x] I have updated the changelog and the corresponding version in the extension's `config/extension.toml` file - [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there --------- Signed-off-by:Hunter Hansen <50837800+hhansen-bdai@users.noreply.github.com> Co-authored-by:
Mayank Mittal <12863862+Mayankm96@users.noreply.github.com>
Showing
Please register or sign in to comment