-
Notifications
You must be signed in to change notification settings - Fork 984
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
Conversation
- 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)) ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@@ -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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
cirq/ops/pauli_string.py
Outdated
_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']] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird line wrapping
There was a problem hiding this comment.
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] = { |
There was a problem hiding this comment.
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}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Automerge cancelled: A status check is failing. |
cirq.PauliString
andcirq.DensePauliString
Example: