-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
bugSomething isn't workingSomething isn't working
Milestone
Description
Environment
- Qiskit version: 1.3
- Python version:
- Operating system:
What is happening?
An external repo that accesses an internal property of ParameterExpression
started breaking with qiskit 1.3 for the official QOAO tutorial. This can be traced back to an unexpected complex coefficient in the PauliEvolutionGate
parameter expression that builds the QAOA ansatz.
How can we reproduce the issue?
The original issue was caught with this reproducing code (it accesses internal properties )
from qiskit.quantum_info import SparsePauliOp
from qiskit import QuantumCircuit
from qiskit.circuit.library import QAOAAnsatz
from qiskit.transpiler import PassManager
from qiskit.transpiler.passes import HighLevelSynthesis
from qiskit.circuit import ParameterExpression
cost_operator = SparsePauliOp.from_list([("IIZZ", -1), ("ZIIZ", 1), ("IZIZ", 2)])
cost_layer = QAOAAnsatz(
cost_operator,
mixer_operator=QuantumCircuit(4),
initial_state=QuantumCircuit(4),
reps=1,
).decompose()
pass_manager = PassManager([HighLevelSynthesis(basis_gates=["rzz"])])
circuit = pass_manager.run(cost_layer)
for inst in circuit.data:
iop = inst.operation
print("param expression", iop.params[0])
print("symbol expression", iop.params[0]._symbol_expr)
The output with 1.2.4 is:
param expression -2.0*γ[0]
symbol expression -2.0*γ[0]
param expression 2.0*γ[0]
symbol expression 2.0*γ[0]
param expression 4.0*γ[0]
symbol expression 4.0*γ[0]
While 1.3.0+ shows:
param expression -2.0*γ[0]
symbol expression (-2.0 + 0.0*I)*γ[0]
param expression 2.0*γ[0]
symbol expression (2.0 + 0.0*I)*γ[0]
param expression 4.0*γ[0]
symbol expression (4.0 + 0.0*I)*γ[0]
But this issue can also be seen with a shorter snippet:
time = Parameter("t")
evo = PauliEvolutionGate(Z, time=time)
angle = evo.definition.data[0].operation.params[0]
print(angle.sympify())
What should happen?
No complex coefficients should be found
Any suggestions?
Working on a fix with @Cryoris
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working