def test_rng_access(): configs_dir = os.path.join(os.path.dirname(__file__), 'configs') orca.add_injectable("configs_dir", configs_dir) output_dir = os.path.join(os.path.dirname(__file__), 'output') orca.add_injectable("output_dir", output_dir) data_dir = os.path.join(os.path.dirname(__file__), 'data') orca.add_injectable("data_dir", data_dir) inject_settings(configs_dir, households_sample_size=HOUSEHOLDS_SAMPLE_SIZE) orca.clear_cache() pipeline.set_rn_generator_base_seed(0) pipeline.open_pipeline() with pytest.raises(RuntimeError) as excinfo: pipeline.set_rn_generator_base_seed(0) assert "call set_rn_generator_base_seed before the first step" in str( excinfo.value) rng = pipeline.get_rn_generator() pipeline.close_pipeline() orca.clear_cache()
def test_mp_run(): mp_configs_dir = os.path.join(os.path.dirname(__file__), 'configs_mp') configs_dir = os.path.join(os.path.dirname(__file__), 'configs') inject.add_injectable('configs_dir', [mp_configs_dir, configs_dir]) output_dir = os.path.join(os.path.dirname(__file__), 'output') inject.add_injectable("output_dir", output_dir) data_dir = os.path.join(os.path.dirname(__file__), 'data') inject.add_injectable("data_dir", data_dir) tracing.config_logger() run_list = mp_tasks.get_run_list() mp_tasks.print_run_list(run_list) # do this after config.handle_standard_args, as command line args may override injectables injectables = ['data_dir', 'configs_dir', 'output_dir'] injectables = {k: inject.get_injectable(k) for k in injectables} # pipeline.run(models=run_list['models'], resume_after=run_list['resume_after']) mp_tasks.run_multiprocess(run_list, injectables) pipeline.open_pipeline('_') regress_mini_auto() pipeline.close_pipeline()
def test_mp_run(): mp_configs_dir = os.path.join(os.path.dirname(__file__), 'configs_mp') configs_dir = os.path.join(os.path.dirname(__file__), 'configs') inject.add_injectable('configs_dir', [mp_configs_dir, configs_dir]) output_dir = os.path.join(os.path.dirname(__file__), 'output') inject.add_injectable("output_dir", output_dir) data_dir = os.path.join(os.path.dirname(__file__), 'data') inject.add_injectable("data_dir", data_dir) tracing.config_logger() run_list = mp_tasks.get_run_list() mp_tasks.print_run_list(run_list) # do this after config.handle_standard_args, as command line args may override injectables injectables = ['data_dir', 'configs_dir', 'output_dir'] injectables = {k: inject.get_injectable(k) for k in injectables} # pipeline.run(models=run_list['models'], resume_after=run_list['resume_after']) mp_tasks.run_multiprocess(run_list, injectables) pipeline.open_pipeline('_') regress_mini_auto() pipeline.close_pipeline()
def test_mini_pipeline_run2(): # the important thing here is that we should get # exactly the same results as for test_mini_pipeline_run # when we restart pipeline configs_dir = os.path.join(os.path.dirname(__file__), 'configs') setup_dirs(configs_dir) inject_settings(configs_dir, households_sample_size=HOUSEHOLDS_SAMPLE_SIZE) # should be able to get this BEFORE pipeline is opened checkpoints_df = pipeline.get_checkpoints() prev_checkpoint_count = len(checkpoints_df.index) # print "checkpoints_df\n", checkpoints_df[['checkpoint_name']] assert prev_checkpoint_count == 8 pipeline.open_pipeline('auto_ownership_simulate') regress_mini_auto() # try to run a model already in pipeline with pytest.raises(RuntimeError) as excinfo: pipeline.run_model('auto_ownership_simulate') assert "run model 'auto_ownership_simulate' more than once" in str( excinfo.value) # and these new ones pipeline.run_model('cdap_simulate') pipeline.run_model('mandatory_tour_frequency') regress_mini_mtf() # should be able to get this before pipeline is closed (from existing open store) checkpoints_df = pipeline.get_checkpoints() assert len(checkpoints_df.index) == prev_checkpoint_count # - write list of override_hh_ids to override_hh_ids.csv in data for use in next test num_hh_ids = 10 hh_ids = pipeline.get_table("households").head(num_hh_ids).index.values hh_ids = pd.DataFrame({'household_id': hh_ids}) data_dir = inject.get_injectable('data_dir') hh_ids.to_csv(os.path.join(data_dir, 'override_hh_ids.csv'), index=False, header=True) pipeline.close_pipeline() inject.clear_cache() close_handlers()
def test_rng_access(): setup_dirs() inject.add_injectable('rng_base_seed', 0) pipeline.open_pipeline() rng = pipeline.get_rn_generator() assert isinstance(rng, random.Random) pipeline.close_pipeline() inject.clear_cache()
def test_mini_pipeline_run2(): # the important thing here is that we should get # exactly the same results as for test_mini_pipeline_run # when we restart pipeline configs_dir = os.path.join(os.path.dirname(__file__), 'configs') setup_dirs(configs_dir) inject_settings(configs_dir, households_sample_size=HOUSEHOLDS_SAMPLE_SIZE) # should be able to get this BEFORE pipeline is opened checkpoints_df = pipeline.get_checkpoints() prev_checkpoint_count = len(checkpoints_df.index) # print "checkpoints_df\n", checkpoints_df[['checkpoint_name']] assert prev_checkpoint_count == 8 pipeline.open_pipeline('auto_ownership_simulate') regress_mini_auto() # try to run a model already in pipeline with pytest.raises(RuntimeError) as excinfo: pipeline.run_model('auto_ownership_simulate') assert "run model 'auto_ownership_simulate' more than once" in str(excinfo.value) # and these new ones pipeline.run_model('cdap_simulate') pipeline.run_model('mandatory_tour_frequency') regress_mini_mtf() # should be able to get this before pipeline is closed (from existing open store) checkpoints_df = pipeline.get_checkpoints() assert len(checkpoints_df.index) == prev_checkpoint_count # - write list of override_hh_ids to override_hh_ids.csv in data for use in next test num_hh_ids = 10 hh_ids = pipeline.get_table("households").head(num_hh_ids).index.values hh_ids = pd.DataFrame({'household_id': hh_ids}) data_dir = inject.get_injectable('data_dir') hh_ids.to_csv(os.path.join(data_dir, 'override_hh_ids.csv'), index=False, header=True) pipeline.close_pipeline() inject.clear_cache() close_handlers()
def test_rng_access(): configs_dir = os.path.join(os.path.dirname(__file__), 'configs') setup_dirs(configs_dir) inject.add_injectable('rng_base_seed', 0) pipeline.open_pipeline() rng = pipeline.get_rn_generator() assert isinstance(rng, random.Random) pipeline.close_pipeline() inject.clear_cache()
def test_mp_run(): mp_configs_dir = os.path.join(os.path.dirname(__file__), 'configs_mp') setup_dirs(ancillary_configs_dir=mp_configs_dir) run_list = mp_tasks.get_run_list() mp_tasks.print_run_list(run_list) # do this after config.handle_standard_args, as command line args may override injectables injectables = ['data_dir', 'configs_dir', 'output_dir'] injectables = {k: inject.get_injectable(k) for k in injectables} # pipeline.run(models=run_list['models'], resume_after=run_list['resume_after']) mp_tasks.run_multiprocess(run_list, injectables) pipeline.open_pipeline('_') regress_mini_auto() pipeline.close_pipeline()
def test_mp_run(): setup_dirs() # Debugging ---------------------- run_list = mp_tasks.get_run_list() mp_tasks.print_run_list(run_list) # -------------------------------- # do this after config.handle_standard_args, as command line args # may override injectables injectables = ["data_dir", "configs_dir", "output_dir"] injectables = {k: inject.get_injectable(k) for k in injectables} mp_tasks.run_multiprocess(injectables) pipeline.open_pipeline("_") regress() pipeline.close_pipeline()
def test_mp_run(): configs_dir = [example_path('configs_3_zone'), example_path('configs')] data_dir = example_path('data_3') setup_dirs(configs_dir, data_dir) inject.add_injectable('settings_file_name', 'settings_mp.yaml') run_list = mp_tasks.get_run_list() mp_tasks.print_run_list(run_list) # do this after config.handle_standard_args, as command line args may override injectables injectables = [ 'data_dir', 'configs_dir', 'output_dir', 'settings_file_name' ] injectables = {k: inject.get_injectable(k) for k in injectables} mp_tasks.run_multiprocess(run_list, injectables) pipeline.open_pipeline('_') regress_3_zone() pipeline.close_pipeline()
os.getcwd() os.chdir('rFirm') from activitysim.core import inject_defaults from activitysim.core import tracing from activitysim.core import pipeline from activitysim.core import inject from activitysim.core.config import setting import rFirm tracing.config_logger() pipeline.open_pipeline('_') # pipeline.preload_injectables() df = pipeline.get_table("table1").to_frame() import pandas as pd file_path = "/Users/jeff.doyle/work/rFirm/example/regression_data/results/firm_sim_types/outputs/Firms.csv" rfirms = pd.read_csv(file_path, comment='#'). \ rename(columns={'BusID': 'bus_id', 'TAZ1': 'TAZ', 'Model_EmpCat': 'model_emp_cat'}). \ set_index('bus_id') rfirms.groupby(['TAZ', 'SCTG']).bus_id.count()
def test_mini_pipeline_run2(): # the important thing here is that we should get # exactly the same results as for test_mini_pipeline_run # when we restart pipeline configs_dir = os.path.join(os.path.dirname(__file__), 'configs') orca.add_injectable("configs_dir", configs_dir) output_dir = os.path.join(os.path.dirname(__file__), 'output') orca.add_injectable("output_dir", output_dir) data_dir = os.path.join(os.path.dirname(__file__), 'data') orca.add_injectable("data_dir", data_dir) inject_settings(configs_dir, households_sample_size=HOUSEHOLDS_SAMPLE_SIZE) orca.clear_cache() # should be able to get this BEFORE pipeline is opened checkpoints_df = pipeline.get_checkpoints() prev_checkpoint_count = len(checkpoints_df.index) # print "checkpoints_df\n", checkpoints_df[['checkpoint_name']] assert prev_checkpoint_count == 11 pipeline.open_pipeline('auto_ownership_simulate') auto_choice = pipeline.get_table("households").auto_ownership # regression test: these are the same as in test_mini_pipeline_run1 hh_ids = [464138, 1918238, 2201602] choices = [0, 1, 2] expected_choice = pd.Series(choices, index=pd.Index(hh_ids, name="HHID"), name='auto_ownership') print "auto_choice\n", auto_choice.head(4) pdt.assert_series_equal(auto_choice[hh_ids], expected_choice) # try to run a model already in pipeline with pytest.raises(RuntimeError) as excinfo: pipeline.run_model('auto_ownership_simulate') assert "run model 'auto_ownership_simulate' more than once" in str( excinfo.value) # and these new ones pipeline.run_model('cdap_simulate') pipeline.run_model('mandatory_tour_frequency') mtf_choice = pipeline.get_table("persons").mandatory_tour_frequency per_ids = [24375, 92744, 172491] choices = ['school2', 'work_and_school', 'work1'] expected_choice = pd.Series(choices, index=pd.Index(per_ids, name='PERID'), name='mandatory_tour_frequency') print "mtf_choice\n", mtf_choice.head(20) pdt.assert_series_equal(mtf_choice[per_ids], expected_choice) # should be able to get this before pipeline is closed (from existing open store) checkpoints_df = pipeline.get_checkpoints() assert len(checkpoints_df.index) == prev_checkpoint_count pipeline.close_pipeline() orca.clear_cache()