def main(): global environment config_file = Parser().parse_args().config config = EnvironmentConfig().create(config_file=config_file) signal.signal(signal.SIGTERM, signal_handler) # try: environment = RosEnvironment(config=config) state = environment.reset() while state.done != TerminationType.Success and state.done != TerminationType.Failure: print(f'state: {environment.fsm_state}') state = environment.step() environment.remove()
cprint(f'Terminated successfully? {bool(result)}', self._logger, msg_type=MessageType.info if result else MessageType.warning) if self._data_saver is not None: self._data_saver.remove() if self._trainer is not None: self._trainer.remove() if self._evaluator is not None: self._evaluator.remove() if self._net is not None: self._net.remove() if self._episode_runner is not None: self._episode_runner.remove() [h.close() for h in self._logger.handlers] if __name__ == "__main__": arguments = Parser().parse_args() config_file = arguments.config if arguments.rm: with open(config_file, 'r') as f: configuration = yaml.load(f, Loader=yaml.FullLoader) if not configuration['output_path'].startswith('/'): configuration['output_path'] = os.path.join(get_data_dir(os.environ['HOME']), configuration['output_path']) shutil.rmtree(configuration['output_path'], ignore_errors=True) experiment_config = ExperimentConfig().create(config_file=config_file, seed=arguments.seed) experiment = Experiment(experiment_config) experiment.run() experiment.shutdown()
import sys from dataclasses import dataclass from dataclasses_json import dataclass_json from src.core.config_loader import Parser, Config from src.core.utils import * @dataclass_json @dataclass class DummyConfig(Config): output_path: str = None config_file = Parser().parse_args().config if config_file is not None: config = DummyConfig().create(config_file=config_file) for i in range(3): print(f'saving file {i} in {config.output_path}') with open(os.path.join(config.output_path, f'dummy_file_{i}'), 'w') as f: try: msg = os.environ['_CONDOR_JOB_AD'] except: msg = 'failed to read _CONDOR_JOB_AD' f.write(msg) time.sleep(60) nested_path = os.path.join(config.output_path, 'nested_dir_1', 'nested_dir_2') os.makedirs(nested_path, exist_ok=True) with open(os.path.join(nested_path, 'already_existing_file'), 'w') as f: f.write('overwritten\noverwritten\noverwritten')
def test_config_parser(self): config_file = 'src/core/test/config/test_config_loader_config.yml' arguments = Parser().parse_args(["--config", config_file]) config = DummyDataCollectionConfig().create( config_file=arguments.config)