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

Add test to check platform precision using a string + fix error #551

Merged
merged 2 commits into from Feb 22, 2022

Conversation

mikemhenry
Copy link
Contributor

Description

Fixes #550

Todos

  • Implement feature / fix bug
  • Add tests
  • Update documentation as needed
  • Update changelogNotable points that this PR has either accomplished or will accomplish.

Status

  • Ready to go

@mikemhenry mikemhenry changed the title add test to check platform precision using a string Add test to check platform precision using a string + fix error Feb 21, 2022
@mikemhenry
Copy link
Contributor Author

Okay this was a tricky one!

We did import openmm at the top of utils.py but because we had an openmm import inside the function, it confused python:
https://github.com/choderalab/openmmtools/blob/main/openmmtools/utils.py#L547-L550

See this example

>>> import sys
>>> def foo():
...  print(sys)
...  if True:
...   import sys
... 
>>> foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in foo
UnboundLocalError: local variable 'sys' referenced before assignment
>>> 

@jchodera
Copy link
Member

Shouldn't we favor local imports (imports inside functions) so that we incur the overhead of importing OpenMM (which sometimes takes several seconds) only when we need it?

@sroet
Copy link
Contributor

sroet commented Feb 22, 2022

Shouldn't we favor local imports (imports inside functions) so that we incur the overhead of importing OpenMM (which sometimes takes several seconds) only when we need it?

(Just my opinion, feel free to ignore)
In general, yes. However, for at least one of the classes defined in that file unit is required to be imported. So you can't really get around the module level openmm import for openmm >= 7.6 (as that is done implicitly when calling from openmm import unit)

@mikemhenry, sorry for not catching this in #528 and thanks for adding a test.

@jchodera
Copy link
Member

Great point, @sroet! Looks like there's no way around the import overhead there. This should be good to go then @mikemhenry.

Copy link
Member

@jchodera jchodera left a comment

Choose a reason for hiding this comment

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

Thanks!

@mikemhenry mikemhenry merged commit 4fab09b into main Feb 22, 2022
@mikemhenry mikemhenry deleted the fix/platform_supports_precision branch February 22, 2022 16:23
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.

platform_supports_precision broken when using a string
3 participants