Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample coomiit #24

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 61 additions & 17 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- master

pull_request_target:
pull_request:
branches:
- master

Expand All @@ -26,15 +26,14 @@ defaults:

jobs:
build:
if: github.repository_owner == 'tardis-sn' &&
(github.event_name == 'push' ||
if: github.event_name == 'push' ||
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request_target' &&
contains(github.event.pull_request.labels.*.name, 'benchmarks')))
(github.event_name == 'pull_request' &&
contains(github.event.pull_request.labels.*.name, 'benchmarks'))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
if: github.event_name != 'pull_request_target'
if: github.event_name != 'pull_request'
with:
fetch-depth: 0

Expand All @@ -43,7 +42,7 @@ jobs:
with:
ref: ${{ github.sha }}
fetch-depth: 0
if: github.event_name == 'pull_request_target'
if: github.event_name == 'pull_request'

- name: Restore Atom Data
uses: actions/cache/restore@v4
Expand All @@ -66,6 +65,13 @@ jobs:
path: benchmarks/data/kurucz_cd23_chianti_H_He.h5
key: atom-data

# - name: Copy atom data to refdata
# run: |
# mkdir -p tardis-refdata/atom_data
# cp benchmarks/data/kurucz_cd23_chianti_H_He.h5 tardis-refdata/atom_data/

# # - name: Setup tmate session
# # uses: mxschmitt/action-tmate@v3
- name: Setup Mamba
uses: mamba-org/setup-micromamba@v1
with:
Expand All @@ -84,7 +90,7 @@ jobs:
run: asv machine --yes

- name: Run benchmarks for last 5 commits if not PR
if: github.event_name != 'pull_request_target'
if: github.event_name != 'pull_request'
run: |
git log -n 5 --pretty=format:"%H" >> tag_commits.txt
asv run HASHFILE:tag_commits.txt | tee asv-output.log
Expand All @@ -93,16 +99,20 @@ jobs:
exit 1
fi

# - name: ASV benchmarks
# if: github.event_name != 'pull_request'
# run: asv run --bench just-discover

- name: Generate Graphs and HTML
if: github.event_name != 'pull_request_target'
if: github.event_name != 'pull_request'
run: asv publish

- name: Delete env files
if: github.event_name != 'pull_request_target'
if: github.event_name != 'pull_request'
run: rm -r .asv/env

- name: Push results to results repository
if: github.event_name != 'pull_request_target'
if: github.event_name != 'pull_request'
continue-on-error: true
uses: cpina/github-action-push-to-another-repository@main
env:
Expand All @@ -116,20 +126,20 @@ jobs:
target-directory: .asv

- name: Compare HEAD with master if PR
if: github.event_name == 'pull_request_target'
if: github.event_name == 'pull_request'
continue-on-error: true # TODO: step failed sporadically while testing
run: |
asv continuous ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | tee asv-cont-output.log
asv continuous ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | tee asv-cont-output.log
if grep -q failed asv-cont-output.log; then
echo "Some benchmarks have errors!"
exit 1
fi

- name: Compare Master and PR head
run: asv compare ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | tee asv-compare-output.log
run: asv compare master HEAD --config asv.conf.json | tee asv-compare-output.log

- name: Compare Master and PR head but only show changed results
run: asv compare ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} --only-changed | tee asv-compare-changed-output.log
run: asv compare master HEAD --only-changed --config asv.conf.json | tee asv-compare-changed-output.log

- name: Benchmarks compare output
id: asv_pr_vs_master
Expand All @@ -143,16 +153,50 @@ jobs:
with:
path: asv-compare-changed-output.log

- name: Run benchmarks for base to head commits of PR
if: github.event_name == 'pull_request_target'
run: |
mkdir -p PR-${{ github.event.number }}
cd PR-${{ github.event.number }}
asv run ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} | tee asv-output-PR.log
if grep -q failed asv-output-PR.log; then
echo "Some benchmarks have failed!"
exit 1
fi

- name: Generate Graphs and HTML of PR
if: github.event_name == 'pull_request_target'
working-directory: PR-${{ github.event.number }}
run: asv publish

- name: Delete env files of PR
if: github.event_name == 'pull_request_target'
run: rm -r PR-${{ github.event.number }}/.asv/env

- name: Push results of PR to results repository
if: github.event_name == 'pull_request_target'
continue-on-error: true
uses: cpina/github-action-push-to-another-repository@main
env:
API_TOKEN_GITHUB: ${{ secrets.BOT_TOKEN }}
with:
source-directory: PR-${{ github.event.number }}
destination-github-username: tardis-sn
destination-repository-name: tardis-benchmarks
user-email: [email protected]
target-branch: main
target-directory: PR

- name: Find Comment
if: always() && github.event_name == 'pull_request_target'
if: always() && github.event_name == 'pull_request'
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ github.event.number }}
body-includes: I ran benchmarks as you asked

- name: Post comment
if: github.event_name == 'pull_request_target'
if: github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.BOT_TOKEN }}
Expand Down
48 changes: 38 additions & 10 deletions benchmarks/benchmark_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,16 @@
from tardis.io.configuration.config_reader import Configuration
from tardis.io.util import YAMLLoader, yaml_load_file
from tardis.model import SimulationState
from tardis.simulation import Simulation
from tardis.tests.fixtures.atom_data import DEFAULT_ATOM_DATA_UUID
from tardis.tests.fixtures.regression_data import RegressionData
from tardis.transport.montecarlo import RPacket
from tardis.transport.montecarlo.numba_interface import (
NumbaModel,
opacity_state_initialize,
)
from tardis.transport.montecarlo.packet_collections import (
VPacketCollection,
)
from tardis.simulation import Simulation
from tardis.tests.fixtures.atom_data import DEFAULT_ATOM_DATA_UUID
from tardis.tests.fixtures.regression_data import RegressionData
from tardis.transport.montecarlo import RPacket, opacity_state_initialize
from tardis.transport.montecarlo.packet_collections import (
VPacketCollection,
)


class BenchmarkBase:
Expand Down Expand Up @@ -67,8 +62,11 @@ def tardis_config_verysimple(self):
@property
def tardis_ref_path(self):
# TODO: This route is fixed but needs to get from the arguments given in the command line.
# /app/tardis-refdata
return "/app/tardis-refdata"
ref_data_path = Path(
Path(__file__).parent.parent,
"tardis-refdata",
).resolve()
return ref_data_path

@property
def atomic_dataset(self) -> AtomData:
Expand Down Expand Up @@ -258,6 +256,36 @@ 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
)

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

@property
Expand Down
16 changes: 13 additions & 3 deletions benchmarks/transport_montecarlo_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ 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)
interaction.thomson_scatter(
packet, time_explosion, enable_full_relativity
)

assert np.abs(packet.mu - init_mu) > 1e-7
assert np.abs(packet.nu - init_nu) > 1e-7
Expand All @@ -46,7 +49,9 @@ def time_line_scatter(self, line_interaction_type):
init_nu = packet.nu
init_energy = packet.energy
packet.initialize_line_id(
self.verysimple_opacity_state, self.verysimple_time_explosion
self.verysimple_opacity_state,
self.verysimple_time_explosion,
self.verysimple_enable_full_relativity,
)
time_explosion = self.verysimple_time_explosion

Expand All @@ -55,6 +60,8 @@ 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,
)

assert np.abs(packet.mu - init_mu) > 1e-7
Expand Down Expand Up @@ -88,7 +95,9 @@ def time_line_emission(self, test_packet):
packet.mu = test_packet["mu"]
packet.energy = test_packet["energy"]
packet.initialize_line_id(
self.verysimple_opacity_state, self.verysimple_time_explosion
self.verysimple_opacity_state,
self.verysimple_time_explosion,
self.verysimple_enable_full_relativity,
)

time_explosion = self.verysimple_time_explosion
Expand All @@ -98,6 +107,7 @@ 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
7 changes: 6 additions & 1 deletion benchmarks/transport_montecarlo_numba_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ class BenchmarkMontecarloMontecarloNumbaNumbaInterface(BenchmarkBase):
def time_opacity_state_initialize(self, input_params):
line_interaction_type = input_params
plasma = self.nb_simulation_verysimple.plasma
numba_interface.opacity_state_initialize(plasma, line_interaction_type)
numba_interface.opacity_state_initialize(
plasma,
line_interaction_type,
self.verysimple_disable_line_scattering,
self.verysimple_continuum_processes_enabled,
)

if line_interaction_type == "scatter":
np.zeros(1, dtype=np.int64)
Expand Down
17 changes: 15 additions & 2 deletions benchmarks/transport_montecarlo_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,22 @@ def time_calculate_distance_boundary(self, packet_params):
{
"packet": {"nu_line": 0.1, "is_last_line": True},
"expected": None,
"enable_full_relativity": True,
},
{
"packet": {"nu_line": 0.2, "is_last_line": False},
"expected": None,
"enable_full_relativity": True,
},
{
"packet": {"nu_line": 0.5, "is_last_line": False},
"expected": utils.MonteCarloException,
"enable_full_relativity": False,
},
{
"packet": {"nu_line": 0.6, "is_last_line": False},
"expected": utils.MonteCarloException,
"enable_full_relativity": False,
},
]
}
Expand All @@ -99,11 +103,14 @@ 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
self.static_packet.r,
self.static_packet.mu,
time_explosion,
enable_full_relativity,
)
comov_nu = self.static_packet.nu * doppler_factor

Expand All @@ -115,6 +122,7 @@ 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 @@ -179,16 +187,19 @@ def time_get_random_mu(self):
"cur_line_id": 0,
"distance_trace": 1e12,
"time_explosion": 5.2e7,
"enable_full_relativity": True,
},
{
"cur_line_id": 0,
"distance_trace": 0,
"time_explosion": 5.2e7,
"enable_full_relativity": True,
},
{
"cur_line_id": 1,
"distance_trace": 1e5,
"time_explosion": 1e10,
"enable_full_relativity": False,
},
]
}
Expand All @@ -197,12 +208,14 @@ def time_update_line_estimators(self, parameters):
cur_line_id = parameters["cur_line_id"]
distance_trace = parameters["distance_trace"]
time_explosion = parameters["time_explosion"]
enable_full_relativity = parameters["enable_full_relativity"]
update_line_estimators(
self.estimators,
self.static_packet,
cur_line_id,
distance_trace,
time_explosion,
enable_full_relativity,
)

@parameterize(
Expand Down
Loading
Loading