-
Notifications
You must be signed in to change notification settings - Fork 164
Change how pauli_keys are represented in CummulativeObservableAnnotation #982
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
d0edee1
1d06580
b4d5c02
814f013
1bfb296
879e4f9
03dbe13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from typing import Any, Dict, Iterable, List, Tuple | ||
from typing import Any, Dict, Iterable, List, Mapping, Tuple | ||
|
||
import cirq | ||
import stim | ||
|
@@ -16,7 +16,7 @@ def __init__( | |
*, | ||
parity_keys: Iterable[str] = (), | ||
relative_keys: Iterable[int] = (), | ||
pauli_keys: Iterable[str] = (), | ||
pauli_keys: Iterable[tuple[cirq.Qid, str]] | Iterable[str] = (), | ||
observable_index: int, | ||
): | ||
""" | ||
|
@@ -29,15 +29,31 @@ def __init__( | |
""" | ||
self.parity_keys = frozenset(parity_keys) | ||
self.relative_keys = frozenset(relative_keys) | ||
self.pauli_keys = frozenset(pauli_keys) | ||
_pauli_keys = [] | ||
for k in pauli_keys: | ||
if isinstance(k, str): | ||
# For backward compatibility | ||
_pauli_keys.append((cirq.LineQubit(int(k[1:])), k[0])) | ||
else: | ||
_pauli_keys.append(tuple(k)) | ||
self.pauli_keys = frozenset(_pauli_keys) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if a user has code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you mean that changing the type of We could keep the type Anyway, again I'm open to whatever you think is the best solution here. Let me know! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main thing is that you must make the changes in a way that doesn't break existing code. Existing code is likely to depend on the type of public fields, so you cannot change their type. You can add other fields, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I tried a version of this. Let me know what you think! |
||
self.observable_index = observable_index | ||
|
||
@property | ||
def qubits(self) -> Tuple[cirq.Qid, ...]: | ||
return () | ||
return tuple(sorted(q for q, _ in self.pauli_keys)) | ||
|
||
def with_qubits(self, *new_qubits) -> 'CumulativeObservableAnnotation': | ||
return self | ||
if len(self.qubits) == len(new_qubits): | ||
pauli_map = dict(self.pauli_keys) | ||
return CumulativeObservableAnnotation( | ||
parity_keys=self.parity_keys, | ||
relative_keys=self.relative_keys, | ||
pauli_keys=tuple((new_q, pauli_map[q]) for new_q, q in zip(new_qubits, self.qubits)), | ||
observable_index=self.observable_index, | ||
) | ||
|
||
raise ValueError("Number of qubits does not match") | ||
|
||
def _value_equality_values_(self) -> Any: | ||
return self.parity_keys, self.relative_keys, self.pauli_keys, self.observable_index | ||
|
@@ -85,6 +101,7 @@ def _stim_conversion_( | |
edit_measurement_key_lengths: List[Tuple[str, int]], | ||
have_seen_loop: bool = False, | ||
tag: str, | ||
targets: list[int], | ||
**kwargs, | ||
): | ||
# Ideally these references would all be resolved ahead of time, to avoid the redundant | ||
|
@@ -109,10 +126,11 @@ def _stim_conversion_( | |
rec_targets.append(stim.target_rec(-1 - offset)) | ||
if not remaining: | ||
break | ||
pauli_map = dict(self.pauli_keys) | ||
rec_targets.extend( | ||
[ | ||
stim.target_pauli(qubit_index=int(k[1:]), pauli=k[0]) | ||
for k in sorted(self.pauli_keys) | ||
stim.target_pauli(qubit_index=tid, pauli=pauli_map[q]) | ||
for q, tid in zip(self.qubits, targets) | ||
] | ||
) | ||
if remaining: | ||
|
Uh oh!
There was an error while loading. Please reload this page.