Skip to content

Commit

Permalink
Merge branch 'tardis-sn:master' into line-interaction-radius
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthak-dv authored Jul 13, 2024
2 parents 046f3b8 + 17b1da4 commit dbc3b09
Show file tree
Hide file tree
Showing 23 changed files with 5,077 additions and 506 deletions.
32 changes: 32 additions & 0 deletions .github/actions/setup_env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "Setup environment"
description: "Sets up environment for tardis and caches it"

inputs:
os-label:
description: "os label for lock file, default linux"
required: true
default: "linux"

runs:
using: "composite"
steps:
- name: Download Lock File
run: wget -q https://raw.githubusercontent.com/tardis-sn/tardis/master/conda-${{ inputs.os-label }}.lock
if: matrix.pip == true
shell: bash

- name: Generate Cache Key
run: |
file_hash=$(cat conda-${{ inputs.os-label }}.lock | shasum -a 256 | cut -d' ' -f1)
echo "file_hash=$file_hash" >> "${GITHUB_OUTPUT}"
id: cache-environment-key
shell: bash

- uses: mamba-org/setup-micromamba@v1
with:
environment-file: conda-${{ inputs.os-label }}.lock
cache-environment-key: ${{ steps.cache-environment-key.outputs.file_hash }}
cache-downloads-key: ${{ steps.cache-environment-key.outputs.file_hash }}
environment-name: tardis
cache-environment: true
cache-downloads: true
20 changes: 5 additions & 15 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,18 @@ jobs:
ref: ${{ github.event.pull_request.head.sha }}
if: github.event_name == 'pull_request_target'

- name: Generate Cache Key
run: |
file_hash=$(cat conda-linux-64.lock | shasum -a 256 | cut -d' ' -f1)
echo "file_hash=$file_hash" >> "${GITHUB_OUTPUT}"
id: cache-environment-key

- name: Setup LFS
uses: ./.github/actions/setup_lfs

- name: Setup environment
uses: ./.github/actions/setup_env
with:
os-label: linux-64

- name: Copy atom_data
run: |
mkdir -p ~/Downloads/tardis-data && cp -a ./tardis-refdata/atom_data/. ~/Downloads/tardis-data
- uses: mamba-org/setup-micromamba@v1
with:
environment-file: conda-linux-64.lock
cache-environment-key: ${{ steps.cache-environment-key.outputs.file_hash }}
cache-downloads-key: ${{ steps.cache-environment-key.outputs.file_hash }}
environment-name: tardis
cache-environment: true
cache-downloads: true

- name: Install package
run: pip install -e .

Expand Down
21 changes: 4 additions & 17 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,10 @@ jobs:
env:
KEY_SECRET_JSON: ${{ secrets.ZENODO_KEY_SECRET_JSON }}

- name: Download Lock File
run: wget -q https://raw.githubusercontent.com/tardis-sn/tardis/master/conda-linux-64.lock

- name: Generate Cache Key
run: |
file_hash=$(cat conda-linux-64.lock | shasum -a 256 | cut -d' ' -f1)
echo "file_hash=$file_hash" >> "${GITHUB_OUTPUT}"
id: cache-environment-key

- uses: mamba-org/setup-micromamba@v1
with:
environment-file: conda-linux-64.lock
cache-environment-key: ${{ steps.cache-environment-key.outputs.file_hash }}
cache-downloads-key: ${{ steps.cache-environment-key.outputs.file_hash }}
environment-name: tardis
cache-environment: true
cache-downloads: true
- name: Setup environment
uses: ./.github/actions/setup_env
with:
os-label: linux-64

- name: Run Notebook
run: jupyter nbconvert gather_data.ipynb --to html --execute --ExecutePreprocessor.timeout=6000
Expand Down
35 changes: 13 additions & 22 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ on:
env:
CACHE_NUMBER: 0 # increase to reset cache manually
PYTEST_FLAGS: --tardis-refdata=${{ github.workspace }}/tardis-refdata --tardis-regression-data=${{ github.workspace }}/tardis-regression-data
--cov=tardis --cov-report=xml --cov-report=html
--cov=tardis --cov-report=xml --cov-report=html
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

concurrency:
Expand All @@ -39,9 +39,9 @@ jobs:
strategy:
matrix:
pip: [true, false]
label: [osx-64, linux-64]
label: [osx-arm64, linux-64]
include:
- label: osx-64
- label: osx-arm64
os: macos-latest
prefix: /Users/runner/miniconda3/envs/tardis

Expand All @@ -56,25 +56,11 @@ jobs:

- name: Setup LFS
uses: ./.github/actions/setup_lfs

- name: Download Lock File
run: wget -q https://raw.githubusercontent.com/tardis-sn/tardis/master/conda-${{ matrix.label }}.lock
if: matrix.pip == true

- name: Generate Cache Key
run: |
file_hash=$(cat conda-${{ matrix.label }}.lock | shasum -a 256 | cut -d' ' -f1)
echo "file_hash=$file_hash" >> "${GITHUB_OUTPUT}"
id: cache-environment-key

- uses: mamba-org/setup-micromamba@v1
with:
environment-file: conda-${{ matrix.label }}.lock
cache-environment-key: ${{ steps.cache-environment-key.outputs.file_hash }}
cache-downloads-key: ${{ steps.cache-environment-key.outputs.file_hash }}
environment-name: tardis
cache-environment: true
cache-downloads: true
- name: Setup environment
uses: ./.github/actions/setup_env
with:
os-label: ${{ matrix.label }}

- name: Install package editable
run: |
Expand All @@ -100,7 +86,12 @@ jobs:
echo "TARDIS_PIP_PATH=$directory_path" >> $GITHUB_ENV
- name: Run tests
run: pytest tardis ${{ env.PYTEST_FLAGS }}
run: pytest tardis ${{ env.PYTEST_FLAGS }} -m "not continuum"
working-directory: ${{ env.TARDIS_PIP_PATH }}
if: always()

- name: Run continuum tests
run: pytest tardis ${{ env.PYTEST_FLAGS }} -m continuum
working-directory: ${{ env.TARDIS_PIP_PATH }}
if: always()

Expand Down
21 changes: 4 additions & 17 deletions .github/workflows/update-refdata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,10 @@ jobs:
- name: Setup LFS
uses: ./.github/actions/setup_lfs

- name: Download Lock File
run: wget -q https://raw.githubusercontent.com/tardis-sn/tardis/master/conda-linux-64.lock

- name: Generate Cache Key
run: |
file_hash=$(cat conda-linux-64.lock | shasum -a 256 | cut -d' ' -f1)
echo "file_hash=$file_hash" >> "${GITHUB_OUTPUT}"
id: cache-environment-key

- uses: mamba-org/setup-micromamba@v1
with:
environment-file: conda-linux-64.lock
cache-environment-key: ${{ steps.cache-environment-key.outputs.file_hash }}
cache-downloads-key: ${{ steps.cache-environment-key.outputs.file_hash }}
environment-name: tardis
cache-environment: true
cache-downloads: true
- name: Setup environment
uses: ./.github/actions/setup_env
with:
os-label: linux-64

- name: Install package
run: pip install -e .
Expand Down
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Alice Harpole <[email protected]>
Alice Harpole <[email protected]> Alice Harpole <[email protected]>

Aman Kumar <[email protected]>
Asish Kumar <[email protected]>

Andreas Flörs <[email protected]>
Andreas Flörs <[email protected]> Andreas Flörs <[email protected]>
Expand Down
84 changes: 69 additions & 15 deletions benchmarks/benchmark_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@

import astropy.units as u
import numpy as np
import pandas as pd
from numba import njit

from benchmarks.util.nlte import NLTE
from tardis import run_tardis
from tardis.io.atom_data import AtomData
from tardis.io.configuration import config_reader
from tardis.io.configuration.config_reader import Configuration
from tardis.io.util import YAMLLoader, yaml_load_file
from tardis.model import SimulationState
from tardis.model.geometry.radial1d import NumbaRadial1DGeometry
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 (
opacity_state_initialize,
)
from tardis.transport.montecarlo import RPacket, montecarlo_configuration
from tardis.transport.montecarlo.estimators import radfield_mc_estimators
from tardis.transport.montecarlo.numba_interface import opacity_state_initialize
from tardis.transport.montecarlo.packet_collections import (
VPacketCollection,
)
from tardis.transport.montecarlo.packet_trackers import RPacketTracker


class BenchmarkBase:
Expand Down Expand Up @@ -350,13 +351,66 @@ def generate_reference(self):
return option

@property
def tardis_ref_data(self):
# TODO: This function is not working in the benchmarks.
if self.generate_reference:
mode = "w"
else:
mode = "r"
with pd.HDFStore(
f"{self.tardis_ref_path}/unit_test_data.h5", mode=mode
) as store:
yield store
def verysimple_radfield_mc_estimators(self):
plasma = self.nb_simulation_verysimple.plasma
return radfield_mc_estimators.initialize_estimator_statistics(
plasma.tau_sobolevs.shape, plasma.gamma.shape
)

@property
def montecarlo_configuration(self):
return montecarlo_configuration.MonteCarloConfiguration()

@property
def rpacket_tracker(self):
return RPacketTracker(0)

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

@property
def simulation_rpacket_tracking_enabled(self):
config_verysimple = self.config_verysimple
config_verysimple.montecarlo.iterations = 3
config_verysimple.montecarlo.no_of_packets = 4000
config_verysimple.montecarlo.last_no_of_packets = -1
config_verysimple.spectrum.virtual.virtual_packet_logging = True
config_verysimple.montecarlo.no_of_virtual_packets = 1
config_verysimple.montecarlo.tracking.track_rpacket = True
config_verysimple.spectrum.num = 2000
atomic_data = deepcopy(self.atomic_dataset)
sim = run_tardis(
config_verysimple,
atom_data=atomic_data,
show_convergence_plots=False,
)
return sim

@property
def geometry(self):
return NumbaRadial1DGeometry(
r_inner=np.array([6.912e14, 8.64e14], dtype=np.float64),
r_outer=np.array([8.64e14, 1.0368e15], dtype=np.float64),
v_inner=np.array([-1, -1], dtype=np.float64),
v_outer=np.array([-1, -1], dtype=np.float64),
)


@property
def estimators(self):
return radfield_mc_estimators.RadiationFieldMCEstimators(
j_estimator=np.array([0.0, 0.0], dtype=np.float64),
nu_bar_estimator=np.array([0.0, 0.0], dtype=np.float64),
j_blue_estimator=np.array(
[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], dtype=np.float64
),
Edotlu_estimator=np.array(
[[0.0, 0.0, 1.0], [0.0, 0.0, 1.0]], dtype=np.float64
),
photo_ion_estimator=np.empty((0, 0), dtype=np.float64),
stim_recomb_estimator=np.empty((0, 0), dtype=np.float64),
bf_heating_estimator=np.empty((0, 0), dtype=np.float64),
stim_recomb_cooling_estimator=np.empty((0, 0), dtype=np.float64),
photo_ion_estimator_statistics=np.empty((0, 0), dtype=np.int64),
)
10 changes: 2 additions & 8 deletions benchmarks/run_tardis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from benchmarks.benchmark_base import BenchmarkBase
from tardis import run_tardis
from tardis.io.configuration.config_reader import Configuration


class BenchmarkRunTardis(BenchmarkBase):
"""
Expand All @@ -14,12 +12,8 @@ class BenchmarkRunTardis(BenchmarkBase):

def __init__(self):
super().__init__()
self.config = None

def setup(self):
filename = "data/tardis_configv1_benchmark.yml"
path = self.get_relative_path(filename)
self.config = Configuration.from_yaml(path)
self.path = self.get_relative_path(filename)

def time_run_tardis(self):
run_tardis(self.config, log_level="ERROR", show_progress_bars=False)
run_tardis(self.path, log_level="ERROR", show_progress_bars=False)
68 changes: 68 additions & 0 deletions benchmarks/transport_geometry_calculate_distances.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from asv_runner.benchmarks.mark import parameterize

import tardis.transport.frame_transformations as frame_transformations
import tardis.transport.geometry.calculate_distances as calculate_distances
from benchmarks.benchmark_base import BenchmarkBase


class BenchmarkTransportGeometryCalculateDistances(BenchmarkBase):
"""
Class to benchmark the calculate distances function.
"""

@property
def model(self):
return 5.2e7

def time_calculate_distance_boundary(self):
mu = 0.3
r = 7.5e14

calculate_distances.calculate_distance_boundary(
r, mu, self.geometry.r_inner[0], self.geometry.r_outer[0]
)

@parameterize(
{
"Parameters": [
{
"packet": {
"nu_line": 0.1,
"is_last_line": True
},
"enable_full_relativity": True,
},
{
"packet": {
"nu_line": 0.2,
"is_last_line": False
},
"enable_full_relativity": True,
}
]
}
)
def time_calculate_distance_line(self, parameters):
packet_params = parameters["packet"]
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

calculate_distances.calculate_distance_line(
self.static_packet,
comov_nu,
is_last_line,
nu_line,
time_explosion,
enable_full_relativity
)
Loading

0 comments on commit dbc3b09

Please sign in to comment.