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

[TEP014] Update Model and Density classes to use HDFWriter + Unit Tests #747

Merged
merged 10 commits into from
Jun 23, 2017

Conversation

vg3095
Copy link
Contributor

@vg3095 vg3095 commented Jun 20, 2017

No description provided.

@vg3095
Copy link
Contributor Author

vg3095 commented Jun 20, 2017

@wkerzendorf Please review

Copy link
Contributor

@yeganer yeganer 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 overall but I'd suggest some changes to make implementing the tests for the other classes easier and to follow the Don't Repeat Yourself principle of python.

Another change I'd like to see which is not directly tied to this PR but could be implemented here, is changing the name of HDFWriter to HDFWriterMixin. This would then correctly reflect that HDFWriter is only a utility class and not the common Root for all our classes.

from density import HomologousDensity

logger = logging.getLogger(__name__)


class Radial1DModel(object):
class Radial1DModel(HDFWriter, object):
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove object since it is not needed here.



@pytest.fixture(scope="module")
def hdf_file_path(tmpdir_factory):
Copy link
Contributor

Choose a reason for hiding this comment

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

You should define a top level fixture in conftest.py that can be used by all test modules. That way you only have to write this code once and if it needs changes, you only have to change one instance of it.



@pytest.fixture(scope="module")
def actual_model():
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can have this as a top level fixture, too? See above.



@pytest.fixture(scope="module", autouse=True)
def to_hdf_buffer(hdf_file_path, actual_model):
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an interesting way to achieve that the model is saved, however I'd prefer if there was a fixture that either returns the filename or the buffer the data was saved to.
Someone not very familiar with the internal workings of pytest might not understand what's happening here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yeganer If I return hdf buffer path from this function , then it same as input argument hdf_file_path. I think , If I return hdf_file_path here , then it is inconsistent .


###
# Save and Load
###
Copy link
Contributor

Choose a reason for hiding this comment

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

See remarks for test_model.py. Most apply here aswell

@yeganer
Copy link
Contributor

yeganer commented Jun 20, 2017

@vg3095 I haven't had the time to look in depth at the latest changes. Can you please explain, why you had to revert the name changes? I'm confused...

@vg3095
Copy link
Contributor Author

vg3095 commented Jun 20, 2017

@yeganer , If I change HDFWriter to HDFWriterMixin, then I have to change it in all places in HDFWriter Unit Tests , and I think ,it will out of scope for this PR.

For now , I am importing HDFWriter in classes like this -->
from tardis.io.util import HDFWriter as HDFWriterMixin
in Radial1DModel and Homologous Density classes.

I will then, make a seperate PR for this afterwards.

Copy link
Contributor

@yeganer yeganer left a comment

Choose a reason for hiding this comment

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

This looks good and goes into the right direction, good job!

Nevertheless I have some minor suggestions

return model

@pytest.fixture(scope="session")
def homologous_density(hdf_config):
Copy link
Contributor

Choose a reason for hiding this comment

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

I would not say that homologous density is used anywhere else than the corresponding test

return str(path)

@pytest.fixture(scope="session")
def hdf_config():
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest a rename to config_verysimple

return config

@pytest.fixture(scope="session")
def model(hdf_config):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you try to create a simulation_verysimple fixture? If that works, then we can get a model by simulation_verysimple.model and therefore we don't need additional fixtures.
Do you think, that could work?

@yeganer
Copy link
Contributor

yeganer commented Jun 21, 2017

@vg3095 You are right, the name change of HDFWriter should not be part of this PR but I think changing the name during the import is not the right way to go about this.

I'd suggest you make a small PR containing the name change and then you rebase this PR and other on your name change PR. That way you can implement it correctly right from the start but you can keep the change separate.
If you are not sure what I'm talking about in terms of git, have a look at git rebase and git rebase -i.

@vg3095
Copy link
Contributor Author

vg3095 commented Jun 21, 2017

@yeganer Coverage is decreasing , due to usage of common Simulation fixture for all hdf tests, should I change it , or is it ok ?

@yeganer
Copy link
Contributor

yeganer commented Jun 21, 2017

@vg3095 Looks good, however please remove the two commits which introduce the name change and then revert it in the next commit. You can delete, modify or merge commits with git rebase -i


@pytest.fixture(scope="session")
def simulation_verysimple(config_verysimple, atomic_data_fname):
atomic_data = AtomData.from_hdf5(atomic_data_fname)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know there is a problem with the atomic data and preparing it multiple times. I think we could solve this by having a session fixture that does AtomData.from_hdf(...) and another function scope fixture that takes the first fixture and returns a copy.deepcopy. Could that work?

@vg3095
Copy link
Contributor Author

vg3095 commented Jun 21, 2017

@yeganer I created a separate session based atomic_dataset fixture , like you said , and in kurucz_atomic_data fixture , I used deepcopy of this session based fixture , but still the integration tests are failing. Look at the last commit.

@vg3095
Copy link
Contributor Author

vg3095 commented Jun 22, 2017

The issue is fixed now.

'(md5="21095dd25faa1683f4c90c911a00c3f8"')

sim = Simulation.from_config(config_verysimple, atom_data=atomic_data)
def simulation_verysimple(config_verysimple, atomic_dataset):
Copy link
Contributor

Choose a reason for hiding this comment

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

You are using the session scoped atomic dataset fixture here. I believe you want to use kurucz_atomic_data which is the one making use of the deepcopy, right?

Copy link
Contributor Author

@vg3095 vg3095 Jun 22, 2017

Choose a reason for hiding this comment

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

@yeganer kurucz_atomic_data fixture is a function scope fixture , that`s why It can`t be used for session based Simulation fixture (It throws ScopeMismatch Error) , that`s why , I used atomic_dataset here(session based fixture) and used deepcopy to create a new copy for atomic dataset inside the function itself..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yeganer And you are seeing the old commit

@wkerzendorf
Copy link
Member

@vg3095 can you rebase onto the current master

@wkerzendorf
Copy link
Member

@yeganer and @wkerzendorf signed off - will merge when tests pass 

@wkerzendorf wkerzendorf merged commit 262c1a3 into tardis-sn:master Jun 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants