stimcirq 1.16.dev1746599232__tar.gz → 1.16.dev1747178717__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/PKG-INFO +1 -1
  2. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/setup.py +1 -1
  3. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/__init__.py +1 -1
  4. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_obs_annotation.py +12 -1
  5. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_obs_annotation_test.py +24 -3
  6. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_stim_to_cirq.py +13 -6
  7. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_stim_to_cirq_test.py +16 -0
  8. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq.egg-info/PKG-INFO +1 -1
  9. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/README.md +0 -0
  10. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/setup.cfg +0 -0
  11. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_cirq_to_stim.py +0 -0
  12. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_cirq_to_stim_test.py +0 -0
  13. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_cx_swap_gate.py +0 -0
  14. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_cx_swap_test.py +0 -0
  15. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_cz_swap_gate.py +0 -0
  16. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_cz_swap_test.py +0 -0
  17. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_det_annotation.py +0 -0
  18. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_det_annotation_test.py +0 -0
  19. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_i_error_gate.py +0 -0
  20. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_i_error_gate_test.py +0 -0
  21. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_ii_error_gate.py +0 -0
  22. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_ii_error_gate_test.py +0 -0
  23. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_ii_gate.py +0 -0
  24. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_ii_gate_test.py +0 -0
  25. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_measure_and_or_reset_gate.py +0 -0
  26. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_measure_and_or_reset_gate_test.py +0 -0
  27. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_shift_coords_annotation.py +0 -0
  28. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_shift_coords_annotation_test.py +0 -0
  29. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_stim_sampler.py +0 -0
  30. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_stim_sampler_test.py +0 -0
  31. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_sweep_pauli.py +0 -0
  32. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_sweep_pauli_test.py +0 -0
  33. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_two_qubit_asymmetric_depolarize.py +0 -0
  34. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq/_two_qubit_asymmetric_depolarize_test.py +0 -0
  35. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq.egg-info/SOURCES.txt +0 -0
  36. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq.egg-info/dependency_links.txt +0 -0
  37. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq.egg-info/requires.txt +0 -0
  38. {stimcirq-1.16.dev1746599232 → stimcirq-1.16.dev1747178717}/stimcirq.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stimcirq
3
- Version: 1.16.dev1746599232
3
+ Version: 1.16.dev1747178717
4
4
  Summary: Implements a cirq.Sampler backed by stim.
5
5
  Home-page: https://github.com/quantumlib/stim
6
6
  Author: Craig Gidney
@@ -17,7 +17,7 @@ from setuptools import setup
17
17
  with open('README.md', encoding='UTF-8') as f:
18
18
  long_description = f.read()
19
19
 
20
- __version__ = '1.16.dev1746599232'
20
+ __version__ = '1.16.dev1747178717'
21
21
 
22
22
  setup(
23
23
  name='stimcirq',
@@ -1,4 +1,4 @@
1
- __version__ = '1.16.dev1746599232'
1
+ __version__ = '1.16.dev1747178717'
2
2
  from ._cirq_to_stim import cirq_circuit_to_stim_circuit
3
3
  from ._cx_swap_gate import CXSwapGate
4
4
  from ._cz_swap_gate import CZSwapGate
@@ -16,6 +16,7 @@ class CumulativeObservableAnnotation(cirq.Operation):
16
16
  *,
17
17
  parity_keys: Iterable[str] = (),
18
18
  relative_keys: Iterable[int] = (),
19
+ pauli_keys: Iterable[str] = (),
19
20
  observable_index: int,
20
21
  ):
21
22
  """
@@ -28,6 +29,7 @@ class CumulativeObservableAnnotation(cirq.Operation):
28
29
  """
29
30
  self.parity_keys = frozenset(parity_keys)
30
31
  self.relative_keys = frozenset(relative_keys)
32
+ self.pauli_keys = frozenset(pauli_keys)
31
33
  self.observable_index = observable_index
32
34
 
33
35
  @property
@@ -38,11 +40,12 @@ class CumulativeObservableAnnotation(cirq.Operation):
38
40
  return self
39
41
 
40
42
  def _value_equality_values_(self) -> Any:
41
- return self.parity_keys, self.relative_keys, self.observable_index
43
+ return self.parity_keys, self.relative_keys, self.pauli_keys, self.observable_index
42
44
 
43
45
  def _circuit_diagram_info_(self, args: Any) -> str:
44
46
  items: List[str] = [repr(e) for e in sorted(self.parity_keys)]
45
47
  items += [f'rec[{e}]' for e in sorted(self.relative_keys)]
48
+ items += sorted(self.pauli_keys)
46
49
  k = ",".join(str(e) for e in items)
47
50
  return f"Obs{self.observable_index}({k})"
48
51
 
@@ -51,6 +54,7 @@ class CumulativeObservableAnnotation(cirq.Operation):
51
54
  f'stimcirq.CumulativeObservableAnnotation('
52
55
  f'parity_keys={sorted(self.parity_keys)}, '
53
56
  f'relative_keys={sorted(self.relative_keys)}, '
57
+ f'pauli_keys={sorted(self.pauli_keys)}, '
54
58
  f'observable_index={self.observable_index!r})'
55
59
  )
56
60
 
@@ -62,6 +66,7 @@ class CumulativeObservableAnnotation(cirq.Operation):
62
66
  result = {
63
67
  'parity_keys': sorted(self.parity_keys),
64
68
  'observable_index': self.observable_index,
69
+ 'pauli_keys': sorted(self.pauli_keys),
65
70
  }
66
71
  if self.relative_keys:
67
72
  result['relative_keys'] = sorted(self.relative_keys)
@@ -104,6 +109,12 @@ class CumulativeObservableAnnotation(cirq.Operation):
104
109
  rec_targets.append(stim.target_rec(-1 - offset))
105
110
  if not remaining:
106
111
  break
112
+ rec_targets.extend(
113
+ [
114
+ stim.target_pauli(qubit_index=int(k[1:]), pauli=k[0])
115
+ for k in sorted(self.pauli_keys)
116
+ ]
117
+ )
107
118
  if remaining:
108
119
  raise ValueError(
109
120
  f"{self!r} was processed before measurements it referenced ({sorted(remaining)!r})."
@@ -191,9 +191,30 @@ def test_json_serialization():
191
191
  c2 = cirq.read_json(json_text=json, resolvers=[*cirq.DEFAULT_RESOLVERS, stimcirq.JSON_RESOLVER])
192
192
  assert c == c2
193
193
 
194
+ def test_json_serialization_with_pauli_keys():
195
+ c = cirq.Circuit(
196
+ stimcirq.CumulativeObservableAnnotation(parity_keys=["a", "b"], observable_index=5, pauli_keys=["X0", "Y1", "Z2"]),
197
+ stimcirq.CumulativeObservableAnnotation(
198
+ parity_keys=["a", "b"], relative_keys=[-1, -3], observable_index=5, pauli_keys=["X0", "Y1", "Z2"]
199
+ ),
200
+ stimcirq.CumulativeObservableAnnotation(observable_index=2, pauli_keys=["X0", "Y1", "Z2"]),
201
+ stimcirq.CumulativeObservableAnnotation(parity_keys=["d", "c"], observable_index=5, pauli_keys=["X0", "Y1", "Z2"]),
202
+ )
203
+ json = cirq.to_json(c)
204
+ c2 = cirq.read_json(json_text=json, resolvers=[*cirq.DEFAULT_RESOLVERS, stimcirq.JSON_RESOLVER])
205
+ assert c == c2
206
+
194
207
 
195
208
  def test_json_backwards_compat_exact():
196
209
  raw = stimcirq.CumulativeObservableAnnotation(parity_keys=['z'], relative_keys=[-2], observable_index=5)
197
- packed = '{\n "cirq_type": "CumulativeObservableAnnotation",\n "parity_keys": [\n "z"\n ],\n "observable_index": 5,\n "relative_keys": [\n -2\n ]\n}'
198
- assert cirq.read_json(json_text=packed, resolvers=[*cirq.DEFAULT_RESOLVERS, stimcirq.JSON_RESOLVER]) == raw
199
- assert cirq.to_json(raw) == packed
210
+ packed_v1 = '{\n "cirq_type": "CumulativeObservableAnnotation",\n "parity_keys": [\n "z"\n ],\n "observable_index": 5,\n "relative_keys": [\n -2\n ]\n}'
211
+ packed_v2 ='{\n "cirq_type": "CumulativeObservableAnnotation",\n "parity_keys": [\n "z"\n ],\n "observable_index": 5,\n "pauli_keys": [],\n "relative_keys": [\n -2\n ]\n}'
212
+ assert cirq.read_json(json_text=packed_v1, resolvers=[*cirq.DEFAULT_RESOLVERS, stimcirq.JSON_RESOLVER]) == raw
213
+ assert cirq.read_json(json_text=packed_v2, resolvers=[*cirq.DEFAULT_RESOLVERS, stimcirq.JSON_RESOLVER]) == raw
214
+ assert cirq.to_json(raw) == packed_v2
215
+
216
+ # With pauli_keys
217
+ raw = stimcirq.CumulativeObservableAnnotation(parity_keys=['z'], relative_keys=[-2], observable_index=5, pauli_keys=["X0", "Y1", "Z2"])
218
+ packed_v2 ='{\n "cirq_type": "CumulativeObservableAnnotation",\n "parity_keys": [\n "z"\n ],\n "observable_index": 5,\n "pauli_keys": [\n "X0",\n "Y1",\n "Z2"\n ],\n "relative_keys": [\n -2\n ]\n}'
219
+ assert cirq.read_json(json_text=packed_v2, resolvers=[*cirq.DEFAULT_RESOLVERS, stimcirq.JSON_RESOLVER]) == raw
220
+ assert cirq.to_json(raw) == packed_v2
@@ -340,11 +340,18 @@ class CircuitTranslationTracker:
340
340
 
341
341
  def resolve_measurement_record_keys(
342
342
  self, targets: Iterable[stim.GateTarget]
343
- ) -> Tuple[List[str], List[int]]:
343
+ ) -> Tuple[List[str], List[int], List[str]]:
344
+ pauli_targets, meas_targets = [], []
345
+ for t in targets:
346
+ if t.is_measurement_record_target:
347
+ meas_targets.append(t)
348
+ else:
349
+ pauli_targets.append(f'{t.pauli_type}{t.value}')
350
+
344
351
  if self.have_seen_loop:
345
- return [], [t.value for t in targets]
352
+ return [], [t.value for t in meas_targets], pauli_targets
346
353
  else:
347
- return [str(self.num_measurements_seen + t.value) for t in targets], []
354
+ return [str(self.num_measurements_seen + t.value) for t in meas_targets], [], pauli_targets
348
355
 
349
356
  def process_detector(self, instruction: stim.CircuitInstruction) -> None:
350
357
  if instruction.tag:
@@ -352,7 +359,7 @@ class CircuitTranslationTracker:
352
359
  else:
353
360
  tags = ()
354
361
  coords = self.coords_after_offset(instruction.gate_args_copy())
355
- keys, rels = self.resolve_measurement_record_keys(instruction.targets_copy())
362
+ keys, rels, _ = self.resolve_measurement_record_keys(instruction.targets_copy())
356
363
  self.append_operation(
357
364
  DetAnnotation(parity_keys=keys, relative_keys=rels, coordinate_metadata=coords).with_tags(*tags)
358
365
  )
@@ -364,10 +371,10 @@ class CircuitTranslationTracker:
364
371
  tags = ()
365
372
  args = instruction.gate_args_copy()
366
373
  index = 0 if not args else int(args[0])
367
- keys, rels = self.resolve_measurement_record_keys(instruction.targets_copy())
374
+ keys, rels, paulis = self.resolve_measurement_record_keys(instruction.targets_copy())
368
375
  self.append_operation(
369
376
  CumulativeObservableAnnotation(
370
- parity_keys=keys, relative_keys=rels, observable_index=index
377
+ parity_keys=keys, relative_keys=rels, pauli_keys=paulis, observable_index=index
371
378
  ).with_tags(*tags)
372
379
  )
373
380
 
@@ -763,3 +763,19 @@ def test_id_error_round_trip():
763
763
  cirq_circuit = stimcirq.stim_circuit_to_cirq_circuit(stim_circuit)
764
764
  restored_circuit = stimcirq.cirq_circuit_to_stim_circuit(cirq_circuit)
765
765
  assert restored_circuit == stim_circuit
766
+
767
+ def test_round_trip_with_pauli_obs():
768
+ stim_circuit = stim.Circuit("""
769
+ QUBIT_COORDS(5, 5) 0
770
+ R 0
771
+ OBSERVABLE_INCLUDE(0) X0
772
+ TICK
773
+ H 0
774
+ TICK
775
+ M 0
776
+ OBSERVABLE_INCLUDE(0) rec[-1]
777
+ TICK
778
+ """)
779
+ cirq_circuit = stimcirq.stim_circuit_to_cirq_circuit(stim_circuit)
780
+ restored_circuit = stimcirq.cirq_circuit_to_stim_circuit(cirq_circuit)
781
+ assert restored_circuit == stim_circuit
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stimcirq
3
- Version: 1.16.dev1746599232
3
+ Version: 1.16.dev1747178717
4
4
  Summary: Implements a cirq.Sampler backed by stim.
5
5
  Home-page: https://github.com/quantumlib/stim
6
6
  Author: Craig Gidney