Skip to content

Commit

Permalink
country roads
Browse files Browse the repository at this point in the history
* added setup function

Signed-off-by: Asish Kumar <[email protected]>

* refactor geometry calculate distances

Signed-off-by: Asish Kumar <[email protected]>

* Refactor montecarlo estimators in benchmark code

Signed-off-by: Asish Kumar <[email protected]>

* add cache and setup functions

Signed-off-by: Asish Kumar <[email protected]>

* add cache and setup functions

Signed-off-by: Asish Kumar <[email protected]>

* ran ruff linter

Signed-off-by: Asish Kumar <[email protected]>

* Thou hath vanquished the redundant variables and functions

Signed-off-by: Asish Kumar <[email protected]>

* fix bugs

Signed-off-by: Asish Kumar <[email protected]>

* change benchmark yml

Signed-off-by: Asish Kumar <[email protected]>

* repeat in class

Signed-off-by: Asish Kumar <[email protected]>

* Benchmark run_tardis with track_rpacket enabled (tardis-sn#2720)

* Benchmark run_tardis with track_rpacket enabled

* Update config to resemble time_run_tardis config

* Fix Benchmark error

* Cache Benchmark Property

* Remove Cached Property decorator

* rounds in benchmarks

Signed-off-by: Asish Kumar <[email protected]>

* fix

Signed-off-by: Asish Kumar <[email protected]>

* fix error in formal integral

Signed-off-by: Asish Kumar <[email protected]>

* more cache

Signed-off-by: Asish Kumar <[email protected]>

* sort by ratio

Signed-off-by: Asish Kumar <[email protected]>

* Donot run docs, benchmarks and stardis tests on draft PRs. (tardis-sn#2761)

* Add ready to review to run tests

* Add if condition to check PR status

* Running stardis tests only on push to master

* Removing osx-64 from workflows

* Add Extend Array Function (tardis-sn#2771)

* Add Extend Array Function

* Fix Typo and restructure

* Restructure

* Doc string update

* Was expecting numpy arrays to be passed by reference but it is not so updating it

* Add test for the extend array function

* Opacity state slice (tardis-sn#2758)

* Added basic sliing operation to opacitystate and set the transport solver to use the bounds of the gemoetry indices

* Reformatted the slicing index

* Added slicing operation with __getitem__

* Added docstring

* removed old slice method

* Ran black

* Added back the 'slice' method because __getitem__ is wacky

* added missing argument

* fixed missing argument

* ran black

* fixed the tests

* ran black

* Updated the slice to use __getitem__ again and modified the opacitystate object defined in the opacities module

* Removed old slice method and print statements

* removed print statement from the test

* added type annotation to OpacityState getitem

* updated numba interface

* Fixes black formatting

* Release Pipeline Fixes (tardis-sn#2767)

* Fix zenodo badge

* Pick from the website

* update badge in credits.rst

* Use the all versions DOI

* Inherit secrets

* Change triggers for testing

* Reset Triggers

* Fix ruff comments issue (tardis-sn#2762)

* Fix ruff comments issue

* Only check files changed

* Testing triggers

* Fix bash commands

* No pager

* fetch depth

* Reset all changes

* cache in setup function

Signed-off-by: Asish Kumar <[email protected]>

* change benchmark yml

Signed-off-by: Asish Kumar <[email protected]>

---------

Signed-off-by: Asish Kumar <[email protected]>
Co-authored-by: Sumit Gupta <[email protected]>
Co-authored-by: KasukabeDefenceForce <[email protected]>
Co-authored-by: Jack O'Brien <[email protected]>
Co-authored-by: Andrew Fullard <[email protected]>
Co-authored-by: Atharva Arya <[email protected]>
  • Loading branch information
6 people authored Aug 2, 2024
1 parent 4f0ab22 commit aa7cd19
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 54 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- reopened
- synchronize
- labeled # benchmarks label required
- ready_for_review
workflow_dispatch:

env:
Expand Down Expand Up @@ -70,8 +71,8 @@ jobs:
- name: Run benchmarks for last 4 commits if not PR
if: github.event_name != 'pull_request_target'
run: |
git log -n 1 --pretty=format:"%H" >> tag_commits.txt
asv run -a rounds=1 HASHFILE:tag_commits.txt --bench transport_montecarlo_single_packet_loop | tee asv-output.log
git log -n 1 --pretty=format:"%H" >> tag_commits.txt
asv run HASHFILE:tag_commits.txt --quick | tee asv-output.log
if grep -q failed asv-output.log; then
echo "Some benchmarks have failed!"
exit 1
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
- reopened
- synchronize
- labeled # requires the `build-docs` label
- ready_for_review

workflow_dispatch: # manual trigger

Expand All @@ -37,6 +38,7 @@ defaults:
jobs:
check-for-changes:
runs-on: ubuntu-latest
if: ${{ !github.event.pull_request.draft }}
outputs:
trigger-check-outcome: ${{ steps.trigger_check.outcome }}
docs-check-outcome: ${{ steps.docs_check.outcome }}
Expand Down
23 changes: 17 additions & 6 deletions .github/workflows/codestyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ name: codestyle
on:
push:
branches:
- "*"

- master
pull_request_target:
branches:
- master
Expand Down Expand Up @@ -37,6 +36,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download Lock File
run: wget -q https://raw.githubusercontent.com/tardis-sn/tardis/master/conda-linux-64.lock
Expand All @@ -57,12 +58,22 @@ jobs:
cache-downloads: true

- name: Show statistics
run: ruff check --statistics --show-fixes . | tee ruff_stats.txt
id: ruff_stats
run: ruff check --statistics --show-fixes $(git --no-pager diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} --) | tee ruff_stats.txt

- name: Show entire output
run: ruff check . --output-format=full | tee ruff_full.txt
id: ruff_complete
run: ruff check --output-format=concise $(git --no-pager diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} --) | tee ruff_full.txt

- name: Statistics output read
id: ruff_stats
uses: juliangruber/[email protected]
with:
path: ruff_stats.txt

- name: Entire output read
id: ruff_complete
uses: juliangruber/[email protected]
with:
path: ruff_full.txt

- name: Find Comment
if: always() && github.event_name == 'pull_request_target'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,6 @@ jobs:

pip_tests:
uses: ./.github/workflows/tests.yml
secrets: inherit
with:
pip_git: true
14 changes: 8 additions & 6 deletions .github/workflows/stardis-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ name: stardis-tests
on:
push:
branches:
- '*'
- master

pull_request:
branches:
- '*'

types:
- opened
- reopened
- synchronize
- ready_for_review
workflow_dispatch:

defaults:
Expand All @@ -22,18 +27,15 @@ jobs:
build:
strategy:
matrix:
label: [osx-64, linux-64]
label: [linux-64]
include:
- os: ubuntu-latest
label: linux-64
prefix: /usr/share/miniconda3/envs/stardis

- os: macos-latest
label: osx-64
prefix: /Users/runner/miniconda3/envs/stardis

name: ${{ matrix.label }}
runs-on: ${{ matrix.os }}
if: ${{ !github.event.pull_request.draft }}
steps:
- uses: actions/checkout@v4
with:
Expand Down
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ The following BibTeX entries are needed for the references:
.. |CITATION| replace:: kerzendorf_2023_10207663

.. |DOI_BADGE| image:: https://img.shields.io/badge/DOI-10.5281/zenodo.3_10207663-blue
:target: https://doi.org/10.5281/zenodo.3_10207663
.. |DOI_BADGE| image:: https://zenodo.org/badge/DOI/10.5281/zenodo.592480.svg
:target: https://doi.org/10.5281/zenodo.592480


.. code-block:: bibtex
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/benchmark_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def config_rpacket_tracking(self):
@functools.cached_property
def tardis_ref_path(self):
ref_data_path = Path(
Path(__file__).parent.parent, "tardis-refdata"
Path(__file__).parent.parent,
"tardis-refdata"
).resolve()
return ref_data_path

Expand Down
1 change: 0 additions & 1 deletion benchmarks/run_tardis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from tardis import run_tardis
from tardis.io.atom_data import AtomData


class BenchmarkRunTardis(BenchmarkBase):
"""
Class to benchmark the `run tardis` function.
Expand Down
3 changes: 3 additions & 0 deletions benchmarks/spectrum_formal_integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

from benchmarks.benchmark_base import BenchmarkBase
from tardis.spectrum import formal_integral

config.THREADING_LAYER = "workqueue"



class BenchmarkTransportMontecarloFormalIntegral(BenchmarkBase):
"""
Class to benchmark the numba formal integral function.
Expand Down
9 changes: 9 additions & 0 deletions benchmarks/transport_montecarlo_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ class BenchmarkTransportMontecarloInteraction(BenchmarkBase):

repeat = 3

def setup(self):
self.Packet = self.packet
self.time_explosion = self.verysimple_time_explosion
self.enable_full_relativity = self.verysimple_enable_full_relativity
self.opacity_state = self.verysimple_opacity_state

repeat = 3

@functools.cache
def setup(self):
self.Packet = self.packet
self.time_explosion = self.verysimple_time_explosion
Expand Down
1 change: 1 addition & 0 deletions benchmarks/transport_montecarlo_packet_trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def time_rpacket_trackers_to_dataframe(self, num_packets, length):
packet_trackers.rpacket_trackers_to_dataframe(
self.TransportState.rpacket_tracker
)

def time_generate_rpacket_tracker_list(self, num_packets, length):
packet_trackers.generate_rpacket_tracker_list(num_packets, length)

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/credits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ The following BibTeX entries are needed for the references:
.. |CITATION| replace:: kerzendorf_2023_10207663

.. |DOI_BADGE| image:: https://img.shields.io/badge/DOI-10.5281/zenodo.3_10207663-blue
:target: https://doi.org/10.5281/zenodo.3_10207663
.. |DOI_BADGE| image:: https://zenodo.org/badge/DOI/10.5281/zenodo.592480.svg
:target: https://doi.org/10.5281/zenodo.592480

.. code-block:: bibtex
Expand Down
35 changes: 35 additions & 0 deletions tardis/opacities/opacity_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,41 @@ def __init__(
self.photo_ion_activation_idx = photo_ion_activation_idx
self.k_packet_idx = k_packet_idx

def __getitem__(self, i: slice):
"""Get a shell or slice of shells of the attributes of the opacity state
Args:
i (slice): shell slice. Will fail if slice is int since class only supports array types
Returns:
OpacityState : a shallow copy of the current instance
"""
# NOTE: This currently will not work with continuum processes since it does not slice those arrays
return OpacityState(
self.electron_density[i],
self.t_electrons[i],
self.line_list_nu,
self.tau_sobolev[:, i],
self.transition_probabilities[:, i],
self.line2macro_level_upper,
self.macro_block_references,
self.transition_type,
self.destination_level_id,
self.transition_line_id,
self.bf_threshold_list_nu,
self.p_fb_deactivation,
self.photo_ion_nu_threshold_mins,
self.photo_ion_nu_threshold_maxs,
self.photo_ion_block_references,
self.chi_bf,
self.x_sect,
self.phot_nus,
self.ff_opacity_factor,
self.emissivities,
self.photo_ion_activation_idx,
self.k_packet_idx,
)


def opacity_state_initialize(
plasma,
Expand Down
13 changes: 9 additions & 4 deletions tardis/transport/montecarlo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from tardis.transport.montecarlo.montecarlo_transport_state import (
MonteCarloTransportState,
)
from tardis.transport.montecarlo.numba_interface import (
from tardis.opacities.opacity_state import (
opacity_state_initialize,
)
from tardis.transport.montecarlo.packet_trackers import (
Expand Down Expand Up @@ -110,16 +110,21 @@ def initialize_transport_state(
packet_collection = self.packet_source.create_packets(
no_of_packets, seed_offset=iteration
)
estimators = initialize_estimator_statistics(
plasma.tau_sobolevs.shape, gamma_shape
)

geometry_state = simulation_state.geometry.to_numba()
opacity_state = opacity_state_initialize(
plasma,
self.line_interaction_type,
self.montecarlo_configuration.DISABLE_LINE_SCATTERING,
)
opacity_state = opacity_state[
simulation_state.geometry.v_inner_boundary_index : simulation_state.geometry.v_outer_boundary_index
]

estimators = initialize_estimator_statistics(
opacity_state.tau_sobolev.shape, gamma_shape
)

transport_state = MonteCarloTransportState(
packet_collection,
estimators,
Expand Down
35 changes: 35 additions & 0 deletions tardis/transport/montecarlo/numba_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,41 @@ def __init__(
self.photo_ion_activation_idx = photo_ion_activation_idx
self.k_packet_idx = k_packet_idx

def __getitem__(self, i: slice):
"""Get a shell or slice of shells of the attributes of the opacity state
Args:
i (slice): shell slice. Will fail if slice is int since class only supports array types
Returns:
OpacityState : a shallow copy of the current instance
"""
# NOTE: This currently will not work with continuum processes since it does not slice those arrays
return OpacityState(
self.electron_density[i],
self.t_electrons[i],
self.line_list_nu,
self.tau_sobolev[:, i],
self.transition_probabilities[:, i],
self.line2macro_level_upper,
self.macro_block_references,
self.transition_type,
self.destination_level_id,
self.transition_line_id,
self.bf_threshold_list_nu,
self.p_fb_deactivation,
self.photo_ion_nu_threshold_mins,
self.photo_ion_nu_threshold_maxs,
self.photo_ion_block_references,
self.chi_bf,
self.x_sect,
self.phot_nus,
self.ff_opacity_factor,
self.emissivities,
self.photo_ion_activation_idx,
self.k_packet_idx,
)


def opacity_state_initialize(
plasma,
Expand Down
46 changes: 21 additions & 25 deletions tardis/transport/montecarlo/packet_trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
("shell_id", int64[:]),
("interaction_type", int64[:]),
("num_interactions", int64),
("extend_factor", int64),
]


Expand Down Expand Up @@ -47,6 +48,8 @@ class RPacketTracker(object):
Type of interaction the rpacket undergoes
num_interactions : int
Internal counter for the interactions that a particular RPacket undergoes
extend_factor : int
The factor by which to extend the properties array when the size limit is reached
"""

def __init__(self, length):
Expand All @@ -61,34 +64,27 @@ def __init__(self, length):
self.shell_id = np.empty(self.length, dtype=np.int64)
self.interaction_type = np.empty(self.length, dtype=np.int64)
self.num_interactions = 0
self.extend_factor = 2

def extend_array(self, array, array_length):
temp_array = np.empty(
array_length * self.extend_factor, dtype=array.dtype
)
temp_array[:array_length] = array
return temp_array

def track(self, r_packet):
if self.num_interactions >= self.length:
temp_length = self.length * 2
temp_status = np.empty(temp_length, dtype=np.int64)
temp_r = np.empty(temp_length, dtype=np.float64)
temp_nu = np.empty(temp_length, dtype=np.float64)
temp_mu = np.empty(temp_length, dtype=np.float64)
temp_energy = np.empty(temp_length, dtype=np.float64)
temp_shell_id = np.empty(temp_length, dtype=np.int64)
temp_interaction_type = np.empty(temp_length, dtype=np.int64)

temp_status[: self.length] = self.status
temp_r[: self.length] = self.r
temp_nu[: self.length] = self.nu
temp_mu[: self.length] = self.mu
temp_energy[: self.length] = self.energy
temp_shell_id[: self.length] = self.shell_id
temp_interaction_type[: self.length] = self.interaction_type

self.status = temp_status
self.r = temp_r
self.nu = temp_nu
self.mu = temp_mu
self.energy = temp_energy
self.shell_id = temp_shell_id
self.interaction_type = temp_interaction_type
self.length = temp_length
self.status = self.extend_array(self.status, self.length)
self.r = self.extend_array(self.r, self.length)
self.nu = self.extend_array(self.nu, self.length)
self.mu = self.extend_array(self.mu, self.length)
self.energy = self.extend_array(self.energy, self.length)
self.shell_id = self.extend_array(self.shell_id, self.length)
self.interaction_type = self.extend_array(
self.interaction_type, self.length
)
self.length = self.length * self.extend_factor

self.index = r_packet.index
self.seed = r_packet.seed
Expand Down
Loading

0 comments on commit aa7cd19

Please sign in to comment.