def run(interface, port, setup_module_name, settings_file, slowdown, seed, paused, pause_after, repl, export, export_path, reset_on_finish, reset_on_finish_wait, exit_on_finish, exit_on_finish_wait, enable_bc, enable_bm, **config_params): try: if settings_file is not None: simulation_settings, advanced_settings = read_settings_from_file( settings_file) update_advanced_settings(advanced_settings) simulation_config = SimulationConfig(**simulation_settings) else: simulation_config = SimulationConfig(**config_params) api_url = "http://{}:{}/api".format(interface, port) ConstSettings.BalancingSettings.ENABLE_BALANCING_MARKET = enable_bm simulation = Simulation(setup_module_name=setup_module_name, simulation_config=simulation_config, slowdown=slowdown, seed=seed, paused=paused, pause_after=pause_after, use_repl=repl, export=export, export_path=export_path, reset_on_finish=reset_on_finish, reset_on_finish_wait=reset_on_finish_wait, exit_on_finish=exit_on_finish, exit_on_finish_wait=exit_on_finish_wait, api_url=api_url, redis_job_id=None, use_bc=enable_bc) except D3AException as ex: raise click.BadOptionUsage(ex.args[0]) start_web(interface, port, simulation) simulation.run()
def run(setup_module_name, settings_file, duration, slot_length, tick_length, market_count, cloud_coverage, compare_alt_pricing, enable_external_connection, start_date, pause_at, slot_length_realtime, **kwargs): # Force the multiprocessing start method to be 'fork' on macOS. if platform.system() == 'Darwin': multiprocessing.set_start_method('fork') try: if settings_file is not None: simulation_settings, advanced_settings = read_settings_from_file( settings_file) update_advanced_settings(advanced_settings) validate_global_settings(simulation_settings) simulation_settings["external_connection_enabled"] = False simulation_config = SimulationConfig(**simulation_settings) else: global_settings = { "sim_duration": duration, "slot_length": slot_length, "tick_length": tick_length, "cloud_coverage": cloud_coverage, "market_count": market_count } validate_global_settings(global_settings) simulation_config = \ SimulationConfig(duration, slot_length, tick_length, market_count, cloud_coverage, start_date=start_date, external_connection_enabled=enable_external_connection) if compare_alt_pricing is True: ConstSettings.IAASettings.AlternativePricing.COMPARE_PRICING_SCHEMES = True # we need the seconds in the export dir name kwargs["export_subdir"] = DateTime.now( tz=TIME_ZONE).format(f"{DATE_TIME_FORMAT}:ss") processes = [] for pricing_scheme in range(0, 4): kwargs["pricing_scheme"] = pricing_scheme p = Process(target=run_simulation, args=(setup_module_name, simulation_config, None, None, None, slot_length_realtime, kwargs)) p.start() processes.append(p) for p in processes: p.join() else: if pause_at is not None: kwargs["pause_after"] = convert_str_to_pause_after_interval( start_date, pause_at) run_simulation(setup_module_name, simulation_config, None, None, None, slot_length_realtime, kwargs) except D3AException as ex: raise click.BadOptionUsage(ex.args[0])
def test_parse_settings_file(self): simulation_settings, advanced_settings = read_settings_from_file( os.path.join(d3a_path, "setup", "d3a-settings.json")) update_advanced_settings(advanced_settings) simulation_config = SimulationConfig(**simulation_settings) assert simulation_config.__getattribute__( "sim_duration") == IntervalType('H:M')("24h") try: for setting in advanced_settings.keys(): getattr(ConstSettings, setting) except AttributeError: self.fail( "The settings file is not consistent with the selection of variables in " "const.py")