Skip to content

Commit

Permalink
Resolves even more global references
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewfullard committed Jul 12, 2024
1 parent dc7abbc commit 634b4e5
Show file tree
Hide file tree
Showing 18 changed files with 101 additions and 168 deletions.
30 changes: 3 additions & 27 deletions benchmarks/benchmark_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,7 @@ def packet(self):

@property
def verysimple_packet_collection(self):
return (
self.nb_simulation_verysimple.transport.transport_state.packet_collection
)
return self.nb_simulation_verysimple.transport.transport_state.packet_collection

@property
def nb_simulation_verysimple(self):
Expand All @@ -257,37 +255,15 @@ def verysimple_opacity_state(self):
return opacity_state_initialize(
self.nb_simulation_verysimple.plasma,
line_interaction_type="macroatom",
disable_line_scattering=self.nb_simulation_verysimple.transport.montecarlo_configuration.DISABLE_LINE_SCATTERING,
continuum_processes_enabled=self.nb_simulation_verysimple.transport.montecarlo_configuration.CONTINUUM_PROCESSES_ENABLED,
)

@property
def verysimple_enable_full_relativity(self):
return self.nb_simulation_verysimple.transport.enable_full_relativity

@property
def verysimple_disable_line_scattering(self):
return (
self.nb_simulation_verysimple.transport.montecarlo_configuration.DISABLE_LINE_SCATTERING
)

@property
def verysimple_continuum_processes_enabled(self):
return (
self.nb_simulation_verysimple.transport.montecarlo_configuration.CONTINUUM_PROCESSES_ENABLED
)

@property
def verysimple_tau_russian(self):
return (
self.nb_simulation_verysimple.transport.montecarlo_configuration.VPACKET_TAU_RUSSIAN
)
return self.nb_simulation_verysimple.transport.montecarlo_configuration.VPACKET_TAU_RUSSIAN

@property
def verysimple_survival_probability(self):
return (
self.nb_simulation_verysimple.transport.montecarlo_configuration.SURVIVAL_PROBABILITY
)
return self.nb_simulation_verysimple.transport.montecarlo_configuration.SURVIVAL_PROBABILITY

@property
def static_packet(self):
Expand Down
8 changes: 2 additions & 6 deletions benchmarks/transport_montecarlo_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def time_thomson_scatter(self):
init_nu = packet.nu
init_energy = packet.energy
time_explosion = self.verysimple_time_explosion
enable_full_relativity = self.verysimple_enable_full_relativity

interaction.thomson_scatter(
packet, time_explosion, enable_full_relativity
packet,
time_explosion,
)

assert np.abs(packet.mu - init_mu) > 1e-7
Expand All @@ -51,7 +51,6 @@ def time_line_scatter(self, line_interaction_type):
packet.initialize_line_id(
self.verysimple_opacity_state,
self.verysimple_time_explosion,
self.verysimple_enable_full_relativity,
)
time_explosion = self.verysimple_time_explosion

Expand All @@ -60,7 +59,6 @@ def time_line_scatter(self, line_interaction_type):
time_explosion,
line_interaction_type,
self.verysimple_opacity_state,
self.verysimple_enable_full_relativity,
self.verysimple_continuum_processes_enabled,
)

Expand Down Expand Up @@ -97,7 +95,6 @@ def time_line_emission(self, test_packet):
packet.initialize_line_id(
self.verysimple_opacity_state,
self.verysimple_time_explosion,
self.verysimple_enable_full_relativity,
)

time_explosion = self.verysimple_time_explosion
Expand All @@ -107,7 +104,6 @@ def time_line_emission(self, test_packet):
emission_line_id,
time_explosion,
self.verysimple_opacity_state,
self.verysimple_enable_full_relativity,
)

assert packet.next_line_id == emission_line_id + 1
4 changes: 0 additions & 4 deletions benchmarks/transport_montecarlo_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,12 @@ def time_calculate_distance_line(self, parameters):
expected_params = parameters["expected"]
nu_line = packet_params["nu_line"]
is_last_line = packet_params["is_last_line"]
enable_full_relativity = parameters["enable_full_relativity"]

time_explosion = self.model
doppler_factor = frame_transformations.get_doppler_factor(
self.static_packet.r,
self.static_packet.mu,
time_explosion,
enable_full_relativity,
)
comov_nu = self.static_packet.nu * doppler_factor

Expand All @@ -122,7 +120,6 @@ def time_calculate_distance_line(self, parameters):
is_last_line,
nu_line,
time_explosion,
enable_full_relativity,
)
except utils.MonteCarloException:
obtained_tardis_error = utils.MonteCarloException
Expand Down Expand Up @@ -215,7 +212,6 @@ def time_update_line_estimators(self, parameters):
cur_line_id,
distance_trace,
time_explosion,
enable_full_relativity,
)

@parameterize(
Expand Down
29 changes: 7 additions & 22 deletions benchmarks/transport_montecarlo_vpacket.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ def v_packet(self):
)

def v_packet_initialize_line_id(
self, v_packet, opacity_state, time_explosion, enable_full_relativity
self,
v_packet,
opacity_state,
time_explosion,
):
inverse_line_list_nu = opacity_state.line_list_nu[::-1]
doppler_factor = get_doppler_factor(
v_packet.r, v_packet.mu, time_explosion, enable_full_relativity
v_packet.r,
v_packet.mu,
time_explosion,
)
comov_nu = v_packet.nu * doppler_factor
next_line_id = len(opacity_state.line_list_nu) - np.searchsorted(
Expand All @@ -48,17 +53,12 @@ def time_trace_vpacket_within_shell(self):
)
verysimple_time_explosion = self.verysimple_time_explosion
verysimple_opacity_state = self.verysimple_opacity_state
enable_full_relativity = self.verysimple_enable_full_relativity
continuum_processes_enabled = (
self.verysimple_continuum_processes_enabled
)

# Give the vpacket a reasonable line ID
self.v_packet_initialize_line_id(
v_packet,
verysimple_opacity_state,
verysimple_time_explosion,
enable_full_relativity,
)

(
Expand All @@ -70,8 +70,6 @@ def time_trace_vpacket_within_shell(self):
verysimple_numba_radial_1d_geometry,
verysimple_time_explosion,
verysimple_opacity_state,
enable_full_relativity,
continuum_processes_enabled,
)

assert delta_shell == 1
Expand All @@ -83,10 +81,6 @@ def time_trace_vpacket(self):
)
verysimple_time_explosion = self.verysimple_time_explosion
verysimple_opacity_state = self.verysimple_opacity_state
enable_full_relativity = self.verysimple_enable_full_relativity
continuum_processes_enabled = (
self.verysimple_continuum_processes_enabled
)
tau_russian = self.verysimple_tau_russian
survival_probability = self.verysimple_survival_probability

Expand All @@ -98,7 +92,6 @@ def time_trace_vpacket(self):
v_packet,
verysimple_opacity_state,
verysimple_time_explosion,
enable_full_relativity,
)

tau_trace_combined = vpacket.trace_vpacket(
Expand All @@ -108,8 +101,6 @@ def time_trace_vpacket(self):
verysimple_opacity_state,
tau_russian,
survival_probability,
enable_full_relativity,
continuum_processes_enabled,
)

assert v_packet.next_line_id == 2773
Expand All @@ -132,12 +123,8 @@ def time_trace_bad_vpacket(self):
verysimple_numba_radial_1d_geometry = (
self.verysimple_numba_radial_1d_geometry
)
enable_full_relativity = self.verysimple_enable_full_relativity
verysimple_time_explosion = self.verysimple_time_explosion
verysimple_opacity_state = self.verysimple_opacity_state
continuum_processes_enabled = (
self.verysimple_continuum_processes_enabled
)
tau_russian = self.verysimple_tau_russian
survival_probability = self.verysimple_survival_probability

Expand All @@ -148,6 +135,4 @@ def time_trace_bad_vpacket(self):
verysimple_opacity_state,
tau_russian,
survival_probability,
enable_full_relativity,
continuum_processes_enabled,
)
12 changes: 10 additions & 2 deletions tardis/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ def no_of_raw_shells(self):
return self.geometry.no_of_shells

@classmethod
def from_config(cls, config, atom_data, legacy_mode_enabled=False):
def from_config(
cls,
config,
atom_data,
):
"""
Create a new SimulationState instance from a Configuration object.
Expand Down Expand Up @@ -314,7 +318,11 @@ def from_config(cls, config, atom_data, legacy_mode_enabled=False):
)

@classmethod
def from_csvy(cls, config, atom_data=None, legacy_mode_enabled=False):
def from_csvy(
cls,
config,
atom_data=None,
):
"""
Create a new SimulationState instance from a Configuration object.
Expand Down
3 changes: 0 additions & 3 deletions tardis/simulation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,6 @@ def from_config(
virtual_packet_logging=False,
show_convergence_plots=False,
show_progress_bars=True,
legacy_mode_enabled=False,
**kwargs,
):
"""
Expand Down Expand Up @@ -672,13 +671,11 @@ def from_config(
simulation_state = SimulationState.from_csvy(
config,
atom_data=atom_data,
legacy_mode_enabled=legacy_mode_enabled,
)
else:
simulation_state = SimulationState.from_config(
config,
atom_data=atom_data,
legacy_mode_enabled=legacy_mode_enabled,
)
# Override with custom packet source from function argument if present
if packet_source is not None:
Expand Down
15 changes: 11 additions & 4 deletions tardis/transport/frame_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
from tardis.transport.montecarlo.configuration.constants import (
C_SPEED_OF_LIGHT,
)
from tardis.transport.montecarlo.configuration.montecarlo_globals import (
ENABLE_FULL_RELATIVITY,
)


@njit(**njit_dict_no_parallel)
def get_doppler_factor(r, mu, time_explosion, enable_full_relativity):
def get_doppler_factor(r, mu, time_explosion):
inv_c = 1 / C_SPEED_OF_LIGHT
inv_t = 1 / time_explosion
beta = r * inv_t * inv_c
if not enable_full_relativity:
if not ENABLE_FULL_RELATIVITY:
return get_doppler_factor_partial_relativity(mu, beta)
else:
return get_doppler_factor_full_relativity(mu, beta)
Expand All @@ -33,7 +36,11 @@ def get_doppler_factor_full_relativity(mu, beta):


@njit(**njit_dict_no_parallel)
def get_inverse_doppler_factor(r, mu, time_explosion, enable_full_relativity):
def get_inverse_doppler_factor(
r,
mu,
time_explosion,
):
"""
Calculate doppler factor for frame transformation
Expand All @@ -46,7 +53,7 @@ def get_inverse_doppler_factor(r, mu, time_explosion, enable_full_relativity):
inv_c = 1 / C_SPEED_OF_LIGHT
inv_t = 1 / time_explosion
beta = r * inv_t * inv_c
if not enable_full_relativity:
if not ENABLE_FULL_RELATIVITY:
return get_inverse_doppler_factor_partial_relativity(mu, beta)
else:
return get_inverse_doppler_factor_full_relativity(mu, beta)
Expand Down
6 changes: 4 additions & 2 deletions tardis/transport/geometry/calculate_distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
SIGMA_THOMSON,
CLOSE_LINE_THRESHOLD,
)
from tardis.transport.montecarlo.configuration.montecarlo_globals import (
ENABLE_FULL_RELATIVITY,
)

from tardis.transport.montecarlo.utils import MonteCarloException
from tardis.transport.montecarlo.r_packet import (
Expand Down Expand Up @@ -68,7 +71,6 @@ def calculate_distance_line(
is_last_line,
nu_line,
time_explosion,
enable_full_relativity,
):
"""
Calculate distance until RPacket is in resonance with the next line
Expand Down Expand Up @@ -105,7 +107,7 @@ def calculate_distance_line(
else:
raise MonteCarloException("nu difference is less than 0.0")

if enable_full_relativity:
if ENABLE_FULL_RELATIVITY:
return calculate_distance_line_full_relativity(
nu_line, nu, time_explosion, r_packet
)
Expand Down
Loading

0 comments on commit 634b4e5

Please sign in to comment.