-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Calibrations involving bound parameters fail to roundtrip through QPY #9764
Comments
Investigated. This is the issue of repr of My old PR could address this issue if symengine is available in your environement. Basically symengine expression can be directly serialized without making plain text, i.e. (Edit) The PR above has dependency on the next release of symengine, which has not been released for a while. |
Likely sympy from sympy import simplify
qc2_assigned = qc2.assign_parameters(param_bind)
expr = expr = qc2_assigned.data[0][0].params[0]
>>> float(expr._symbol_expr), float(simplify(expr._symbol_expr))
(-1.7131982974314244, -1.71319829743142) Here |
Unfortunately looks like your PR's still on hold, since the necessary Symengine fix is merged to main, but they haven't cut a 0.10.0 release. Other than that, though, yeah, your PR looks like a much more straightforwards way to go than serialisation to string. |
Thanks for your comment on my PR. As you pointed out, my PR would break portability of QPY data. We need another mechanism to serialize expression without changing significant digits, or we should promote symengine to be required. Alternatively we could use single precision floating point in circuit calibrations dictionary. |
Python doesn't natively support single-precision floats, so I suppose what we'd really be saying is that we round the stored data in Making the calibration dict fuzzy in any way just to support deficiencies in parameter serialisation via QPY is probably not going to be very satisfying. I wonder if we could accept a performance hit in QPY where we verify on write-out that the roundtrip is exactly equal, and revert to some slower-but-safer serialisation method if it isn't? I'm not very sure what that would be, though. |
Hmm me neither. Probably we can typecast expression to float before calling sympy from qiskit.circuit import Parameter
p = Parameter("p")
v = -1.7131982974314244
p_assigned = p.assign(p, v)
float(p_assigned) == p_assigned # True I think this doesn't break any reference. (edit) but we cannot recover digits of coefficients in unbound expression. this could be an issue for QASM3 with offloaded parameter binding? |
I found that it's a bug of symengine. See symengine/symengine#1901. It rounds float value with wrong digits, which may affect translation of symengine expression to sympy expression, which is necessary for serialization in QPY. Note that this issue has been already fixed in their master branch but just not released. I tried to install their master branch but it was really complicated and I gave up. I think we just need to wait for symengine 0.10. |
For temp fix you can uninstall symengine from your env. This allows you to bypass the expression typecast at the price of performance. |
Environment
What is happening?
Calibrations that are defined for gates whose parameters are precisely of type
float
seem to roundtrip through QPY just fine. However, if the calibration is made to a gate whose parameters are fully boundParameterExpression
s, then a QPY-roundtripped circuit doesn't seem to recognise the calibration any more.How can we reproduce the issue?
gives
Notably,
roundtrip(qc2_t)
still does appear to have the requisite calibration, it's just not quite recognised correctly:What should happen?
The roundtripped circuit should still recognise that it has a calibration for that instruction.
Any suggestions?
I think what's happening is that the floating-point number in the
ParameterExpression
is changing by 1 ULP, which sounds suspiciously like there might be a dodgy float-to-str conversion happening somewhere in theParameterExpression
handling in QPY?I mean, the underlying cause is another of these things where fully assigned
ParameterExpression
s not immediately becoming regular floats is causing problems. But either way, if it happens with boundParameterExpression
, I'm sure there'll be mechanisms to trigger it with bound ones as well, we just don't notice as much if they're like 1ULP differences in a random float coefficient in a mostly symbolic calculation.See Qiskit/qiskit-ibm-runtime#666.
cc: @kt474, @nbronn.
The text was updated successfully, but these errors were encountered: