-
-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved the ASV framework; Added benchmarks taking the unit tests.
- Loading branch information
Showing
57 changed files
with
5,797 additions
and
68 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
Basic TARDIS Benchmark. | ||
""" | ||
from asv_runner.benchmarks.mark import skip_benchmark | ||
from benchmarks.benchmark_base import BenchmarkBase | ||
|
||
|
||
@skip_benchmark | ||
class BenchmarkXx(BenchmarkBase): | ||
""" | ||
Class to benchmark the Xx function. | ||
""" | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def time_template(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
Basic TARDIS Benchmark. | ||
""" | ||
import numpy as np | ||
from asv_runner.benchmarks.mark import parameterize, skip_benchmark | ||
|
||
from benchmarks.benchmark_base import BenchmarkBase | ||
from tardis.energy_input.samplers import create_energy_cdf | ||
|
||
|
||
# @skip_benchmark | ||
class BenchmarkEnergyInputEnergySource(BenchmarkBase): | ||
""" | ||
Class to benchmark the run_tardis function. | ||
""" | ||
|
||
@parameterize({"Energy CDF": [ | ||
{ | ||
"energy": np.array([100.0, 50.0]), | ||
"intensity": np.array([1.0, 1.0]) | ||
}, | ||
{ | ||
"energy": np.array([50.0, 100.0]), | ||
"intensity": np.array([0.0, 1.0]) | ||
}, | ||
]}) | ||
def time_create_energy_cdf(self, values: dict): | ||
create_energy_cdf(values.get('energy'), values.get('intensity')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
Basic TARDIS Benchmark. | ||
""" | ||
import numpy as np | ||
from asv_runner.benchmarks.mark import skip_benchmark | ||
|
||
from tardis.energy_input import H_CGS_KEV | ||
from tardis.energy_input.GXPacket import GXPacketStatus, GXPacket | ||
from tardis.energy_input.gamma_ray_grid import move_packet | ||
|
||
|
||
# @skip_benchmark | ||
class BenchmarkEnergyInputGammaRayGrid: | ||
""" | ||
Class to benchmark the gamma ray grid function. | ||
""" | ||
|
||
def time_move_packet(self): | ||
packet = GXPacket( | ||
location=np.array([1.36375693e13, 4.10589818e14, 9.11718168e14]), | ||
direction=np.array([-0.97113853, 0.23134328, -0.05805379]), | ||
energy_rf=1e52, | ||
energy_cmf=1e52, | ||
nu_rf=1000.0e3 / H_CGS_KEV, | ||
nu_cmf=1000.0e3 / H_CGS_KEV, | ||
status=GXPacketStatus.IN_PROCESS, | ||
shell=1, | ||
time_current=1000, | ||
) | ||
distance = 1.0e15 | ||
|
||
move_packet(packet, distance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
Basic TARDIS Benchmark. | ||
""" | ||
import numpy as np | ||
from asv_runner.benchmarks.mark import parameterize, skip_benchmark | ||
|
||
from benchmarks.benchmark_base import BenchmarkBase | ||
from tardis.energy_input import H_CGS_KEV, ELECTRON_MASS_ENERGY_KEV | ||
from tardis.energy_input.GXPacket import GXPacketStatus, GXPacket | ||
from tardis.energy_input.gamma_ray_interactions import pair_creation_packet, scatter_type | ||
|
||
|
||
# @skip_benchmark | ||
class BenchmarkEnergyInputGammaRayInteractions(BenchmarkBase): | ||
""" | ||
Class to benchmark the gamma ray interactions function. | ||
""" | ||
|
||
def __init__(self): | ||
self.basic_gamma_ray = GXPacket( | ||
location=np.array([1.36375693e13, 4.10589818e14, 9.11718168e14]), | ||
direction=np.array([-0.97113853, 0.23134328, -0.05805379]), | ||
energy_rf=1e52, | ||
energy_cmf=1e52, | ||
nu_rf=1000.0e3 / H_CGS_KEV, | ||
nu_cmf=1000.0e3 / H_CGS_KEV, | ||
status=GXPacketStatus.IN_PROCESS, | ||
shell=1, | ||
time_current=1000, | ||
) | ||
|
||
def time_pair_creation(self): | ||
np.random.seed(2) | ||
self.basic_gamma_ray.nu_cmf = 2 * ELECTRON_MASS_ENERGY_KEV / H_CGS_KEV | ||
pair_creation_packet(self.basic_gamma_ray) | ||
|
||
@parameterize({"Scatter type": [ | ||
{ | ||
"compton_opacity": 1, | ||
"photoabsorption_opacity": 0, | ||
"total_opacity": 1, | ||
}, | ||
{ | ||
"compton_opacity": 0, | ||
"photoabsorption_opacity": 1, | ||
"total_opacity": 1, | ||
}, | ||
{ | ||
"compton_opacity": 0, | ||
"photoabsorption_opacity": 0, | ||
"total_opacity": 1, | ||
}, | ||
]}) | ||
def time_scatter_type(self, values: dict): | ||
scatter_type( | ||
values.get('compton_opacity'), values.get('photoabsorption_opacity'), values.get('total_opacity') | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
""" | ||
Basic TARDIS Benchmark. | ||
""" | ||
import astropy.units as u | ||
from asv_runner.benchmarks.mark import skip_benchmark | ||
|
||
from benchmarks.benchmark_base import BenchmarkBase | ||
from tardis.energy_input.energy_source import get_all_isotopes, setup_input_energy | ||
from tardis.energy_input.gamma_ray_transport import create_isotope_dicts, create_inventories_dict, \ | ||
calculate_total_decays, decay_chain_energies, calculate_average_energies, calculate_energy_per_mass | ||
|
||
|
||
# @skip_benchmark | ||
class BenchmarkEnergyInputGammaRayTransport(BenchmarkBase): | ||
""" | ||
Class to benchmark the gamma ray transport function. | ||
""" | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def time_calculate_cell_masses(self): | ||
""" | ||
Function to test calculation of shell masses. | ||
""" | ||
self.gamma_ray_simulation_state.composition.calculate_cell_masses( | ||
self.gamma_ray_simulation_state.geometry.volume | ||
) | ||
|
||
def time_calculate_total_decays_activity(self): | ||
# setup of decay test | ||
time_delta = 1.0 * u.s | ||
|
||
# calculating necessary values | ||
composition = self.gamma_ray_simulation_state.composition | ||
cell_masses = composition.calculate_cell_masses( | ||
self.gamma_ray_simulation_state.geometry.volume | ||
) | ||
isotopic_mass_fractions = ( | ||
self.gamma_ray_simulation_state.composition.isotopic_mass_fraction | ||
) | ||
iso_dict = create_isotope_dicts(isotopic_mass_fractions, cell_masses) | ||
inv_dict = create_inventories_dict(iso_dict) | ||
|
||
calculate_total_decays(inv_dict, time_delta) | ||
|
||
def time_calculate_total_decays_activity_chain(self): | ||
time_delta = 1.0 * u.d.to(u.s) | ||
|
||
composition = self.gamma_ray_simulation_state.composition | ||
cell_masses = composition.calculate_cell_masses( | ||
self.gamma_ray_simulation_state.geometry.volume | ||
) | ||
isotopic_mass_fractions = ( | ||
self.gamma_ray_simulation_state.composition.isotopic_mass_fraction | ||
) | ||
iso_dict = create_isotope_dicts(isotopic_mass_fractions, cell_masses) | ||
inv_dict = create_inventories_dict(iso_dict) | ||
|
||
calculate_total_decays(inv_dict, time_delta) | ||
|
||
def time_isotope_dicts(self): | ||
isotopic_mass_fractions = ( | ||
self.gamma_ray_simulation_state.composition.isotopic_mass_fraction | ||
) | ||
composition = self.gamma_ray_simulation_state.composition | ||
cell_masses = composition.calculate_cell_masses( | ||
self.gamma_ray_simulation_state.geometry.volume | ||
) | ||
create_isotope_dicts(isotopic_mass_fractions, cell_masses) | ||
|
||
def time_average_energies(self): | ||
isotopic_mass_fraction = ( | ||
self.gamma_ray_simulation_state.composition.isotopic_mass_fraction | ||
) | ||
gamma_ray_lines = self.atomic_dataset.decay_radiation_data | ||
|
||
all_isotope_names = get_all_isotopes(isotopic_mass_fraction) | ||
|
||
for isotope_name in all_isotope_names: | ||
setup_input_energy( | ||
gamma_ray_lines[ | ||
gamma_ray_lines.index == isotope_name.replace("-", "") | ||
], | ||
"g", | ||
) | ||
|
||
def time_decay_energy_chain(self): | ||
isotopic_mass_fractions = ( | ||
self.gamma_ray_simulation_state.composition.isotopic_mass_fraction | ||
) | ||
|
||
composition = self.gamma_ray_simulation_state.composition | ||
cell_masses = composition.calculate_cell_masses( | ||
self.gamma_ray_simulation_state.geometry.volume | ||
) | ||
iso_dict = create_isotope_dicts(isotopic_mass_fractions, cell_masses) | ||
inventories_dict = create_inventories_dict(iso_dict) | ||
gamma_ray_lines = self.atomic_dataset.decay_radiation_data | ||
|
||
total_decays = calculate_total_decays(inventories_dict, 1.0 * u.s) | ||
|
||
( | ||
average_energies, | ||
_, | ||
_, | ||
) = calculate_average_energies(isotopic_mass_fractions, gamma_ray_lines) | ||
|
||
decay_chain_energies( | ||
average_energies, | ||
total_decays, | ||
) | ||
|
||
def time_energy_per_mass(self): | ||
isotopic_mass_fractions = ( | ||
self.gamma_ray_simulation_state.composition.isotopic_mass_fraction | ||
) | ||
composition = self.gamma_ray_simulation_state.composition | ||
cell_masses = composition.calculate_cell_masses( | ||
self.gamma_ray_simulation_state.geometry.volume | ||
) | ||
iso_dict = create_isotope_dicts(isotopic_mass_fractions, cell_masses) | ||
inventories_dict = create_inventories_dict(iso_dict) | ||
total_decays = calculate_total_decays(inventories_dict, 1.0 * u.s) | ||
|
||
gamma_ray_lines = self.atomic_dataset.decay_radiation_data | ||
average_energies = calculate_average_energies( | ||
isotopic_mass_fractions, gamma_ray_lines | ||
) | ||
decay_energy = decay_chain_energies( | ||
average_energies[0], | ||
total_decays, | ||
) | ||
calculate_energy_per_mass( | ||
decay_energy, isotopic_mass_fractions, cell_masses | ||
) |
Oops, something went wrong.