-
-
Notifications
You must be signed in to change notification settings - Fork 404
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
Replace Comparison values in Plasma Unit Tests with reference HDF file #774
Conversation
I have currently replaced values for |
@wkerzendorf Can you check my approach ? |
.travis.yml
Outdated
- MINICONDA_URL='http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh' | ||
|
||
matrix: | ||
include: | ||
- python: 2.7 | ||
env: | ||
- COMPILER=gcc | ||
- SETUP_CMD='test --args="--atomic-dataset=$HOME/kurucz_cd23_chianti_H_He.h5"' | ||
- SETUP_CMD='test --args="--atomic-dataset=$HOME/kurucz_cd23_chianti_H_He.h5 --plasma-reference=$HOME/plasma_reference/"' |
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.
@wkerzendorf Here I want to pass path for plasma-reference
files, but travis doesn't recognise this option.
I have added this option in conftest.py
and this option works fine in my laptop.
So, what should I do here?
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.
@yeganer has some comments on this - I let him discuss this with you.
.travis.yml
Outdated
@@ -21,27 +21,29 @@ env: | |||
- SETUP_CMD='test' | |||
- TEST_MODE='normal' | |||
- ATOM_DATA_URL='https://github.com/tardis-sn/tardis-atomdata/raw/master/kurucz_cd23_chianti_H_He.h5.zip' | |||
- PLASMA_NLTE_REFERENCE_URL='https://github.com/vg3095/tardis-refdata/raw/plasma-ref2/plasma_reference/plasma_nlte_reference.h5' |
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.
@vg3095 can you check out how this refdata is solved in carsus and use the same methods
@vg3095 as @wkerzendorf pointed out I have some ideas how we could solve the issue with the reference data for tardis. The idea borrows the approach from carsus in some way. On the tardis side this has the benefit that we can treat all file names as relative to this 'root'. What do you think? Would this be a good idea? |
@yeganer I think its a great idea. |
@vg3095 With this approach, we should also test for the version of the |
@wkerzendorf You can review this PR now. |
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.
@vg3095 I did a quick review of the PR and found some only small issues. However, it was very difficult for me to review because this PR mixes two changes: The transition towards the tardis-refdata
repository and your changes to the plasma tests. Could you please split these into two Pull Requests? This would make reviewing a lot easier.
Apart from that, I think the changes required to use tardis-refdata
seem to be almost complete. Good and very quick work!
|
||
cls.config_path = os.path.join( | ||
'tardis', 'plasma', 'tests', 'data', 'plasma_test_config_nlte.yml') | ||
cls.config = Configuration.from_yaml(cls.config_path) | ||
cls.config['atom_data'] = os.path.abspath(os.path.expanduser(os.path.expandvars( | ||
pytest.config.getvalue('atomic-dataset')))) | ||
cls.config['atom_data'] = os.path.join( |
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.
You should use the one of the atomic_dataset
fixtures here.
tardis/tests/test_atomic.py
Outdated
@pytest.mark.skipif(not pytest.config.getvalue("atomic-dataset"), | ||
reason='--atomic_database was not specified') | ||
@pytest.mark.skipif(not pytest.config.getvalue("tardis-refdata"), | ||
reason='--tardis-refdata was not specified') | ||
def test_atomic_reprepare(): |
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.
Again, we should use a fixture here.
tardis/tests/test_tardis_full.py
Outdated
@@ -25,7 +25,7 @@ class TestSimpleRun(): | |||
@pytest.fixture(scope="class", autouse=True) | |||
def setup(self): | |||
self.atom_data_filename = os.path.expanduser(os.path.expandvars( | |||
pytest.config.getvalue('atomic-dataset'))) | |||
os.path.join(pytest.config.getvalue('tardis-refdata'), 'atom_data', 'kurucz_cd23_chianti_H_He.h5'))) |
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.
As above, this should be a fixture.
from tardis.simulation import Simulation | ||
|
||
|
||
class BasePlasmaTest: |
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.
This is missing the (object)
.
d1ce48c
to
0d76524
Compare
@wkerzendorf Not completely. This misses 2 commits, which I added afterwards in PR #775. I have left it deliberately for now, so that |
@wkerzendorf You can review this PR. I have rebased it. |
|
||
class TestNLTEPlasma(BasePlasmaTest): | ||
|
||
@classmethod |
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.
why is this a classmethod?
@classmethod | ||
@pytest.fixture(scope="class", autouse=True) | ||
def setup(cls, atomic_data_fname, tardis_ref_path): | ||
cls.reference_file_path = os.path.join( |
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.
same code as above - why is this not in the baseclass
#GENERAL PROPERTIES | ||
def test_beta_rad(self): | ||
pdt.assert_almost_equal(self.plasma.beta_rad, | ||
self.read_hdf_attr('beta_rad').values) |
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.
this could be parameterizable - that might make it easier.
@@ -70,6 +70,8 @@ before_install: | |||
- if [[ $TEST_MODE == 'spectrum' ]]; then git lfs install --skip-smudge; fi | |||
- if [[ $TEST_MODE == 'spectrum' ]]; then git clone $TARDIS_REF_DATA_URL $HOME/tardis-refdata; fi | |||
- if [[ $TEST_MODE == 'spectrum' ]]; then cd $HOME/tardis-refdata; fi | |||
- if [[ $TEST_MODE == 'spectrum' ]]; then git fetch origin pull/2/head:plasma-ref2; fi |
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.
This is only temporary, right?
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.
Yes, this is temporary.
#GENERAL PROPERTIES | ||
def test_beta_rad(self): | ||
pdt.assert_almost_equal(self.plasma.beta_rad, | ||
self.read_hdf_attr('beta_rad').values) |
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.
Why are we using x.values
here instead of the original object? Is the reference not a DataFrame/Series or is there another reason for this?
cls.config = Configuration.from_yaml(cls.config_path) | ||
cls.config['atom_data'] = atomic_data_fname | ||
cls.sim = Simulation.from_config(cls.config) | ||
cls.sim.run() |
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 think it's not required to run the Simulation. Everything that depends on the run is either tested in the integration tests or in test_tardis_full
.
239f749
to
d19f0da
Compare
@wkerzendorf I have updated this PR. |
I don't have specific comments on the PR however, the coverage dropped by 6%. This is not acceptable, even more so for a PR that targets tests and has full coverage of the plasma module as the ultimate goal. Please have a look at the coverage report and fix this. |
@yeganer @wkerzendorf I have made a PR #779 regarding this, can you check that? |
@vg3095 I agree with that. We had a discussion about that topic sometime last year. If I remember correctly we decided to not test during the run with reference files because we were interested in the coverage of our unit-tests, not the integration tests. With the addition of the integration tests and our plan to actively use |
@vg3095 please rebase this and then see how high the coverage is for plasma. |
@wkerzendorf I have rebased this.
|
test_complete_plasmas.py contains combined tests for all these files
1. Parametrize Plasma tests for different properties 2. Use a common setup method , which is implemented in BasePlasmaTest class
Added 2 more Plasma setup for testing. One having radiative_rates_type - detailed, classical_nebular- True. Second having radiative_rates_type as blackbody.
from tardis.simulation import Simulation | ||
|
||
|
||
setupI = { |
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 was more thinking about having a list of all options like this:
ionization = [
{ 'ionization': 'nebular'},
{ 'ionization': 'lte'},
]
excitation = [
{ 'excitation' : 'lte'},
{ 'excitation': 'dilute-lte'}
]
@pytest.fixture(params=ionization+excitation)
def config(...):
for k, v in ...params.items():
config.plasma[k] = v
# rest of the code
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.
That way we test each option individually which makes it easier to see which option causes a failure.
I'm not sure right now but I think we might do this seperately for nlte and lte configurations but that should not be your concern. Your main goal should be to design this system in such a way that we can easily add the rest.
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.
@yeganer Oh, then I cannot think of any way of setting reference_path
. And, apart from that , saving reference file for all the generated permutations ( even assuming we have 4 options to set(i.e. ionization
, excitation
, etc), and having 2 different values that can be set for each option - 2^4 = 16 reference files(the real no. will be much greater than that, considering all options).
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.
@yeganer Did you mean , that like for example , ionization
: nlte
, that the values will be same, irrespective of other plasma config options?
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.
We don't need to test all permutations. That would be too much reference data. But we can test all options 'alone'. I think this would give us ~20 different setups which I think is doable.
For the reference path, one method could be to hash the string representation of the config. The result should be unique and one could use this as the identification of the reference data set. |
@vg3095 that looks great - can you tell us what the test percentage is for plasma - and what and if things are missing. |
@@ -282,6 +282,8 @@ def get_properties(self): | |||
data['atom_data_uuid'] = self.atomic_data.uuid1 | |||
if 'atomic_data' in data: | |||
data.pop('atomic_data') | |||
if 'nlte_data' in data: |
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 add a warning here that nlte_data
can not be saved.
@vg3095 I wrote some comments on gitter. |
This PR contains following changes -
Some new tests for Plasma
General Properties
- Dilution factor('w')
Atomic Properties
- nu
- wavelength_cm
- f_lu
- metastability
Radiative Properties
- transition_probabilites
Scalar Properties
- helium_treatment
- link_t_rad_t_electron
- time_explosion
NTLE