From 85a469744ad2b76266b13fd7d9f9985460d05474 Mon Sep 17 00:00:00 2001 From: Jack O'Brien Date: Wed, 23 Feb 2022 10:25:46 -0500 Subject: [PATCH] Fix PyTest fixtures and updated mainloop to properly compile (#1901) * added in a special fixture for the montecarlo_1e5 model tests as to avoid mixing config fixtures. Set the montecarlo_main_loop to recompile itself on the first iteration ot set proper config options * Removed setting the single packet seed which is currently deprecated * Removed print statement --- tardis/conftest.py | 9 ++++++++- tardis/model/tests/test_base.py | 1 - tardis/montecarlo/montecarlo_numba/base.py | 2 +- .../montecarlo_numba/tests/test_base.py | 16 +++++++--------- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/tardis/conftest.py b/tardis/conftest.py index 86924c02e44..52505bddd69 100644 --- a/tardis/conftest.py +++ b/tardis/conftest.py @@ -138,7 +138,7 @@ def tardis_ref_data(tardis_ref_path, generate_reference): yield store -@pytest.fixture +@pytest.fixture(scope="function") def tardis_config_verysimple(): return yaml_load_config_file( "tardis/io/tests/data/tardis_configv1_verysimple.yml" @@ -164,6 +164,13 @@ def config_verysimple(): return config +@pytest.fixture(scope="function") +def config_montecarlo_1e5_verysimple(): + filename = "tardis_configv1_verysimple.yml" + path = os.path.abspath(os.path.join("tardis/io/tests/data/", filename)) + config = Configuration.from_yaml(path) + return config + @pytest.fixture(scope="session") def simulation_verysimple(config_verysimple, atomic_dataset): atomic_data = deepcopy(atomic_dataset) diff --git a/tardis/model/tests/test_base.py b/tardis/model/tests/test_base.py index 01e4c825b53..52cda7a02c8 100644 --- a/tardis/model/tests/test_base.py +++ b/tardis/model/tests/test_base.py @@ -387,7 +387,6 @@ def test_density(self): def to_hdf_buffer(hdf_file_path, simulation_verysimple): simulation_verysimple.model.to_hdf(hdf_file_path, overwrite=True) - model_scalar_attrs = ["t_inner"] diff --git a/tardis/montecarlo/montecarlo_numba/base.py b/tardis/montecarlo/montecarlo_numba/base.py index f07d6fc057f..d50f45bbbb1 100644 --- a/tardis/montecarlo/montecarlo_numba/base.py +++ b/tardis/montecarlo/montecarlo_numba/base.py @@ -63,7 +63,7 @@ def montecarlo_radial1d( packet_seeds = montecarlo_configuration.packet_seeds number_of_vpackets = montecarlo_configuration.number_of_vpackets - + if iteration == 0: montecarlo_main_loop.recompile() # Make sure we update ( v_packets_energy_hist, last_interaction_type, diff --git a/tardis/montecarlo/montecarlo_numba/tests/test_base.py b/tardis/montecarlo/montecarlo_numba/tests/test_base.py index 37f097407a9..fde614fc50d 100644 --- a/tardis/montecarlo/montecarlo_numba/tests/test_base.py +++ b/tardis/montecarlo/montecarlo_numba/tests/test_base.py @@ -15,7 +15,7 @@ def test_montecarlo_radial1d(): assert False def test_montecarlo_main_loop( - config_verysimple, + config_montecarlo_1e5_verysimple, atomic_dataset, tardis_ref_path, tmpdir, @@ -27,17 +27,15 @@ def test_montecarlo_main_loop( montecarlo_configuration.LEGACY_MODE_ENABLED = True # Setup model config from verysimple atomic_data = deepcopy(atomic_dataset) - config_verysimple.montecarlo.last_no_of_packets = 1e5 - config_verysimple.montecarlo.no_of_virtual_packets = 0 - config_verysimple.montecarlo.iterations = 1 - config_verysimple.montecarlo.single_packet_seed = 0 - config_verysimple.plasma.line_interaction_type = 'macroatom' - del config_verysimple["config_dirname"] + config_montecarlo_1e5_verysimple.montecarlo.last_no_of_packets = 1e5 + config_montecarlo_1e5_verysimple.montecarlo.no_of_virtual_packets = 0 + config_montecarlo_1e5_verysimple.montecarlo.iterations = 1 + config_montecarlo_1e5_verysimple.plasma.line_interaction_type = 'macroatom' + del config_montecarlo_1e5_verysimple["config_dirname"] - sim = Simulation.from_config(config_verysimple, atom_data=atomic_data) + sim = Simulation.from_config(config_montecarlo_1e5_verysimple, atom_data=atomic_data) sim.run() - compare_fname = os.path.join(tardis_ref_path, "montecarlo_1e5_compare_data.h5") if request.config.getoption("--generate-reference"): sim.to_hdf(compare_fname, overwrite=True)