Skip to content

Conversation

@dwhswenson
Copy link
Member

@dwhswenson dwhswenson commented Jun 17, 2021

A recurring issue has been that users create CVs that return length-1 arrays/lists, and then use these CVs to define volumes/interfaces. Because Python/NumPy allow order comparisons on length-1 iterables as if they were scalars, sampling goes fine. However, some aspects of analysis expect the CVs to output scalars, and then users get cryptic error messages at unexpected points.

This PR emits a warning if the CV used by a CVDefinedVolume returns an iterable.

See also #1029.

  • Initial implementation for len-1 arrays
  • Warn on any iterable: the CV for a CVDefinedVolume should not, in general, be any kind of iterable (although things that aren't orderable will fail later anyway)
  • Add tests

@codecov
Copy link

codecov bot commented Jun 17, 2021

Codecov Report

Merging #1030 (3d1cbc0) into master (aaff2b8) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1030      +/-   ##
==========================================
+ Coverage   81.30%   81.31%   +0.01%     
==========================================
  Files         139      139              
  Lines       15150    15165      +15     
==========================================
+ Hits        12318    12332      +14     
- Misses       2832     2833       +1     
Impacted Files Coverage Δ
openpathsampling/volume.py 93.44% <100.00%> (+0.38%) ⬆️
openpathsampling/netcdfplus/cache.py 63.72% <0.00%> (-0.33%) ⬇️
openpathsampling/numerics/histogram.py 83.98% <0.00%> (-0.06%) ⬇️

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 aaff2b8...3d1cbc0. Read the comment docs.

@dwhswenson dwhswenson changed the title Warn if CVDefinedVolume CVs return len-1 arrays Warn if CVDefinedVolume CVs return iterables Jun 18, 2021
@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 Sat 19 Jun 19:00 GMT (15:00 my local).

In general, I'm not a fan of this sort of type checking. However, we've seen problems with this coming from multiple users, so I think it's worth giving a reasonably early warning that a user might notice and fix before doing a lot of sampling.

@dwhswenson dwhswenson merged commit 793a075 into openpathsampling:master Jun 23, 2021
@dwhswenson dwhswenson deleted the warn-singleton-cv branch June 23, 2021 17:52
@dwhswenson dwhswenson mentioned this pull request Jul 5, 2021
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.

1 participant