def from_mjcf_model(cls, mjcf_model): """Constructs a new `mjcf.Physics` from an `mjcf.RootElement`. Args: mjcf_model: An `mjcf.RootElement` instance. Returns: A new `mjcf.Physics` instance. """ debug_context = debugging.DebugContext() xml_string = mjcf_model.to_xml_string(debug_context=debug_context) if _pymjcf_log_xml(): if debug_context.debug_mode and debug_context.default_dump_dir: logging.info('Full debug info is dumped to disk at %s', debug_context.default_dump_dir) debug_context.dump_full_debug_info_to_disk() else: logging.info( 'Full debug info is not yet dumped to disk. If this is ' 'needed, pass all three flags: --pymjcf_log_xml ' '--pymjcf_debug --pymjcf_debug_full_dump_dir=/path/dir/') _log_xml(xml_string) assets = mjcf_model.get_assets() try: return cls.from_xml_string(xml_string=xml_string, assets=assets) except mujoco_wrapper.Error: debug_context.process_and_raise_last_exception()
def reload_from_mjcf_model(self, mjcf_model): """Reloads this `mjcf.Physics` from an `mjcf.RootElement`. After calling this method, the state of this `Physics` instance is the same as a new `Physics` instance created with the `from_mjcf_model` named constructor. Args: mjcf_model: An `mjcf.RootElement` instance. """ debug_context = debugging.DebugContext() xml_string = mjcf_model.to_xml_string(debug_context=debug_context) if _pymjcf_log_xml(): _log_xml(xml_string) assets = mjcf_model.get_assets() try: self.reload_from_xml_string(xml_string=xml_string, assets=assets) except mujoco_wrapper.Error: debug_context.process_and_raise_last_exception()