-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 qpy serialization of substitution of type ParameterExpression
#13890
base: main
Are you sure you want to change the base?
Conversation
When substitution history `ParameterExpression._qpy_replay` is serialized, there was no branch for the case that the substituted value is of type `ParameterExpression`. This commit fixes this oversight.
Pull Request Test Coverage Report for Build 13427794082Details
💛 - Coveralls |
EDIT: Fixed in fa0d254
|
* Added a branch for reading `ParameterExpression` in _qpy_replay * Added a missing argument (version) in an existing call in code path that was previously untested * Remove a bit of useless code introduced in last commit * run black
One or more of the following people are relevant to this code:
|
I ported this to Qiskit v1.3.2 and verified that it works. On the main branch, I can't test with qiskit-ibm-runtime, because it is incompatible with the qiskit development branch. The fix applied to the stable release Qiskit v1.3.2 is not worth much, because deserializing on the server end fails of course. It will need to be updated, too. Because of this, it looks like this will require a version bump in qpy. |
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.
Overall this LGTM, I left one small comment inside about trying to minimize the diff for backport reasons. The other thing which might be good is adding a backwards compatibilty test to https://github.com/Qiskit/qiskit/blob/main/test/qpy_compat/test_qpy.py to cover this case so that we ensure we can load payloads with these types of expressions from qiskit >= 1.4.1
with QPY 13.
Because of this, it looks like this will require a version bump in qpy.
I'm on the fence about this. From the way the format spec is written this was just an oversight in the implementation so I view it as a straight bug in the v13 implementation that neither serialization or deserialization works with nested substituted parameter expressions. But your also correct that no v13 implementation out there works with this model yet which makes it feel like doing this in v14 is a better choice.
I'm inclined to just leave this as a v13 fix, and not require v14 for it since the format is still parsable in v13, it will just error because of the deserialization bug.
@@ -229,14 +232,22 @@ def _write_parameter_expression(file_obj, obj, use_symengine, *, version): | |||
file_obj.write(elem_header) | |||
file_obj.write(symbol_data) | |||
file_obj.write(value_data) | |||
for symbol in extra_symbols.values(): | |||
for symbol in extra_expressions.values(): |
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.
Do you mind reverting the name change here? I agree with the change in the naming, but since we're probably going to backport this PR for 1.4.1 I think it's better to minimize the diff to reduce the risk of regression. So we can keep the change here to just the functional component below adding the missing handling of the PARAMETER_EXPRESSION
type in the extra expression/symbols.
We can do the renaming in a standalone PR that we don't backport.
When substitution history
ParameterExpression._qpy_replay
is serialized, there was no branch for the case that the substituted value is of typeParameterExpression
.This commit fixes this oversight.
Tests need to be added.Closes #13879