-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Cast fully bound ParameterExpression
to float within the PauliEvolutionGate
#7508
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
Conversation
Pull Request Test Coverage Report for Build 3329512584
💛 - Coveralls |
ParameterExpression
to float within the PauliEvolutionGate
ParameterExpression
to float within the PauliEvolutionGate
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.
Is there a case where we would expect the ParameterExpression
to not be able to be cast to a float
while having an empty parameters
? The error message TypeError: ParameterExpression with unbound parameters (set()) cannot be cast to a float.
makes me wonder if something is going wrong earlier in the process.
@kdk: yes, if the parameter is complex. From attaching pdb to the traceback, the issue here is that somewhere in the process, the time is getting turned into In [10]: from qiskit.circuit import Parameter
...: import numpy as np
...:
...: t = Parameter("t")
...: t.bind({t: 0.25}), np.array([t.bind({t: 0.25})], dtype=float)
Out[10]: (ParameterExpression(0.25), array([0.25])) |
Thanks for tracking that down! Another solution would be to leave |
Using the regression test added in this PR, but modified for Qiskit 1.0: from qiskit.circuit import Parameter, QuantumCircuit
from qiskit.quantum_info import Pauli, Operator
from qiskit.circuit.library import PauliEvolutionGate
from qiskit.synthesis import MatrixExponential
op = Pauli("X")
time = Parameter("t")
evo_gate = PauliEvolutionGate(op, time, synthesis=MatrixExponential())
circuit = QuantumCircuit(1)
circuit.append(evo_gate, [0])
bound = circuit.assign_parameters({time: 0.12})
ref = QuantumCircuit(1)
ref.rx(0.24, 0)
assert Operator(bound).equiv(ref) this no longer fails, and #7507 is no longer reproducible either, so I'll close this as obsoleted. Feel free to reopen if there's more to be done. |
Summary
Fixes #7507.
Details and comments
The underlying issue here is that
ParameterExpression
s, after being fully bound, often remainParameterExpression
s instead of being cast to float/complex. This PR fixes it very high-level, but maybe we should put this fix already at the level ofInstruction.validate_parameter
.Misses: