def run_simulation(self, simulation_instance=None): if simulation_instance is None: simulation_instance = ModelSystem() simulation_instance.run(self.config) #simulation_instance.run_multiprocess(self.config, is_run_subset=True) logger.log_status("Data cache in %s" % self.simulation_state.get_cache_directory())
def create_latex_tables_for_model(self, config, model_name, dir): """Write to directory dir a file containing a LaTeX table describing this model's coefficients, and a file containing a LaTeX table describing this model's specification. Files will be named named <model_name>_coefficients.tex and <model_name>_specification.tex. """ config = Configuration(config) model_system = ModelSystem() input_db, output_db = model_system._get_database_connections(config) sql_storage = StorageFactory().get_storage('sql_storage', storage_location=input_db) #TODO: only do the next stuff if this model has coefficients if 'controller' not in config['models_configuration'][model_name]: return if 'prepare_for_run' not in config['models_configuration'][model_name][ 'controller']: return if 'coefficients' not in config['models_configuration'][model_name][ 'controller']['prepare_for_run']['output']: return specification_table_name = config['models_configuration'][ model_name].get('specification_table', None) coefficents_table_name = config['models_configuration'][ model_name].get('coefficients_table', None) (specification, coefficients) = prepare_specification_and_coefficients( specification_storage=sql_storage, specification_table=specification_table_name, coefficients_storage=sql_storage, coefficients_table=coefficents_table_name) self.create_latex_table_for_coefficients_for_model( coefficients, model_name, dir) self.create_latex_table_for_specifications_for_model( specification, model_name, dir)
def run_simulation(self, simulation_instance=None): logger.start_block( 'Simulation on database %s' % self.config['scenario_database_configuration'].database_name) try: if simulation_instance is None: simulation_instance = ModelSystem() simulation_instance.run(self.config) #simulation_instance.run_multiprocess(self.config, is_run_subset=True) finally: logger.end_block() logger.log_status("Data cache in %s" % self.simulation_state.get_cache_directory())
def __init__(self, config=None, save_estimation_results=False): if 'cache_directory' not in config or config['cache_directory'] is None: raise KeyError( "The cache directory must be specified in the " "given configuration, giving the filesystem path to the cache " "directory containing the data with which to estimate. Please " "check that your configuration contains the 'cache_directory' " "entry and that it is not None.") self.simulation_state = SimulationState(new_instance=True) self.simulation_state.set_cache_directory(config['cache_directory']) SessionConfiguration( new_instance=True, package_order=config['dataset_pool_configuration'].package_order, in_storage=AttributeCache()) self.config = Resources(config) self.save_estimation_results = save_estimation_results self.debuglevel = self.config.get("debuglevel", 4) self.model_system = ModelSystem() self.agents_index_for_prediction = None models = self.config.get('models', []) self.model_name = None if "model_name" in config.keys(): self.model_name = config["model_name"] else: for model in models: if isinstance(model, dict): model_name = model.keys()[0] if (model[model_name] == "estimate") or ( isinstance(model[model_name], list) and ("estimate" in model[model_name])): self.model_name = model_name break estimate_config_changes = self.config.get( 'config_changes_for_estimation', {}).get('estimate_config', {}) if len(estimate_config_changes) > 0: change = Resources({ 'models_configuration': { self.model_name: { 'controller': { 'init': { 'arguments': {} } } } } }) estimate_config_str = self.config['models_configuration'].get( self.model_name, {}).get('controller', {}).get('init', {}).get('arguments', {}).get('estimate_config', '{}') estimate_config = Resources({}) try: estimate_config = eval(estimate_config_str) except: pass estimate_config.merge(estimate_config_changes) self.config.merge(change) self.config['models_configuration'][ self.model_name]['controller']['init']['arguments'][ 'estimate_config'] = 'Resources(%s)' % estimate_config
# Opus/UrbanSim urban simulation software. # Copyright (C) 2005-2009 University of Washington # See opus_core/LICENSE from urbansim.simulation.run_simulation import RunSimulation from urbansim.model_coordinators.model_system import ModelSystem from randstad.run_config.randstad_baseline import run_configuration as my_configuration from urbansim.configs.base_configuration import AbstractUrbansimConfiguration config = AbstractUrbansimConfiguration() simulation = RunSimulation() run_configuration = config.copy() run_configuration.merge(my_configuration) simulation.prepare_and_run(run_configuration, simulation_instance=ModelSystem(), remove_cache=True)
def run(self): self.model_system = ModelSystem() self.model_system.run(self.config, write_datasets_to_cache_at_end_of_year=False) logger.log_status("Data cache in %s" % self.simulation_state.get_cache_directory())
def test_run_models(self): model_system = ModelSystem() model_system.run_in_same_process(self.config)