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

CollectCliffords pass ignores Rz's #13138

Closed
samanthavbarron opened this issue Sep 11, 2024 · 0 comments · Fixed by #13214
Closed

CollectCliffords pass ignores Rz's #13138

samanthavbarron opened this issue Sep 11, 2024 · 0 comments · Fixed by #13214
Assignees
Labels
bug Something isn't working

Comments

@samanthavbarron
Copy link
Contributor

Environment

  • Qiskit version: 1.2.0
  • Python version: 3.12.3
  • Operating system: MacOS

What is happening?

rz gates are ignored by the CollectCliffords pass (regardless of angle), when it could potentially collect them.

How can we reproduce the issue?

from qiskit import QuantumCircuit
from qiskit.transpiler import PassManager
from qiskit.transpiler.passes import CollectCliffords

qc = QuantumCircuit(1)
qc.rz(0, 0)
qc.sx(0)

PassManager([CollectCliffords(min_block_size=1)]).run(qc).draw()

What should happen?

There should be a single instruction in the resulting circuit, however I get

   ┌───────┐┌──────────┐
q: ┤ Rz(0) ├┤ Clifford ├
   └───────┘└──────────┘

Any suggestions?

It seems this function is just looking at _BASIS_1Q which doesn't include rz (and shouldn't, IMO).

Presumably this issue extends to other parameterized gates.

A possible fix would be to instead have an option in CollectCliffords which attempts to cast it as a Clifford. Since this would likely come at a performance hit, it should probably be False by default.

E.g.

def _is_clifford_gate(node, try_harder: bool = False):
    """Specifies whether a node holds a clifford gate."""
    if getattr(node.op, "condition", None) is not None:
        return False
    if node.op.name in clifford_gate_names:
        return True
    
    if not try_harder:
        return False
    
    try:
        Clifford(node.op)
        return True
    except:
        return False
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

Successfully merging a pull request may close this issue.

2 participants