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

Fixture fixes #2977

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
113 changes: 113 additions & 0 deletions .github/workflows/compare-regdata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# For more information about TARDIS pipelines, please refer to:
#
# https://tardis-sn.github.io/tardis/development/continuous_integration.html

name: compare-regdata

on:
push:
branches:
- master
pull_request:
branches:
- master
types:
- opened
- reopened
- synchronize

env:
CACHE_NUMBER: 0 # increase to reset cache manually
PYTEST_FLAGS: --tardis-regression-data=${{ github.workspace }}/tardis-regression-data --cov=tardis --cov-report=xml --cov-report=html --cov-append
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

defaults:
run:
shell: bash -l {0}

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
test-cache:
uses: ./.github/workflows/lfs-cache.yml
with:
atom-data-sparse: false
regression-data-repo: tardis-sn/tardis-regression-data
allow_lfs_pull: ${{ github.ref == 'refs/heads/master' || contains(github.event.pull_request.labels.*.name, 'git-lfs-pull') }}

tests:
name: ${{ matrix.continuum }} continuum ${{ matrix.os }} ${{ inputs.pip_git && 'pip tests enabled' || '' }}
if: github.repository_owner == 'tardis-sn'
needs: [test-cache]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
label: [osx-arm64, linux-64]
continuum: ['not', '']
include:
- label: osx-arm64
os: macos-latest
prefix: /Users/runner/miniconda3/envs/tardis

- label: linux-64
os: ubuntu-latest
prefix: /usr/share/miniconda3/envs/tardis
steps:
- uses: actions/checkout@v4

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

- name: Setup environment
uses: ./.github/actions/setup_env
with:
os-label: ${{ matrix.label }}

- name: Install package editable
if: ${{ !inputs.pip_git }}
run: |
pip install -e . --user

- name: Install package git
if: ${{ inputs.pip_git }}
run: |
pip install git+https://github.com/tardis-sn/tardis.git@master

- name: Install qgridnext
if: ${{ !inputs.pip_git }}
run: |
pip install qgridnext


- name: Regression Data Generation tests
run: pytest tardis ${{ env.PYTEST_FLAGS }} --generate-reference -m "${{ matrix.continuum }} continuum"

- name: Commit regression data
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add tardis
git commit -m "Update regression data for commit ${GITHUB_SHA}"
working-directory: ${{ github.workspace }}/tardis-regression-data

- name: Update compare.py from fork
run: |
curl -s https://raw.githubusercontent.com/atharva-2001/tardis-regression-data/refs/heads/update_notebook/compare.py > compare.py
working-directory: ${{ github.workspace }}/tardis-regression-data

- name: Run comparison notebook
run: |
jupyter nbconvert --execute compare_regression_data.ipynb \
--to html \
--output=compare_regression_data_${{ github.sha }}_${{ matrix.continuum }}_${{ matrix.os }}.html \
working-directory: ${{ github.workspace }}/tardis-regression-data

- name: Upload comparison notebook
uses: actions/upload-artifact@v4
with:
name: compare_regression_data_${{ github.sha }}_${{ matrix.continuum }}_${{ matrix.os }}.html
include-hidden-files: true
path: ${{ github.workspace }}/tardis-regression-data/compare_regression_data_${{ github.sha }}_${{ matrix.continuum }}_${{ matrix.os }}.html
18 changes: 7 additions & 11 deletions tardis/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,6 @@ def tardis_regression_path(request):
)


@pytest.fixture(scope="session")
def tardis_snapshot_path(request):
tardis_snapshot_path = request.config.getoption("--tardis-snapshot-data")
if tardis_snapshot_path is None:
pytest.skip("--tardis-snapshot-data was not specified")
else:
return Path(
os.path.expandvars(os.path.expanduser(tardis_snapshot_path))
)


@pytest.fixture(scope="function")
def tardis_config_verysimple():
return yaml_load_file(
Expand Down Expand Up @@ -233,6 +222,13 @@ def simulation_verysimple(config_verysimple, atomic_dataset):
sim.run_final()
return sim

@pytest.fixture(scope="session")
def simulation_verysimple_default(config_verysimple, atomic_dataset):
atomic_data = deepcopy(atomic_dataset)
sim = Simulation.from_config(config_verysimple, atom_data=atomic_data)
sim.run_final()
return sim


@pytest.fixture(scope="session")
def simulation_verysimple_vpacket_tracking(config_verysimple, atomic_dataset):
Expand Down
44 changes: 17 additions & 27 deletions tardis/spectrum/tests/test_spectrum_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,23 @@ class TestSpectrumSolver:
regression_data: RegressionData = None

@pytest.fixture(scope="class")
def simulation(
def simulation_regression_data(
self,
request,
atomic_data_fname,
generate_reference,
example_configuration_dir: Path,
simulation_verysimple_default,
request: pytest.FixtureRequest,
):
config = Configuration.from_yaml(
str(example_configuration_dir / "tardis_configv1_verysimple.yml")
)
config["atom_data"] = atomic_data_fname

simulation = Simulation.from_config(config)
simulation.run_final()

request.cls.regression_data = RegressionData(request)
data = request.cls.regression_data.sync_hdf_store(simulation)
data = request.cls.regression_data.sync_hdf_store(simulation_verysimple_default)

yield simulation
yield simulation_verysimple_default
data.close()

def get_expected_data(self, key: str):
return pd.read_hdf(self.regression_data.fpath, key)

def test_initialization(self, simulation):
transport_state = simulation.transport.transport_state
spectrum_frequency_grid = simulation.transport.spectrum_frequency_grid
def test_initialization(self, simulation_regression_data):
transport_state = simulation_regression_data.transport.transport_state
spectrum_frequency_grid = simulation_regression_data.transport.spectrum_frequency_grid

solver = SpectrumSolver(transport_state, spectrum_frequency_grid, None)
assert solver.transport_state == transport_state
Expand All @@ -57,9 +47,9 @@ def test_initialization(self, simulation):
assert solver.integrator_settings is None
assert solver._spectrum_integrated is None

def test_spectrum_real_packets(self, simulation):
transport_state = simulation.transport.transport_state
spectrum_frequency_grid = simulation.transport.spectrum_frequency_grid
def test_spectrum_real_packets(self, simulation_regression_data):
transport_state = simulation_regression_data.transport.transport_state
spectrum_frequency_grid = simulation_regression_data.transport.spectrum_frequency_grid

solver = SpectrumSolver(transport_state, spectrum_frequency_grid, None)
result = solver.spectrum_real_packets.luminosity
Expand All @@ -73,9 +63,9 @@ def test_spectrum_real_packets(self, simulation):
luminosity,
)

def test_spectrum_real_packets_reabsorbed(self, simulation):
transport_state = simulation.transport.transport_state
spectrum_frequency_grid = simulation.transport.spectrum_frequency_grid
def test_spectrum_real_packets_reabsorbed(self, simulation_regression_data):
transport_state = simulation_regression_data.transport.transport_state
spectrum_frequency_grid = simulation_regression_data.transport.spectrum_frequency_grid

solver = SpectrumSolver(transport_state, spectrum_frequency_grid, None)
result = solver.spectrum_real_packets_reabsorbed.luminosity
Expand All @@ -89,9 +79,9 @@ def test_spectrum_real_packets_reabsorbed(self, simulation):
luminosity,
)

def test_solve(self, simulation):
transport_state = simulation.transport.transport_state
spectrum_frequency_grid = simulation.transport.spectrum_frequency_grid
def test_solve(self, simulation_regression_data):
transport_state = simulation_regression_data.transport.transport_state
spectrum_frequency_grid = simulation_regression_data.transport.spectrum_frequency_grid

solver = SpectrumSolver(transport_state, spectrum_frequency_grid, None)
result_real, result_virtual, result_integrated = solver.solve(
Expand Down
32 changes: 11 additions & 21 deletions tardis/tests/test_tardis_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,58 +38,48 @@ class TestTransportSimple:
regression_data: RegressionData = None

@pytest.fixture(scope="class")
def simulation(
def simulation_regression_data(
self,
request,
atomic_data_fname,
generate_reference,
example_configuration_dir: Path,
simulation_verysimple_default,
):
config = Configuration.from_yaml(
str(example_configuration_dir / "tardis_configv1_verysimple.yml")
)
config["atom_data"] = atomic_data_fname

simulation = Simulation.from_config(config)
simulation.run_convergence()
simulation.run_final()

request.cls.regression_data = RegressionData(request)
data = request.cls.regression_data.sync_hdf_store(simulation)

yield simulation
data = request.cls.regression_data.sync_hdf_store(simulation_verysimple_default)

yield simulation_verysimple_default
data.close()

def get_expected_data(self, key: str):
return pd.read_hdf(self.regression_data.fpath, key)

def test_j_blue_estimators(self, simulation):
def test_j_blue_estimators(self, simulation_regression_data):
key = "simulation/transport/transport_state/j_blue_estimator"
expected = self.get_expected_data(key)

npt.assert_allclose(
simulation.transport.transport_state.radfield_mc_estimators.j_blue_estimator,
simulation_regression_data.transport.transport_state.radfield_mc_estimators.j_blue_estimator,
expected.values,
)

def test_spectrum(self, simulation):
def test_spectrum(self, simulation_regression_data):
key = "simulation/spectrum_solver/spectrum_real_packets/luminosity"
expected = self.get_expected_data(key)

luminosity = u.Quantity(expected, "erg /s")

assert_quantity_allclose(
simulation.spectrum_solver.spectrum_real_packets.luminosity,
simulation_regression_data.spectrum_solver.spectrum_real_packets.luminosity,
luminosity,
)

def test_virtual_spectrum(self, simulation):
def test_virtual_spectrum(self, simulation_regression_data):
key = "simulation/spectrum_solver/spectrum_virtual_packets/luminosity"
expected = self.get_expected_data(key)

luminosity = u.Quantity(expected, "erg /s")

assert_quantity_allclose(
simulation.spectrum_solver.spectrum_virtual_packets.luminosity,
simulation_regression_data.spectrum_solver.spectrum_virtual_packets.luminosity,
luminosity,
)
Loading