Skip to content

Commit

Permalink
Fix PyTest fixtures and updated mainloop to properly compile (#1901)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Rodot- authored Feb 23, 2022
1 parent 059f959 commit 85a4697
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
9 changes: 8 additions & 1 deletion tardis/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion tardis/model/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]


Expand Down
2 changes: 1 addition & 1 deletion tardis/montecarlo/montecarlo_numba/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 7 additions & 9 deletions tardis/montecarlo/montecarlo_numba/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 85a4697

Please sign in to comment.