-
Notifications
You must be signed in to change notification settings - Fork 301
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
Find or create an instrument without worrying about existing instances #1210
Find or create an instrument without worrying about existing instances #1210
Conversation
It avoids the need to worry about which instruments are instantiated and which are not, and conveniently works out possible exceptions raised from the Instrument.find_instrument method.
Codecov Report
@@ Coverage Diff @@
## master #1210 +/- ##
==========================================
+ Coverage 80.53% 80.76% +0.23%
==========================================
Files 49 49
Lines 6821 6841 +20
==========================================
+ Hits 5493 5525 +32
+ Misses 1328 1316 -12 |
- allows to recreate an instrument even though it was found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Could consider documenting and or testing what happens if an instrument of the same name but a different class exists. As far a I can see that will raise a TypeError inside find_instrument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
just added a test and a note about "same name, different class" case. If necessary, the current behavior can be revisited later. |
This new function
find_or_create_instrument
avoids the hassle of usage ofInstrument.find_instrument
. In case an instrument does not already exist, the latter will throw an exception, while the new function will just return the reference to that instrument.If this function is used to create instruments, then it can be reexecuted, because unlike
find_instrument
or just reinstantiation with a constructor, this function does not throw. Moreover, thanks to therecreate
kwarg, it allows to recreate an instance of the instrument in case one already exists.Researchers find this convenience function very handy.
pytopo
repository (Delft lab) also has a variation of this convenience function. Even I ended up implementing this function forv0_characterization
experiment and repository.@wpfff Let me know if this is good enough (I've decided to avoid the
force_new_instance
feature). Update: aligned on the solution.