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

Refactor the single qubit Clifford gate #5069

Merged
merged 43 commits into from
Apr 20, 2022

Conversation

BichengYing
Copy link
Collaborator

@BichengYing BichengYing commented Mar 11, 2022

This PR mainly moved the SingleQubitCliffordGate as the derived class of CliffordGate.

It didn't add any new functionalities or features. The code change looks large but actually not. Because I moved the
SingleQubitCliffordGate to the place after CliffordGate and auto-diff is not that smart enough to tell that. Context #4791.

Main change are:

  1. Modify the value equality so that SingleQubitCliffordGate can be evaluate equal to the same CliffordGate
  2. Moved the module-level initialization common SingleQubitCliffordGate (like X, Y, Z) to the class-level one.
  3. Make a few function SingleQubitCliffordGate to use CliffordGate one.

@CirqBot CirqBot added the size: XL lines changed >1000 label Mar 11, 2022
@property
def X(cls):
if getattr(cls, '_X', None) is None:
cls._Z = cls._generate_clifford_from_known_gate(1, pauli_gates.X)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these copy paste errors? The _Xs, _Ys, and _Zs are all intermixed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, great catch! Thanks!

@@ -878,3 +490,387 @@ def _act_on_(self, args: 'cirq.ActOnArgs', qubits: Sequence['cirq.Qid']) -> bool
return NotImplemented

return NotImplemented

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're here, the sig for _act_on_ should be _act_on_(self, args: 'cirq.OperationTarget', qubits: Sequence['cirq.Qid']) -> bool

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will update it in this PR as well.

@BichengYing BichengYing requested a review from cduck as a code owner March 24, 2022 04:31
@BichengYing BichengYing requested a review from viathor March 24, 2022 04:31
@MichaelBroughton MichaelBroughton self-assigned this Mar 28, 2022
Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for review @daxfohl .

@MichaelBroughton MichaelBroughton added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Apr 4, 2022
@CirqBot
Copy link
Collaborator

CirqBot commented Apr 4, 2022

Automerge cancelled: There are merge conflicts.

@CirqBot CirqBot removed the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Apr 4, 2022
args: 'cirq.OperationTarget', # pylint: disable=unused-argument
qubits: Sequence['cirq.Qid'], # pylint: disable=unused-argument
):
# TODO(PR number) will create a PR if we agree on adding this.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daxfohl @MichaelBroughton Do you have any objection on this?

Copy link
Contributor

@daxfohl daxfohl Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but thanks for asking. I noticed this a few weeks ago and my initial thought was to ask for a change here. I'd been trying to remove all the isinstance checks from act_on because it made more sense that the simulator should know about gates but not vice versa. However here, I feel like this is an example of a gate that operates on a higher level than the simulator, because the gate itself is specifically designed to work with Clifford simulators. So I think this is an example where it's okay.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None from me. Can we resolve the merge conflicts so we can retry the auto merge ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@MichaelBroughton
Copy link
Collaborator

Looks like there is still a little bit of formatting and merge conflicts.

@BichengYing
Copy link
Collaborator Author

BichengYing commented Apr 17, 2022

Yeah, that probably is because of recent black version update. Hopefully, it is resolved this time.

@MichaelBroughton MichaelBroughton added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Apr 20, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Apr 20, 2022
@CirqBot CirqBot merged commit be1569b into quantumlib:master Apr 20, 2022
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Apr 20, 2022
tonybruguier pushed a commit to tonybruguier/Cirq that referenced this pull request Apr 22, 2022
This PR mainly moved the `SingleQubitCliffordGate` as the derived class of `CliffordGate`.

It didn't add any new functionalities or features. The code change looks large but actually not. Because I moved the
`SingleQubitCliffordGate` to the place after `CliffordGate` and auto-diff is not that smart enough to tell that. Context quantumlib#4791.

 Main change are:
1. Modify the value equality so that SingleQubitCliffordGate can be evaluate equal to the same CliffordGate
2. Moved the module-level initialization common SingleQubitCliffordGate (like X, Y, Z) to the class-level one.
3. Make a few function `SingleQubitCliffordGate` to use `CliffordGate` one.
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
This PR mainly moved the `SingleQubitCliffordGate` as the derived class of `CliffordGate`.

It didn't add any new functionalities or features. The code change looks large but actually not. Because I moved the
`SingleQubitCliffordGate` to the place after `CliffordGate` and auto-diff is not that smart enough to tell that. Context quantumlib#4791.

 Main change are:
1. Modify the value equality so that SingleQubitCliffordGate can be evaluate equal to the same CliffordGate
2. Moved the module-level initialization common SingleQubitCliffordGate (like X, Y, Z) to the class-level one.
3. Make a few function `SingleQubitCliffordGate` to use `CliffordGate` one.
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
This PR mainly moved the `SingleQubitCliffordGate` as the derived class of `CliffordGate`.

It didn't add any new functionalities or features. The code change looks large but actually not. Because I moved the
`SingleQubitCliffordGate` to the place after `CliffordGate` and auto-diff is not that smart enough to tell that. Context quantumlib#4791.

 Main change are:
1. Modify the value equality so that SingleQubitCliffordGate can be evaluate equal to the same CliffordGate
2. Moved the module-level initialization common SingleQubitCliffordGate (like X, Y, Z) to the class-level one.
3. Make a few function `SingleQubitCliffordGate` to use `CliffordGate` one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: XL lines changed >1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants