-
Notifications
You must be signed in to change notification settings - Fork 320
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
Field Vectors attributes should only be floats #1458
Conversation
The doc string says that the parameters can only be floats, however this goes unchecked and _silently_ ignored. This causes bugs far upstream. Proposed changes: make the parameters floats. There are two entry points for a parameter: inside set_component and during __init__. The rest of _compute_unknowns, set_vector, _set_attribute_values, and _set_attribute_value, despite what the names would suggests do not need changing. Backstory: The AMI430 magnet uses a field vector inside the 3-axis driver. This driver sets the the 'r' component of the vector to np.int32(0). This is fine, as numpy casting means most things work out. Then, the snapshot of the driver is supposed to return a json serializable object, including the unchecked 'r' value however numpy.in32 s are not json serializable. This means snapshot of the driver fails, crashing user defined acquisition code. Weather the AMI430 driver /should/ set 'r' to np.int32(0) is a different bug and pull request. Regards, Matt
My mistake, quick fix.
Are you using the latest qcodes? I'm asking because the issue of JSON serializing a station snapshot with numpy (and other) type has been resolved, see this line where a specific JSON serializer class is being passed to We should strive to fix the right things. If you're using the latest qcodes, then the bug should be somewhere else (not in the field vector). Otherwise, I'd love to hear more on "Whether the AMI430 driver /should/ set 'r' to np.int32(0) is a bug" :) |
( Regardless of the comment above, (almost all) the changes in this PR are valid ) |
We are using the latest qcodes. However we are using the standard json encoder without the qcodes extension ( I didn't know it was needed/existed). Sometimes using fast-json if performance is needed. We had assumed that the snapshot should be JSON-encodable because the docstring for qcodes.instrument says that the snapshot dictionary is the "State of the instrument as a JSON-compatible dict." which I had believed. However if it always needs to go through the pre-processor described in
I fully agree.
If I can fix the 'almost' let me know. Cheers, |
@GeneralSarsby, I think the "almost" part is basically just some missing parentheses that make the tests fail. |
This tells me that you are not using the "qcodes infrastructure" for storing snapshots, right? in this case, you seem to be doing something hacky/unsupported. Just to explain the custom encoder - the python default one has a limited support for data types, for example not all funky numpy stuff is supported. For the reason of supporting more datatypes, qcodes uses an custom extended json encoder class. Performance is fine, but there is no surprise that some performance penalties may be expected when non-standard python types are used.
As i already explain above, this is unavoidable because not everything useful is built into python, and not everything should.
here we need to be careful. "snapshot" is initially a python dictionary, and that's what snapshots are until they arrive to the
I'd rather have a full picture of what is going on because "fixing one thing at once" may change the other bug that you happen to be looking into. To conclude: let know about the other bug(s) and then it will be clear what fixes need to be done. |
fixed missing brackets
The test case wrongly assumes that the field vector is an integer. However as field vectors are floats, this needs updating.
Codecov Report
@@ Coverage Diff @@
## master #1458 +/- ##
==========================================
+ Coverage 73.78% 73.81% +0.03%
==========================================
Files 92 92
Lines 10439 10435 -4
==========================================
+ Hits 7702 7703 +1
+ Misses 2737 2732 -5 |
Trying to use google style for docs, also minor refactoring of handling optionals
After an offline discussion with @GeneralSarsby , we've agreed to proceed with this PR so that there is no ambiguitiy in types of values insidethe field vector. The driver-related bugs will be discovered and tackled in other PRs. @QCoDeS/core could you review this and see if you agree with this suggested change? (i'm gonna add an explicit test for the |
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.
Apart from the type checking issue in CI and the missing tests this looks fine
Merge: 66f8d93 1e4c4c8 Author: Mikhail Astafev <[email protected]> Merge pull request #1458 from GeneralSarsby/patch-1
The doc string says that the parameters can only be floats, however this goes unchecked and silently ignored.
This causes bugs far upstream.
Proposed changes: make the parameters floats.
There are two entry points for a parameter: inside set_component and during init.
The rest of _compute_unknowns, set_vector, _set_attribute_values, and _set_attribute_value, despite what the names would suggests do not need changing.
Backstory:
The AMI430 magnet uses a field vector inside the 3-axis driver.
This driver sets the the 'r' component of the vector to np.int32(0). This is fine, as numpy casting means
most things work out.
Then, the snapshot of the driver is supposed to return a json serializable object, including the unchecked 'r' value however numpy.in32 s are not json serializable.
This means snapshot of the driver fails, crashing user defined acquisition code.
Weather the AMI430 driver /should/ set 'r' to np.int32(0) is a different bug and pull request.
Regards,
Matt
Simple reproducible bug: