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

Include detailed tests for forcefield metadata #435

Merged

Conversation

justinGilmer
Copy link
Contributor

PR Summary:

Previously, the tests in test_forcefield.py were assumed to test that
forcefield metadata like version, name, etc. were properly loaded
into the Forcefield object.

This is only partially true, as there are cases where the files either
go out of scope before that information is gathered, etc. This PR
includes additional tests to ensure that this information is not being
lost prematurely. Big thanks to: @mattwthompson, @ahy3nz for discovering
this issue, creating MWE's for some of these cases, and taking my
investigation further and most likely pinpointing the issue.

PR Checklist


  • Includes appropriate unit test(s)
  • Appropriate docstring(s) are added/updated
  • Code is (approximately) PEP8 compliant
  • Issue(s) raised/addressed?

Refer to issues/PRs: #433 #434

Note: This does not have @ahy3nz 's fix incorporated yet, just the test cases that fail and currently work.

Previously, the tests in test_forcefield.py were assumed to test that
forcefield metadata like `version`, `name`, etc. were properly loaded
into the `Forcefield` object.

This is only partially true, as there are cases where the files either
go out of scope before that information is gathered, etc. This PR
includes additional tests to ensure that this information is not being
lost prematurely. Big thanks to: @mattwthompson, @ahy3nz for discovering
this issue, creating MWE's for some of these cases, and taking my
investigation further and most likely pinpointing the issue.
@justinGilmer justinGilmer linked an issue Jun 29, 2021 that may be closed by this pull request
@justinGilmer justinGilmer requested review from ahy3nz, mattwthompson and a team June 29, 2021 17:14
@codecov
Copy link

codecov bot commented Jun 29, 2021

Codecov Report

Merging #435 (a283ab6) into master (3b91082) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #435      +/-   ##
==========================================
- Coverage   73.59%   73.58%   -0.02%     
==========================================
  Files          17       17              
  Lines        1803     1802       -1     
==========================================
- Hits         1327     1326       -1     
  Misses        476      476              

When a forcefield file is provided by using the internal name:
`foyer.Forcefield(name='oplsaa)`, the final file processing would happen
in a separate part of the logic and use variables that were only
accessed if the user used `forcefield_files` in the `Forcefield`
constructor method.

Now the same final processing occurs for all input types to load the
forcefields. All tests currently pass with this fix in place.
@mattwthompson
Copy link
Member

Looks like this reproduces the issue (test_load_metadata_from_internal_name, the one using Forcefield(name="") is failing).

I took Alex's suggested patch (#434 (comment)) and made a couple fixes so that tests would pass. I haven't thought much about unintended side effects yet.

Here is the commit; feel free to move it around, copy, etc. : 22855d4

@justinGilmer
Copy link
Contributor Author

Yeah we essentially had the same design process and handling of the strings. Once this passes and we have the approvals, we can merge. Thanks @mattwthompson and @ahy3nz for both of your contributions!

@mattwthompson
Copy link
Member

Does it matter that you're using preprocessed_files and I'm using all_files_to_load? Both seem to pass tests ... it's probably better to use the pre-processed ones in principle?

@mattwthompson
Copy link
Member

(Sorry for the misclick 😬)

@justinGilmer
Copy link
Contributor Author

Does it matter that you're using preprocessed_files and I'm using all_files_to_load? Both seem to pass tests ... it's probably better to use the pre-processed ones in principle?

That was my thought, we already strip out/handle things that might not behave the way we expect once we have pre-processed.

@justinGilmer
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@mattwthompson mattwthompson left a comment

Choose a reason for hiding this comment

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

LGTM iff tests pass.

There should be some added confidence if another piece of metadata can be added (#433) without re-engineering this machinery.

@ahy3nz
Copy link
Contributor

ahy3nz commented Jun 29, 2021

Does it matter that you're using preprocessed_files and I'm using all_files_to_load? Both seem to pass tests ... it's probably better to use the pre-processed ones in principle?

That was my thought, we already strip out/handle things that might not behave the way we expect once we have pre-processed.

While I agree the pre-processed XML files are safer to try reading, we might have to consider this block of code that is being deleted in this PR. Originally, IIRC @justinGilmer ran into some problems with /tmp blowing up when running a lot of atomtyping and creating a lot of preprocessed XML files in /tmp, so we needed to add this code chunk to remove old XML files. If this chunk of code is removed, this problem may come up again.

748bdd8

        try:
            super(Forcefield, self).__init__(*preprocessed_files)
        finally:
            for ff_file_name in preprocessed_files:
                os.remove(ff_file_name)

@justinGilmer
Copy link
Contributor Author

I did add a small section at the end of this init method to iterate through the open files and os.remove them. It runs into the problem where I cant really put a try catch finally around the entire part of that code to always ensure that the files are deleted, but it should handle most cases.

https://github.com/mosdef-hub/foyer/pull/435/files#diff-2e32e78335ccab485367397b205f395d5793e27101a8e63226d79081eb4f2356R536-R537

@ahy3nz
Copy link
Contributor

ahy3nz commented Jun 29, 2021

My mistake! Good catch

Copy link
Member

@daico007 daico007 left a comment

Choose a reason for hiding this comment

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

LGTM!

@daico007 daico007 merged commit fc44f80 into mosdef-hub:master Jun 29, 2021
@justinGilmer justinGilmer deleted the fix/include_tests_for_ffmetadata branch June 29, 2021 21:55
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.

Metadata parsing issues
4 participants