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

Define cirq.PAULI_GATE_LIKE #2557

Merged
merged 7 commits into from
Nov 16, 2019
Merged

Define cirq.PAULI_GATE_LIKE #2557

merged 7 commits into from
Nov 16, 2019

Conversation

Strilanc
Copy link
Contributor

@Strilanc Strilanc commented Nov 15, 2019

  • Use in cirq.PauliString and cirq.DensePauliString
  • Generalize to allow lower case "ixyz"
  • Make it consistent to allow integers 0=I, 1=X, 2=Y, 3=Z

Example:

cirq.PauliString({
    cirq.GridQubit(0, 0): 0,
    cirq.GridQubit(0, 1): 1,
    cirq.GridQubit(0, 2): 2,
    cirq.GridQubit(0, 3): 3,
})
X((0, 1))*Y((0, 2))*Z((0, 3))

- Generalize to allow lower case "ixyz"
- Generalize to allow integers 0=I, 1=X, 2=Y, 3=Z

Example:

```python
cirq.PauliString({
    cirq.GridQubit(0, 0): 0,
    cirq.GridQubit(0, 1): 1,
    cirq.GridQubit(0, 2): 2,
    cirq.GridQubit(0, 3): 3,
})
```

```
X((0, 1))*Y((0, 2))*Z((0, 3))
```
@googlebot googlebot added the cla: yes Makes googlebot stop complaining. label Nov 15, 2019
Copy link
Collaborator

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

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

lgtm

cirq/ops/pauli_string.py Show resolved Hide resolved
@@ -272,6 +284,14 @@ def __bool__(self):
def __len__(self) -> int:
return len(self._qubit_pauli_map)

def _repr_pretty_(self, p: Any, cycle: bool) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you explain? is this because jupyter shows the repr by default which is way too long because of the need for roundtrippability?

I have some prototype code that defines _repr_latex_ on paulistring which looks pretty nice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's because the representation is shorter this way.

_z = cast(pauli_gates.Pauli, pauli_gates.Z) # type: ignore

PAULI_GATE_LIKE_TO_GATE_MAP: Dict['cirq.PAULI_GATE_LIKE',
Union['cirq.Pauli', 'cirq.IdentityGate']] = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

weird line wrapping

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. yapf wants what it wants, who are we to judge.

3: _z,
}

PAULI_GATE_LIKE_TO_INDEX_MAP: Dict['cirq.PAULI_GATE_LIKE', int] = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

define one of these using the other?

I_TO_PAULI = [_i, _x, _y, _z]

pauligateliketogate = {k: I_TO_PAULI[PAULI_GATE_LIKE_TO_INDEX_MAP]] for k in pgltim}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@Strilanc Strilanc added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 16, 2019
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Nov 16, 2019
@CirqBot
Copy link
Collaborator

CirqBot commented Nov 16, 2019

Automerge cancelled: A status check is failing.

@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 Nov 16, 2019
@Strilanc Strilanc added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 16, 2019
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Nov 16, 2019
@CirqBot CirqBot merged commit e904305 into master Nov 16, 2019
@CirqBot CirqBot removed the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 16, 2019
@CirqBot CirqBot deleted the identify5 branch November 16, 2019 08:55
@CirqBot CirqBot removed the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Nov 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants