-
-
Notifications
You must be signed in to change notification settings - Fork 422
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 for doppler factor functions #2379
Merged
andrewfullard
merged 14 commits into
tardis-sn:master
from
sonachitchyan:adding_tests_doppler
Aug 11, 2023
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
750685a
added tests for get_doppler_factor_partial_relativity and get_doppler…
sonachitchyan dc0be96
changed the full relativity and added tests
sonachitchyan 1d86340
revert to the correct version of doppler factor for the full relativi…
sonachitchyan 84ea29d
small fix in the tests
sonachitchyan ff081c3
added a new test file in transport
sonachitchyan 237f038
moved tests to transport for doppler_factor
sonachitchyan e04b998
removed duplicate test
sonachitchyan 922732e
running black
sonachitchyan 51ffe54
got rid of unnecessary todo
sonachitchyan 7514e9d
got rid of duplicate tests
sonachitchyan 6b8025f
moved 2 doppler factor associated tests to the test_doppler_factor
sonachitchyan c806371
commented out outdated tests
sonachitchyan 11c8a31
added docstrings
sonachitchyan e6014cf
got rid of old tests
sonachitchyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import pytest | ||
import numpy as np | ||
|
||
import tardis.transport.frame_transformations as frame_transformations | ||
import tardis.montecarlo.montecarlo_numba.r_packet as r_packet | ||
|
||
from numpy.testing import ( | ||
assert_almost_equal, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["mu", "r", "inv_t_exp", "expected"], | ||
[ | ||
(0.3, 7.5e14, 1 / 5.2e7, 0.9998556693818854), | ||
(-0.3, 0, 1 / 2.6e7, 1.0), | ||
(0, 1, 1 / 2.6e7, 1.0), | ||
], | ||
) | ||
def test_get_doppler_factor(mu, r, inv_t_exp, expected): | ||
# Set the params from test cases here | ||
time_explosion = 1 / inv_t_exp | ||
|
||
# Perform any other setups just before this, they can be additional calls | ||
# to other methods or introduction of some temporary variables | ||
|
||
obtained = frame_transformations.get_doppler_factor(r, mu, time_explosion) | ||
|
||
# Perform required assertions | ||
assert_almost_equal(obtained, expected) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["mu", "beta", "expected"], | ||
[ | ||
(0.3, 0.2, 0.94), | ||
(-0.3, 0, 1.0), | ||
(0, 0.8, 1.0), | ||
], | ||
) | ||
def test_get_doppler_factor_partial_relativity(mu, beta, expected): | ||
obtained = frame_transformations.get_doppler_factor_partial_relativity( | ||
mu, beta | ||
) | ||
assert_almost_equal(obtained, expected) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["mu", "beta", "expected"], | ||
[ | ||
(0.3, 0.2, 0.95938348), | ||
(-0.3, 0, 1.0), | ||
(0, 0.8, 1.6666667), | ||
], | ||
) | ||
def test_get_doppler_factor_full_relativity(mu, beta, expected): | ||
obtained = frame_transformations.get_doppler_factor_full_relativity( | ||
mu, beta | ||
) | ||
assert_almost_equal(obtained, expected) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["mu", "r", "inv_t_exp", "expected"], | ||
[ | ||
(0.3, 7.5e14, 1 / 5.2e7, 1 / 0.9998556693818854), | ||
(-0.3, 0, 1 / 2.6e7, 1.0), | ||
(0, 1, 1 / 2.6e7, 1.0), | ||
], | ||
) | ||
def test_get_inverse_doppler_factor(mu, r, inv_t_exp, expected): | ||
sonachitchyan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Set the params from test cases here | ||
time_explosion = 1 / inv_t_exp | ||
|
||
# Perform any other setups just before this, they can be additional calls | ||
# to other methods or introduction of some temporary variables | ||
|
||
obtained = frame_transformations.get_inverse_doppler_factor( | ||
r, mu, time_explosion | ||
) | ||
|
||
# Perform required assertions | ||
assert_almost_equal(obtained, expected) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["mu", "beta", "expected"], | ||
[ | ||
(0.3, 0.2, 1 / 0.94), | ||
(-0.3, 0, 1.0), | ||
(0, 0.8, 1.0), | ||
], | ||
) | ||
def test_get_inverse_doppler_factor_partial_relativity(mu, beta, expected): | ||
obtained = ( | ||
frame_transformations.get_inverse_doppler_factor_partial_relativity( | ||
mu, beta | ||
) | ||
) | ||
assert_almost_equal(obtained, expected) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["mu", "beta", "expected"], | ||
[ | ||
(0.3, 0.2, 1.0818579), | ||
(-0.3, 0, 1.0), | ||
(0, 0.8, 1.6666667), | ||
], | ||
) | ||
def test_get_inverse_doppler_factor_full_relativity(mu, beta, expected): | ||
obtained = frame_transformations.get_inverse_doppler_factor_full_relativity( | ||
mu, beta | ||
) | ||
assert_almost_equal(obtained, expected) | ||
|
||
|
||
@pytest.mark.parametrize(["mu", "r", "inv_t_exp"], [(-0.3, 5, 1e10)]) | ||
def test_unphysical_doppler_factor(mu, r, inv_t_exp): | ||
# Set the params from test cases here | ||
# TODO: add relativity tests | ||
time_explosion = 1 / inv_t_exp | ||
|
||
# Perform any other setups just before this, they can be additional calls | ||
# to other methods or introduction of some temporary variables | ||
with pytest.raises(r_packet.SuperluminalError): | ||
sonachitchyan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
obtained = frame_transformations.get_doppler_factor( | ||
r, mu, time_explosion | ||
) | ||
|
||
|
||
@pytest.mark.parametrize(["mu", "r", "inv_t_exp"], [(-0.3, 5, 1e10)]) | ||
def test_unphysical_inverse_doppler_factor(mu, r, inv_t_exp): | ||
# Set the params from test cases here | ||
# TODO: add relativity tests | ||
time_explosion = 1 / inv_t_exp | ||
|
||
# Perform any other setups just before this, they can be additional calls | ||
# to other methods or introduction of some temporary variables | ||
with pytest.raises(r_packet.SuperluminalError): | ||
obtained = r_packet.get_inverse_doppler_factor(r, mu, time_explosion) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are more doppler factor tests below. I would also move them to the new file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chvogl the tests below fail because of this line. Seems like the SuperluminousError is not defined anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. It looks like it doesn't exist anymore. I also just noticed that all tests in test_montecarlo.py are skipped because of
pytestmark = pytest.mark.skip(reason="Port from C to numba")
. This explains why the tests did not fail.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make an issue that we should check if there are any tests in test_montecarlo.py that we actually need but are currently skipped?