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

Tests Plasma Using Syrupy #2413

Merged
merged 36 commits into from
Nov 6, 2023
Merged

Conversation

atharva-2001
Copy link
Member

@atharva-2001 atharva-2001 commented Sep 19, 2023

📝 Description

Type: 🪲 bugfix | 🚀 feature | ☣️ breaking change | 🚦 testing | 📝 documentation | 🎢 infrastructure

This PR has my extensions inside fixtures in the main conftest.py. It uses those fixtures to generate the snapshot_np and snapshot_pd fixtures in the plasma conftest.py file.
Until the Syrupy devs complete their PR syrupy-project/syrupy#816 to allow sending kwargs to custom extensions, we are stuck with fixed functions like assert_allclose for NumPy and Pandas. However I have sent them an example and asked them for a workaround. The snapshots are saved in a separate plasma directory.

TODO-

  • Remove parameters from test func definitions
  • Change lockfiles
  • Push data for all plasma tests
  • Make all checks pass (docstr fails)

📌 Resources

Examples, notebooks, and links to useful references.

Plasma data pull request- tardis-sn/tardis-regressions#1

🚦 Testing

How did you test these changes?

  • Testing pipeline
  • Other method (describe)
  • My changes can't be tested (explain why)

☑️ Checklist

  • I requested two reviewers for this pull request
  • I updated the documentation according to my changes
  • I built the documentation by applying the build_docs label

Note: If you are not allowed to perform any of these actions, ping (@) a contributor.

@atharva-2001
Copy link
Member Author

All the data which was generated(for test plasma complete at the moment)-
https://github.com/atharva-2001/tardis-refdata/tree/syrupy_plasma/syrupy_data

tardis_env3.yml Outdated Show resolved Hide resolved
tardis/conftest.py Outdated Show resolved Hide resolved
@jvshields
Copy link
Contributor

Needs an updated lockfile so that the tests don't break, and should remove the redundant assert statements in many tests. Other than that, it looks good to me!

@andrewfullard andrewfullard self-requested a review September 20, 2023 14:59
@atharva-2001 atharva-2001 force-pushed the syrupy_plasma branch 2 times, most recently from ce094ad to af3ae92 Compare September 22, 2023 12:51
@codecov
Copy link

codecov bot commented Sep 29, 2023

Codecov Report

Merging #2413 (8a156df) into master (f89e125) will decrease coverage by 0.13%.
Report is 13 commits behind head on master.
The diff coverage is 77.27%.

❗ Current head 8a156df differs from pull request most recent head 36bf454. Consider uploading reports for the commit 36bf454 to get more accurate results

@@            Coverage Diff             @@
##           master    #2413      +/-   ##
==========================================
- Coverage   66.94%   66.82%   -0.13%     
==========================================
  Files         153      154       +1     
  Lines       13621    13651      +30     
==========================================
+ Hits         9119     9122       +3     
- Misses       4502     4529      +27     
Files Coverage Δ
tardis/plasma/tests/test_hdf_plasma.py 91.42% <100.00%> (-3.31%) ⬇️
tardis/plasma/tests/test_nlte_excitation.py 100.00% <100.00%> (ø)
tardis/plasma/tests/test_nlte_solver.py 100.00% <100.00%> (ø)
tardis/plasma/tests/test_plasma_contiuum.py 100.00% <100.00%> (ø)
tardis/plasma/tests/test_plasma_vboundary.py 100.00% <100.00%> (ø)
...s/plasma/tests/test_tardis_model_density_config.py 100.00% <100.00%> (ø)
...dis/montecarlo/montecarlo_numba/formal_integral.py 54.43% <66.66%> (+0.11%) ⬆️
tardis/io/atom_data/base.py 91.62% <50.00%> (-0.84%) ⬇️
tardis/plasma/properties/atomic.py 85.60% <33.33%> (-0.62%) ⬇️
tardis/plasma/tests/test_complete_plasmas.py 96.59% <82.35%> (-0.47%) ⬇️
... and 2 more

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

)
# TODO: allow rtol=1e-6
assert snapshot_np == np.array(actual_rate_matrix)
# assert_allclose(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does assert_allclose not work with the snapshot?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have to create another snapshot fixture to get that to work. Does assert_almostequal not fulfill the needs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Syrupy devs are working on another PR which would enable the functionality to do this-
syrupy-project/syrupy#816

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good, but this functionality is critical for our tests. I'm concerned about the timeline for the syrupy updates in this case.

Copy link
Member Author

@atharva-2001 atharva-2001 Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked them, would let you know in sometime.

@tardis-bot
Copy link
Contributor

tardis-bot commented Oct 2, 2023

*beep* *bop*

Hi, human.

The docs workflow has succeeded ✔️

Click here to see your results.

.github/workflows/tests.yml Outdated Show resolved Hide resolved
- name: Clone tardis-sn/tardis-regressions
uses: actions/checkout@v4
with:
repository: atharva-2001/tardis-regressions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will this be changed to the "official" repository?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking to change this once everything else is done.

tardis/plasma/tests/test_hdf_plasma.py Outdated Show resolved Hide resolved
tardis/plasma/tests/test_hdf_plasma.py Outdated Show resolved Hide resolved
tardis/plasma/tests/test_nlte_excitation.py Show resolved Hide resolved
[0.0, 1.0, 0.0, 1.0, 2.0, -1.0],
]
assert_almost_equal(actual_jacobian_matrix, desired_jacobian_matrix)
# TODO: allow for assert_almost_equal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if I understand correctly, assert_allclose is good enough

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

andrewfullard
andrewfullard previously approved these changes Oct 3, 2023
Copy link
Contributor

@andrewfullard andrewfullard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Time for the last bit of cleanup.

andrewfullard
andrewfullard previously approved these changes Oct 3, 2023
@andrewfullard
Copy link
Contributor

Why are tests failing now?

@andrewfullard andrewfullard self-requested a review October 16, 2023 16:14
@andrewfullard
Copy link
Contributor

Why are tests failing now?

Ah I see, because this is using the slightly outdated env without syrupy in

Copy link
Contributor

@andrewfullard andrewfullard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work atharva!

@atharva-2001
Copy link
Member Author

atharva-2001 commented Oct 18, 2023

great work atharva!

Thank you so much! I might need to rebase this once #2441 is merged

@atharva-2001
Copy link
Member Author

atharva-2001 commented Oct 23, 2023

Looks like since no merge conflicts are visible- this can be merged.
We can also merge the regressions PR if we want to see tests pass.
tardis-sn/tardis-regressions#1

@andrewfullard
Copy link
Contributor

Tests complaining about no syrupy package in the env

@atharva-2001
Copy link
Member Author

atharva-2001 commented Nov 1, 2023

Tests complaining about no syrupy package in the env

It's because the latest cache is not used. The cache is just ~400 MBs, I deleted them and the tests are now passing.

@andrewfullard andrewfullard merged commit 87e8f3a into tardis-sn:master Nov 6, 2023
7 of 8 checks passed
atharva-2001 added a commit to atharva-2001/tardis that referenced this pull request Nov 28, 2023
* Allow Simulation Tests to Run Independently  (tardis-sn#2407)

* Modify test_packet_source.py so that sim and tardis/tests can run

* remove BasePacketSource

* format

* Add docstrings

* Pre-release 2023.09.17 (tardis-sn#2411)

Automated changes for pre-release 2023.09.17

* upgrading env in 2022 (tardis-sn#2410)

* fix several bugs related to upgrade

* fix the get function in pandas

* fixed several incompatibilities for new libraries

* fixed up the changes in pandas testing and other reindexing issues

* fix other bugs with new environment

* blackify tardis

* updated the conda-lock file

* add lock files

* update cache number

* fix simulation tests

* remove units for testing

* blackify

* Update tardis/visualization/tools/tests/test_sdec_plot.py

good catch

Co-authored-by: Atharva Arya <[email protected]>

* add assert

* reset caches

---------

Co-authored-by: Atharva Arya <[email protected]>

* In gamma ray code : Changed times to np.geomspace (tardis-sn#2415)

* Changed times to np.geomspace

* Added myself to mailmap

* rename RadialModel1D to SimulationState (tardis-sn#2417)

* rename RadialModel1D to SimulationState

* black files

* rename simulation_state2 (tardis-sn#2421)

* fixup of many files to make them pass the tests

* change model for typo

* Ignore tests in docstr coverage (tardis-sn#2424)

ignore tests in docstr coverage

* Disabled formal integral for continuum interaction (tardis-sn#2426)

Disabled formal integral

Co-authored-by: Alexander Holas <alexander.holas@h-its>

* add linelist exposure to atom data and reader, built on current (tardis-sn#2428)

* add linelist exposure to atom data and reader, built on current

* add josh to mailmap

* Modified how setup input energy takes isotope name. Earlier it was ga… (tardis-sn#2425)

Modified how setup input energy takes isotope name. Earlier it was gamma_ray_lines.Isotope

* Added a function to calculate shell masses (tardis-sn#2434)

* Added a function to calculate shell masses

* Added a function to calculate shell masses

* changed shell masses with the new function

* Fix duplicate entries in continuum line list (tardis-sn#2443)

* Workaround list access

* Formatting

* Added error if duplicate

* Remove duplicates

* Fix typo, add comment

* Remove bandaid fix

* Cleanup

* More cleanup

* Fix numba parallel issues (tardis-sn#2447)

* Enabled parallel

* Fix the mistake

* Update docs

* Change glob patterns in `setup.cfg`  (tardis-sn#2441)

* Fix package_data in setup.cfg, mainly io and viz

* more folders

* Test pip installation

* Remove test step

* Fix more folders

* restructure of geometry (tardis-sn#2422)

* restructure of geometry

* add radial1d boundary logic

* black format

* several fixes

* fix epsilon

* add testing of boundaries

* change the r_inner_active

* first integration with `from_config` working

* hunting down density indexing bug

* all model tests (without csvy) pass

* more fixes

* fix of model to simulation_state

* fix inner boundary packet error

* fix some leftovers

* final fix for csvy

* blackify

* restructure to readers and remove some leftover code

* further cleanup

* first start of the restructure

* add comment about removing quantitiness

* add velocity check

* add new abundance functions

* remove default units

* Add FAQ section to documentation (tardis-sn#2450)

* Add faq

* Added Overview

* Fix typo

* Remove lock file creation from pre release workflow (tardis-sn#2432)

* Install latest version of mamba

* Unpin conda lock installatiion

* Split lockfilee creation to separate workflow

* change docs installation- put a warning for conda forge installation and comment out install from package

* fix

* delete create lockfiles

* download llock file

* Pre-release 2023.10.20 (tardis-sn#2452)

Automated changes for pre-release 2023.10.20

* Add verbose assert to NLTE rate equation (tardis-sn#2457)

* add verbose assert

* formatting

* Fix bug in relativistic packet source (tardis-sn#2453)

* Fix bug in relativistic packet source

* Add initial test for BlackBodySimpleSourceRelativistic

* Remove incorrect docstring

* Update tardis/montecarlo/tests/test_packet_source.py

Co-authored-by: Wolfgang Kerzendorf <[email protected]>

* Update tardis/montecarlo/tests/test_packet_source.py

Co-authored-by: Wolfgang Kerzendorf <[email protected]>

* Rename all occurences of blackbodysimplesourcerelativistic

* Do not hardcore blackbody_simplesource_relativistic.beta

---------

Co-authored-by: Wolfgang Kerzendorf <[email protected]>

* Enable nlte ionization as plasma component (tardis-sn#2458)

* Rename nlte ion and electron

* Enable NLTE

* Fix typo

* Add docs

* Fix transitionprob dtype

* dtype conversion

* dtype for sparse matrix

* Typing in numba

* Fix test variable name

* Add missing electron density case

* Fix typo

* Update docstr-cov.yml to fix failing action (tardis-sn#2462)

* Update docstr-cov.yml to fix failing action

* Explicitly install setuptools

* NLTE Ionization solver polish (tardis-sn#2461)

* assertion for first guess

* Add checks to decay

* Fix greater equal

* Fix deprecated series index

* Pre-release 2023.11.05 (tardis-sn#2466)

Automated changes for pre-release 2023.11.05

* Tests Plasma Using Syrupy (tardis-sn#2413)

* Add syrupy classes to conftest

* Add syrupy to env file

* Another folder for syrupy data

* Save as npy instead of txt

* Use syrupy fixtures

* Different assertion functions for pandas dataframes and series

* Zeta data fix

* Blackify

* Blackify conftest

* test_hdf_plasmas using syrupy

* Install syrupy with conda

* Remove additional line adding syrupy as a plugin

* Set update snapshots config option when generate reference is selected

* Remove old refdata code from test plasmas complete

* Create plasma conftest file

* Text based snapshot fixture with custom location

* Snapshot path

* tardis regressions my fork

* Refactor test_hdf_plasmas.py

* Format using black

* test nlte excitation using syrupy

* nlte solver

* plasma continuum

* test tardis model density config

* Lock files

* Increase cache no

* format using black

* cleanup- sort dependencies, delete comments

* Documentation to run these tests

* remove commented out fixtures which are not used anywhere

* docs code render fix

* tests final cleanup

* renaming files, yet to deal with ambr snapshot extension and curly brackets

* renaming snapshots

* Add comments

* Add astropy import guard (tardis-sn#2470)

* Add astropy import guard

* mailmap

* Reading in decay radiation data in atom data (tardis-sn#2471)

* Reading in decay radiation data in atom data

* Added docstring

* Fixes the checksum

* Pre-release 2023.11.26 (tardis-sn#2477)

Automated changes for pre-release 2023.11.26

* Update plasma configuration documentation (tardis-sn#2459)

* update plasma docs

* Update mailmap

* Fix typo

* Add ruff rules and docs (tardis-sn#2478)

* Add ruff rules and docs

* Update pyproject.toml

Co-authored-by: Wolfgang Kerzendorf <[email protected]>

* rebuild docs

---------

Co-authored-by: Wolfgang Kerzendorf <[email protected]>

* Decay energy chain (tardis-sn#2448)

* Added a function to calculate shell masses

* Added a function to calculate shell masses

* changed shell masses with the new function

* Changed mass fraction to masses in to_inventories()

* Co-authored-by: Wolfgang Kerzendorf <[email protected]>

* Added a function to calculate total decays

* Added a function to calculate energies from gamma rays and positrons.

* added a function to calculate average energies of gamma rays and positrons

* Added a fucntion to calculate each decay chain energies

* Added dictionaries to handle multiple isotopes

* Changed value to values

* added tests for gamma_ray_transport

* Added tests for calculating activity

* Added test for activity

* Added tests for two isotope

* Changed Ni_isotope_mass

* Added pytest paramterize

* Added test for calculating shell masses

* Ran test for checking activity of parent nuclide with analytical solution.

* The function test_activity matches with the radioactivedecay output upto 14 decimal places. The Avogadro's number used in radioactivedecay is not from astropy.

* Added tests for checking if iso_dict is returning the right key.

* Added test for inventories dictionary.

* Added a test to check if the calculate_average_energy function passes the right list ahead.

* Added new function for testing energy budget from each decay chain.

* Added a new function for energy per mass

* Reading in decay radiation data in atom data

* Add

* Added tests for gamma ray transport.

* Added tests for all functions for gamma_ray_transport. Added docstrings.

* Changing decay energy chain

* Added a function to get taus

* Added tests for multiple isotopes

* Fixes the test calculate shell masses with hand calculated values

* Use Mamba instead of conda

* Run asv for last 5 commits

* Add pull request trigger temporarily

* Reset

---------

Co-authored-by: tardis-bot <[email protected]>
Co-authored-by: Wolfgang Kerzendorf <[email protected]>
Co-authored-by: Anirban <[email protected]>
Co-authored-by: Alexander Holas <[email protected]>
Co-authored-by: Alexander Holas <alexander.holas@h-its>
Co-authored-by: Joshua Shields <[email protected]>
Co-authored-by: Anirban <[email protected]>
Co-authored-by: Christian Vogl <[email protected]>
Co-authored-by: Andrew <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants