-
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
TypeError: ParameterExpression with unbound parameters (set()) cannot be cast to a float. #9187
Comments
I'm agreed that the error message from In general, if you introduce complex numbers into your parameters as a user, you're the one responsible for handling the potentially lossy cast back to reals. In your case there's no floating-point fuzziness, but if you use your parameters more, you can easily end up in the case of having something like |
Hello, Thanks for the answer. I understand your point. However, as a user I feel like this could be handled better, and it doesn't seem very consistent with other parts of Qiskit.
Here, Qiskit has no problem discarding the null imaginary part and effectively treating the coefficient as a real number. The only difference is I added
The coefficient is exactly the same as in the code that raises the error, yet here it was converted to a float. In this case, the user doesn't get to decide how the complex number is handled. I don't see why the same shouldn't happen for the exponentiated version.
raises In my view, it doesn't make sense to raise an error when the imaginary part of the coefficient of the Hamiltonian is non-null (thereby recognizing that the imaginary part shouldn't exist), but expect the user to handle it when the imaginary part is zero (or very close to it). If the fact that the coefficient is complex (even with null imaginary part) will cause problems later on, then maybe the error should be raised here, as happens for coefficients with non-null imaginary parts.
E.g., this works:
But if we change the first line into
we get |
### Summary This PR aims to remove the use of complex amplitude for `SymbolicPulse` in calibration experiments. Most notable changes are to the `HalfAngleCal` experiment and the `FixedFrquencyTransmon` library. With these changes, support of complex values in general raises a `PendingDeprecationWarning`. ### Details and comments Qiskit Terra recently changed the representation of `SymbolicPulse` from complex amplitude to (`amp`,`angle`). Once the deprecation is completed, some calibration experiments will fail. Additionally, assignment of complex parameters in general has caused problems recently (See Qiskit-Terra issue [9187](Qiskit/qiskit#9187)), and is also being phased out (See Qiskit-Terra PR [9735](Qiskit/qiskit#9735)). Most calibration experiments are oblivious to these changes, with the exception of `HalfAngleCal` and `RoughAmplitudeCal`. The library `FixedFrequencyTransmon` also has to conform with the new representation. To create as little breaking changes as possible, the following were changed: - `FixedFrequencyTransmon` library was converted to the new representation. All experiments will work as they have been with it. - `RoughAmplitudeCal` was changed such that it will work for both real or complex `amp`, without changing the type of the value. - `HalfAngleCal` was changed to calibrate 'angle' instead of the complex amplitude. A user which uses the `FixedFrequencyTransmon` library will experience no change (except for the added parameters). A user which uses custom built schedules will experience an error. To simplify the transition, most likely scenarios (schedule with no `angle` parameter, `cal_parameter_name="amp"`) will raise an informative error with explanation about the needed changes. A `PendingDeprecationWarning` is raised with every initialization of `ParameterValue` with complex type value (which also covers addition of parameter value to a calibration). Note that Qiskit-Terra PR [9897](Qiskit/qiskit#9897) will also raise a warning from the Terra side, for all assignment of complex parameters. Handling of loaded calibrations which do not conform to the new representation will be sorted out once PR #1120 is merged, as it introduces a major change in calibration loading. --------- Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com> Co-authored-by: Will Shanks <wshaos@posteo.net> Co-authored-by: Daniel J. Egger <38065505+eggerdj@users.noreply.github.com>
I inadvertently fixed this in #10183. There I changed because I did not intend to fix this and I think there are still some outstanding issues ( |
I accidentally opened a dup. It might lay things out clearly though: #10191 It may be inadvertently fixed. But it should be fixed at a lower level. Like |
The issue still persists when building a controlled-version of a parameterized gate. |
Environment
What is happening?
Creating and evaluating a Trotter evolution circuit for certain operators raises an error. The error message indicates that the
ParameterExpression
has unbound parameters, even though this is not the case.This issue has similarities with #7507, but it's not the same. The proposed solution in there (forcing the parameter to a float in
PauliEvolutionGate.validate_parameter
) does not work in this case.How can we reproduce the issue?
What should happen?
bound_circuit
should be evaluated without errors.Any suggestions?
The problem seems to arise in the
_apply_operation
method ofParameterExpression
. When our (yet unbound)param
is multiplied by the numeric coefficient (1j * 0.5j
, simplified to0.5 + 0j
), the values of the relevant local variables inside that method are as follows:Later when the parameter θ is bound to -0.1, the attribute
_symbol_expr
associated with theParameterExpression
is-0.1*(-0.5 + 0.0*I)
. Casting this to a float is what gives an error (RuntimeError: Not Implemented
). The error doesn't occur if_symbol_expr
is-0.1*(-0.5)
.Naively, doing
in
_apply_operation
fixes the issue.Alternatively, the error doesn't occur if we change the code the reproduces the problem into
i.e., if the coefficient is real to begin with. However, this seems a bit rigid, as we might want to define operators with imaginary coefficients.
The text was updated successfully, but these errors were encountered: