Skip to content
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

Commutation Checker with PauliGate #13570

Open
MarcDrudis opened this issue Dec 16, 2024 · 0 comments
Open

Commutation Checker with PauliGate #13570

MarcDrudis opened this issue Dec 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@MarcDrudis
Copy link
Contributor

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.

  1. 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).
  2. Before if one of the gates was parameterized commute would return False. 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.

@MarcDrudis MarcDrudis added the bug Something isn't working label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant