-
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.0, 1.2 and 1.3
- Python version: 3.12.7
- Operating system: Linux
What is happening?
The commutation checker always fails to commute a PauliGate with any other gate. I get this error message.
return self.cc.commute(op1, qargs1, cargs1, op2, qargs2, cargs2, max_num_qubits)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
qiskit.exceptions.QiskitError: 'Unable to hash a non-float instruction parameter.'
I think it is because the parameter in a PauliGate
is the Pauli
operator that it implements rather than a Parameter
or a float
. I realized that CommutatorChecker
did not have a unittest for this particular case, and also I have tried it for different python versions 1.0, 1.2 and 1.3. 1.0 and 1.2 work fine but 1.3 does not.
2 things have changed.
- The way that parameters are hashed has been ported to rust (the parameter in
PauliGate
is a string so I don't see why we can't hash it). - Before if one of the gates was parameterized
commute
would returnFalse
. Now it does some more invoved logic.
How can we reproduce the issue?
from qiskit.circuit.commutation_library import SessionCommutationChecker as scc
from qiskit.circuit.library.generalized_gates.pauli import PauliGate
from qiskit.circuit.library.standard_gates.rx import RXGate
from qiskit.circuit.library.standard_gates.x import XGate
from qiskit.circuit.parameter import Parameter
pauli_gate = PauliGate("XX")
# pauli_gate = XGate()
rx_gate_theta = RXGate(Parameter("Theta"))
print(scc.commute(pauli_gate, [0, 1], [], rx_gate_theta, [0], []))
print(scc.commute(rx_gate_theta, [0], [], pauli_gate, [0, 1], []))
What should happen?
For versions up to 1.2 we get False
(which is not the correct answer). And for version 1.3 we get the error message.
Any suggestions?
I think the best option would be to fix the hashing. If there is a deeper reason why that is not possible then we need to change the logic of the function.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working