Skip to content

Improve coverage of _decompose_into_clifford_with_qubits_ and has_stabilizer_effect protocols #5906

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

Closed
tanujkhattar opened this issue Oct 3, 2022 · 6 comments
Assignees
Labels
area/clifford-group good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. good for learning For beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues" kind/feature-request Describes new functionality priority/p2 Next release should contain it triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on

Comments

@tanujkhattar
Copy link
Collaborator

tanujkhattar commented Oct 3, 2022

Is your feature request related to a use case or problem? Please describe.
The two protocols were added to Cirq to support fast stabilizer simulations for (mostly) Clifford operations. See #2600 (review) and #2423 for historical context.

However, the coverage of these two protocols across Cirq gates is not great. For example;

>>> cirq.has_stabilizer_effect(cirq.XX)
False # Should be true.
>>> hasattr(cirq.XX, '_decompose_into_clifford_with_qubits_')
True
>>> hasattr(cirq.ZZ, '_decompose_into_clifford_with_qubits_')
False # Should be true?

Describe the solution you'd like
This feature request is to improve the coverage of has_stabilizer_effect and _decompose_into_clifford_with_qubits_ protocols so that:

  1. For all out gates defined by Cirq, users can easily identify whether the gate is a Clifford or not by calling these protocols.
  2. Consider adding a cirq.is_clifford protocol which fallbacks to cirq.decompose to figure out if the current gate is a clifford or not by recursively checking whether all gates that the current gate decomposes into are cliffords or not.
  3. Add consistency checks as part of assert_implements_consistent_protocols

What is the urgency from your perspective for this issue? Is it blocking important work?
P1 - I need this no later than the next release (end of quarter)

@tanujkhattar tanujkhattar added good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. kind/feature-request Describes new functionality priority/p2 Next release should contain it good for learning For beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues" area/clifford-group triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Oct 3, 2022
@tanujkhattar tanujkhattar added triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Oct 12, 2022
@tanujkhattar
Copy link
Collaborator Author

@NoureldinYosri Do you want to take a stab at this issue?

@NoureldinYosri
Copy link
Collaborator

@tanujkhattar sure, can you assign it to me?

@NoureldinYosri
Copy link
Collaborator

there are two ways to do this

  1. Bruteforce add has_stabilizer_effect and _decompose_into_clifford_with_qubits_ to more gate classes.
  2. Implement an algorithm that checks if a general unitary is a clifford operator (e.g. https://quantumcomputing.stackexchange.com/a/13158) and use it when the number of qubits of the operation is small (e.g. $\leq 4$) and for operations on more qubits fallback to the checking its decomposition.

The second option is more scalable and should be fast enough since we will only apply it when the unitary is relatively small.

@tanujkhattar
Copy link
Collaborator Author

Should we do both? We can make quick improvements to has_stabilizer_effect and _decompose_into_clifford_with_qubits_ to improve coverage (this should take a few days) and then also implement the algorithm to check if a general unitary is a clifford or not (this can take a few weeks)?

I think there is value in getting a quick fix for this this one; unless we think the general algorithm can be implemented within a week or two. What do you think?

@NoureldinYosri
Copy link
Collaborator

I have a prototype for the algorithm so it shouldn't take long to get it in a decent shape and create a PR.

A minor issue of the algorithm is that it is a numerical algorithm so what we get in the end is a check that depends on the tolerance we use (yes means definatly a clifford, no means maybe a larger tolerance could turn it to yes).

so the algorithm is would be a quick fix.. but adding the has_stabilizer_effect and _decompose_into_clifford_with_qubits_ to the most commonly used gates should also be done before closing this issue

NoureldinYosri added a commit that referenced this issue Jul 5, 2023
- This is the first step to implementing the algorithm in #5906 (comment)
- Based on https://quantumcomputing.stackexchange.com/questions/13157/how-do-i-check-if-a-gate-represented-by-unitary-u-is-a-clifford-gate#comment17495_13158
- The complexity of this algorithm is $\mathcal{O}(n 4^n)$ where $n$ is the number of qubits it acts on or alternatively $\mathcal{O}(S \log_4{S})$ where $S$ is the size of the unitary.
@NoureldinYosri
Copy link
Collaborator

NoureldinYosri commented Nov 2, 2023

I compiled a list of classes that I think should be covered by the protocols inorder to achieve the goal of this issue:

  • cirq.ops.clifford_gate.CliffordGate
  • cirq.ops.dense_pauli_string.DensePauliString
  • cirq.ops.parity_gates.XXPowGate
  • cirq.ops.parity_gates.YYPowGate
  • cirq.ops.parity_gates.ZZPowGate
  • cirq.ops.pauli_interaction_gate.PauliInteractionGate
  • cirq.ops.pauli_string_phasor.PauliStringPhasorGate
  • cirq.ops.pauli_measurement_gate.PauliMeasurementGate
  • cirq.ops.boolean_hamiltonian.BooleanHamiltonianGat

Most of these gates have _decompose_ method defined that yields clifford gates so _decompose_into_clifford_with_qubits_ would just copy that decomposition.

@NoureldinYosri NoureldinYosri moved this to In Progress in Cirq 2023 roadmap Nov 2, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in Cirq 2023 roadmap Dec 20, 2023
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this issue Oct 31, 2024
- This is the first step to implementing the algorithm in quantumlib#5906 (comment)
- Based on https://quantumcomputing.stackexchange.com/questions/13157/how-do-i-check-if-a-gate-represented-by-unitary-u-is-a-clifford-gate#comment17495_13158
- The complexity of this algorithm is $\mathcal{O}(n 4^n)$ where $n$ is the number of qubits it acts on or alternatively $\mathcal{O}(S \log_4{S})$ where $S$ is the size of the unitary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/clifford-group good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. good for learning For beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues" kind/feature-request Describes new functionality priority/p2 Next release should contain it triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants