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

Fix simtk JSON storage in SimStore #961

Merged
merged 7 commits into from Jan 19, 2021

Conversation

dwhswenson
Copy link
Member

Switch to using is_storage_iterable everywhere.

This fixes a problem that simtk.unit.Quantity objects couldn't be directly tagged (or, probably, otherwised saved as part of simulation objects).

Switch to using is_storage_iterable everywhere
@codecov
Copy link

codecov bot commented Jan 17, 2021

Codecov Report

Merging #961 (dc4c346) into master (dc4c346) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #961   +/-   ##
=======================================
  Coverage   80.25%   80.25%           
=======================================
  Files         136      136           
  Lines       14449    14449           
=======================================
  Hits        11596    11596           
  Misses       2853     2853           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc4c346...c7a021b. Read the comment docs.

@dwhswenson
Copy link
Member Author

This is ready for review and comment. I will leave it open for at least 24 hours, merging no earlier than Mon 18 Jan 14:00 GMT (15:00 local).

@sroet
Copy link
Member

sroet commented Jan 17, 2021

Looked at the code, and this is definitely a cleaner implementation so +1 for that.
However, I don't see how this implementation is different from the previous one? (As it seems like a cache-wrapper around the same if-statement, so it shouldn't change the behavior?)

Do you mind adding a test-case that would illustrate the failure/fix? (also to prevent regression later on, as you definitely want to keep the ability to save simtk.unit.Quantity stuff)

@dwhswenson
Copy link
Member Author

dwhswenson commented Jan 17, 2021

However, I don't see how this implementation is different from the previous one? (As it seems like a cache-wrapper around the same if-statement, so it shouldn't change the behavior?)

Easier to show with code. The fundamental problem is this:

>>> from simtk import unit
>>> from collections.abc import Iterable
>>> q = 2.0 * unit.nanometers
>>> isinstance(q, Iterable)
True

I would raise this as a bug, but I think Pete's probably already annoyed at me for not replying quickly on his fix for the simtk.unit bug I filed a couple weeks ago. 😆 (Issue here: isinstance(..., Iterable) checks for the presence of __iter__; simtk.unit.Quantity implements __iter__ and raises errors if the underlying thing isn't iterable.)

In any case, this is why the following things were added to SimStore and the OPS implementation of storage:

def force_true(self, cls):
self._false_set.discard(cls)
self._true_set.add(cls)
def force_false(self, cls):
self._true_set.discard(cls)
self._false_set.add(cls)

is_storage_iterable.force_false(simtk.unit.Quantity)

If it actually is iterable, we still want to treat as not (the same way we do with numpy). Actually, I should probably move the numpy check into a similar setup in the class lookup: Just use force_false for that, too.

Do you mind adding a test-case that would illustrate the failure/fix? (also to prevent regression later on, as you definitely want to keep the ability to save simtk.unit.Quantity stuff)

Good point; will do.

@sroet
Copy link
Member

sroet commented Jan 17, 2021

is_storage_iterable.force_false(simtk.unit.Quantity)

Ah. I understand now how this differs from the replaced if statement (other than caching), I had not stumbled across that line when reviewing this PR.
Thanks for explaining it, I would still prefer a test to prevent regression, but other than that this looks good to me.

@dwhswenson
Copy link
Member Author

Good thing that:

  1. You asked for those tests, and
  2. I had just relearned git diff main...branch as a way to remember what was in old unmerged branches, as well as git rev-list --left-right --count main...branch to get ahead/behind.

It turns out that I had failed to push the commit with the tests for simtk unit storage! The test you asked for is the last one in that file, and the most recent commit. But better to have the tests I wrote a month ago, too!

Copy link
Member

@sroet sroet left a comment

Choose a reason for hiding this comment

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

Looks mostly good to me.

One comment about the last test, as I think it is sidestepping the test due to caching, but feel free to ignore that if that is a misinterpretation of the test

openpathsampling/experimental/storage/test_simtk_unit.py Outdated Show resolved Hide resolved
Co-authored-by: Sander Roet <sanderroet@hotmail.com>
Copy link
Member

@sroet sroet left a comment

Choose a reason for hiding this comment

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

I am not sure why codecov doesn't like it, but this looks good to me now :)

@dwhswenson
Copy link
Member Author

I am not sure why codecov doesn't like it

It seems to catch up when the Py27 unit tests finish. For some reason, Py27 takes a really long time to install (I guess conda has improved performance?), so Py37 is finishing notebooks as Py27 is starting them.

We do have some tests that are a bit flaky on coverage, so I used to see a few lines (maybe 10 or so) vary in coverage. We should allow drops of 0.05% or so; not sure if I've done that or left it extremely strict.

@sroet
Copy link
Member

sroet commented Jan 17, 2021

It seems to catch up when the Py27 unit tests finish. For some reason, Py27 takes a really long time to install (I guess conda has improved performance?), so Py37 is finishing notebooks as Py27 is starting them.

Indeed, it seems to update when the tests finish. All green now at least :)

@dwhswenson dwhswenson merged commit 5384e3f into openpathsampling:master Jan 19, 2021
@dwhswenson dwhswenson deleted the fix-simstore-simtk branch January 19, 2021 09:42
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.

None yet

2 participants