cirq-core 1.3.0.dev20231201141002__py3-none-any.whl → 1.4.0__py3-none-any.whl

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 (157) hide show
  1. cirq/__init__.py +4 -0
  2. cirq/_compat.py +9 -11
  3. cirq/_compat_test.py +45 -56
  4. cirq/_version.py +31 -1
  5. cirq/_version_test.py +1 -1
  6. cirq/circuits/circuit.py +13 -8
  7. cirq/circuits/circuit_operation.py +2 -1
  8. cirq/circuits/circuit_test.py +2 -2
  9. cirq/circuits/frozen_circuit.py +3 -2
  10. cirq/circuits/moment.py +12 -10
  11. cirq/circuits/qasm_output.py +5 -1
  12. cirq/circuits/qasm_output_test.py +25 -10
  13. cirq/contrib/qcircuit/qcircuit_diagram_info.py +9 -7
  14. cirq/contrib/quimb/mps_simulator_test.py +1 -1
  15. cirq/contrib/quimb/state_vector.py +9 -2
  16. cirq/contrib/svg/svg.py +2 -1
  17. cirq/contrib/svg/svg_test.py +1 -0
  18. cirq/devices/grid_qubit.py +85 -32
  19. cirq/devices/grid_qubit_test.py +22 -4
  20. cirq/devices/line_qubit.py +74 -26
  21. cirq/devices/line_qubit_test.py +19 -0
  22. cirq/devices/noise_utils.py +33 -31
  23. cirq/devices/noise_utils_test.py +1 -84
  24. cirq/devices/superconducting_qubits_noise_properties.py +7 -6
  25. cirq/experiments/__init__.py +8 -0
  26. cirq/experiments/qubit_characterizations.py +288 -44
  27. cirq/experiments/qubit_characterizations_test.py +61 -7
  28. cirq/experiments/random_quantum_circuit_generation.py +1 -1
  29. cirq/experiments/single_qubit_readout_calibration.py +132 -6
  30. cirq/experiments/single_qubit_readout_calibration_test.py +3 -1
  31. cirq/experiments/t1_decay_experiment.py +14 -7
  32. cirq/experiments/t1_decay_experiment_test.py +14 -26
  33. cirq/experiments/two_qubit_xeb.py +483 -0
  34. cirq/experiments/two_qubit_xeb_test.py +304 -0
  35. cirq/json_resolver_cache.py +2 -0
  36. cirq/linalg/decompositions.py +11 -13
  37. cirq/linalg/decompositions_test.py +1 -3
  38. cirq/linalg/diagonalize.py +5 -4
  39. cirq/linalg/predicates.py +8 -6
  40. cirq/linalg/transformations.py +2 -1
  41. cirq/linalg/transformations_test.py +1 -1
  42. cirq/ops/__init__.py +2 -0
  43. cirq/ops/clifford_gate.py +59 -16
  44. cirq/ops/common_gates_test.py +1 -2
  45. cirq/ops/control_values.py +4 -3
  46. cirq/ops/controlled_gate_test.py +1 -3
  47. cirq/ops/gate_operation.py +10 -1
  48. cirq/ops/named_qubit.py +74 -28
  49. cirq/ops/named_qubit_test.py +19 -0
  50. cirq/ops/parity_gates.py +5 -0
  51. cirq/ops/parity_gates_test.py +2 -10
  52. cirq/ops/pauli_gates.py +5 -2
  53. cirq/ops/pauli_string.py +2 -2
  54. cirq/ops/permutation_gate.py +16 -18
  55. cirq/ops/phased_iswap_gate_test.py +1 -3
  56. cirq/ops/phased_x_gate.py +1 -1
  57. cirq/ops/phased_x_z_gate.py +17 -1
  58. cirq/ops/phased_x_z_gate_test.py +24 -0
  59. cirq/ops/qid_util.py +4 -8
  60. cirq/ops/qubit_manager.py +7 -4
  61. cirq/ops/qubit_manager_test.py +20 -0
  62. cirq/ops/raw_types.py +5 -2
  63. cirq/ops/raw_types_test.py +14 -15
  64. cirq/ops/uniform_superposition_gate.py +123 -0
  65. cirq/ops/uniform_superposition_gate_test.py +94 -0
  66. cirq/protocols/approximate_equality_protocol_test.py +2 -2
  67. cirq/protocols/circuit_diagram_info_protocol.py +6 -4
  68. cirq/protocols/commutes_protocol.py +2 -4
  69. cirq/protocols/decompose_protocol.py +7 -12
  70. cirq/protocols/decompose_protocol_test.py +7 -3
  71. cirq/protocols/has_stabilizer_effect_protocol.py +1 -5
  72. cirq/protocols/has_stabilizer_effect_protocol_test.py +13 -4
  73. cirq/protocols/json_serialization.py +51 -181
  74. cirq/protocols/json_serialization_test.py +13 -47
  75. cirq/protocols/json_test_data/CircuitOperation.json +131 -148
  76. cirq/protocols/json_test_data/CircuitOperation.json_inward +55 -0
  77. cirq/protocols/json_test_data/CircuitOperation.repr_inward +6 -0
  78. cirq/protocols/json_test_data/FrozenCircuit.json +196 -210
  79. cirq/protocols/json_test_data/FrozenCircuit.json_inward +35 -0
  80. cirq/protocols/json_test_data/FrozenCircuit.repr_inward +4 -0
  81. cirq/protocols/json_test_data/UniformSuperpositionGate.json +5 -0
  82. cirq/protocols/json_test_data/UniformSuperpositionGate.repr +1 -0
  83. cirq/protocols/json_test_data/cirq.MSGate.json +4 -0
  84. cirq/protocols/json_test_data/cirq.MSGate.repr +1 -0
  85. cirq/protocols/json_test_data/spec.py +2 -0
  86. cirq/protocols/pow_protocol_test.py +1 -3
  87. cirq/protocols/resolve_parameters.py +4 -2
  88. cirq/qis/__init__.py +10 -0
  89. cirq/qis/clifford_tableau.py +8 -2
  90. cirq/qis/noise_utils.py +123 -0
  91. cirq/qis/noise_utils_test.py +97 -0
  92. cirq/sim/classical_simulator.py +227 -87
  93. cirq/sim/classical_simulator_test.py +135 -0
  94. cirq/sim/clifford/clifford_simulator_test.py +4 -2
  95. cirq/sim/mux.py +5 -3
  96. cirq/sim/simulation_product_state.py +15 -10
  97. cirq/sim/simulation_state.py +1 -1
  98. cirq/sim/simulation_state_test.py +2 -2
  99. cirq/sim/simulator_base.py +3 -3
  100. cirq/sim/state_vector_simulation_state.py +4 -4
  101. cirq/sim/state_vector_simulator.py +17 -2
  102. cirq/study/__init__.py +1 -0
  103. cirq/study/result.py +14 -0
  104. cirq/study/result_test.py +6 -0
  105. cirq/study/sweeps.py +4 -2
  106. cirq/study/sweeps_test.py +8 -0
  107. cirq/testing/__init__.py +6 -1
  108. cirq/testing/_compat_test_data/__init__.py +3 -3
  109. cirq/testing/_compat_test_data/module_a/__init__.py +2 -2
  110. cirq/testing/circuit_compare.py +1 -1
  111. cirq/testing/consistent_qasm.py +6 -0
  112. cirq/testing/gate_features.py +10 -0
  113. cirq/testing/lin_alg_utils.py +5 -3
  114. cirq/transformers/__init__.py +15 -0
  115. cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +3 -1
  116. cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +24 -0
  117. cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +17 -0
  118. cirq/transformers/dynamical_decoupling.py +122 -0
  119. cirq/transformers/dynamical_decoupling_test.py +123 -0
  120. cirq/transformers/gauge_compiling/__init__.py +26 -0
  121. cirq/transformers/gauge_compiling/cz_gauge.py +46 -0
  122. cirq/transformers/gauge_compiling/cz_gauge_test.py +23 -0
  123. cirq/transformers/gauge_compiling/gauge_compiling.py +214 -0
  124. cirq/transformers/gauge_compiling/gauge_compiling_test.py +41 -0
  125. cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +83 -0
  126. cirq/transformers/gauge_compiling/gauge_compiling_test_utils_test.py +52 -0
  127. cirq/transformers/gauge_compiling/iswap_gauge.py +105 -0
  128. cirq/transformers/gauge_compiling/iswap_gauge_test.py +23 -0
  129. cirq/transformers/gauge_compiling/spin_inversion_gauge.py +33 -0
  130. cirq/transformers/gauge_compiling/spin_inversion_gauge_test.py +37 -0
  131. cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +64 -0
  132. cirq/transformers/gauge_compiling/sqrt_cz_gauge_test.py +27 -0
  133. cirq/transformers/gauge_compiling/sqrt_iswap_gauge.py +94 -0
  134. cirq/transformers/gauge_compiling/sqrt_iswap_gauge_test.py +22 -0
  135. cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +1 -0
  136. cirq/transformers/merge_k_qubit_gates_test.py +23 -23
  137. cirq/transformers/merge_single_qubit_gates_test.py +14 -14
  138. cirq/transformers/optimize_for_target_gateset.py +39 -17
  139. cirq/transformers/optimize_for_target_gateset_test.py +189 -39
  140. cirq/transformers/qubit_management_transformers.py +1 -1
  141. cirq/transformers/routing/visualize_routed_circuit_test.py +17 -17
  142. cirq/transformers/stratify_test.py +13 -13
  143. cirq/transformers/target_gatesets/compilation_target_gateset.py +26 -2
  144. cirq/transformers/target_gatesets/compilation_target_gateset_test.py +16 -16
  145. cirq/transformers/target_gatesets/cz_gateset.py +4 -0
  146. cirq/transformers/transformer_api.py +1 -2
  147. cirq/transformers/transformer_primitives.py +15 -14
  148. cirq/transformers/transformer_primitives_test.py +99 -72
  149. cirq/value/classical_data.py +6 -6
  150. cirq/value/value_equality_attr.py +4 -0
  151. cirq/work/sampler.py +3 -4
  152. cirq/work/sampler_test.py +25 -0
  153. {cirq_core-1.3.0.dev20231201141002.dist-info → cirq_core-1.4.0.dist-info}/METADATA +10 -19
  154. {cirq_core-1.3.0.dev20231201141002.dist-info → cirq_core-1.4.0.dist-info}/RECORD +157 -130
  155. {cirq_core-1.3.0.dev20231201141002.dist-info → cirq_core-1.4.0.dist-info}/WHEEL +1 -1
  156. {cirq_core-1.3.0.dev20231201141002.dist-info → cirq_core-1.4.0.dist-info}/LICENSE +0 -0
  157. {cirq_core-1.3.0.dev20231201141002.dist-info → cirq_core-1.4.0.dist-info}/top_level.txt +0 -0
@@ -46,19 +46,18 @@ def _to_target_circuit_type(
46
46
  ) -> CIRCUIT_TYPE:
47
47
  return cast(
48
48
  CIRCUIT_TYPE,
49
- circuit.unfreeze(copy=False)
50
- if isinstance(target_circuit, circuits.Circuit)
51
- else circuit.freeze(),
49
+ (
50
+ circuit.unfreeze(copy=False)
51
+ if isinstance(target_circuit, circuits.Circuit)
52
+ else circuit.freeze()
53
+ ),
52
54
  )
53
55
 
54
56
 
55
57
  def _create_target_circuit_type(ops: ops.OP_TREE, target_circuit: CIRCUIT_TYPE) -> CIRCUIT_TYPE:
56
- return cast(
57
- CIRCUIT_TYPE,
58
- circuits.Circuit(ops)
59
- if isinstance(target_circuit, circuits.Circuit)
60
- else circuits.FrozenCircuit(ops),
61
- )
58
+ if isinstance(target_circuit, circuits.FrozenCircuit):
59
+ return cast(CIRCUIT_TYPE, circuits.FrozenCircuit(ops).with_tags(*target_circuit.tags))
60
+ return cast(CIRCUIT_TYPE, circuits.Circuit(ops))
62
61
 
63
62
 
64
63
  def map_moments(
@@ -640,11 +639,13 @@ def merge_moments(
640
639
  if deep:
641
640
  circuit = map_operations(
642
641
  circuit,
643
- lambda op, _: op.untagged.replace(
644
- circuit=merge_moments(op.untagged.circuit, merge_func, deep=deep)
645
- ).with_tags(*op.tags)
646
- if isinstance(op.untagged, circuits.CircuitOperation)
647
- else op,
642
+ lambda op, _: (
643
+ op.untagged.replace(
644
+ circuit=merge_moments(op.untagged.circuit, merge_func, deep=deep)
645
+ ).with_tags(*op.tags)
646
+ if isinstance(op.untagged, circuits.CircuitOperation)
647
+ else op
648
+ ),
648
649
  tags_to_ignore=tags_to_ignore,
649
650
  )
650
651
  merged_moments: List[circuits.Moment] = [circuit[0]]
@@ -131,38 +131,38 @@ def test_map_operations_deep_subcircuits():
131
131
  )
132
132
 
133
133
  def map_func(op: cirq.Operation, _: int) -> cirq.OP_TREE:
134
- yield [
135
- cirq.Z.on_each(*op.qubits),
136
- cirq.CX(*op.qubits),
137
- cirq.Z.on_each(*op.qubits),
138
- ] if op.gate == cirq.CX else op
134
+ yield (
135
+ [cirq.Z.on_each(*op.qubits), cirq.CX(*op.qubits), cirq.Z.on_each(*op.qubits)]
136
+ if op.gate == cirq.CX
137
+ else op
138
+ )
139
139
 
140
140
  cirq.testing.assert_has_diagram(
141
141
  c_orig_with_circuit_ops,
142
142
  '''
143
- [ [ 0: ───@─── ] ]
144
- [ 0: ───[ │ ]────────────────────────────────────────────────────────────── ]
145
- [ [ 1: ───X─── ](loops=2)['internal'] ]
146
- [ │ ]
147
- [ 1: ───#2────────────────────────────────────────────────────────────────────────── ]
148
- [ ]
149
- [ [ 2: ───X─── ] ]
150
- 0: ───[ 2: ───[ │ ]────────────────────────────────────────────────────────────── ]────────────────────────
151
- [ [ 3: ───@─── ](loops=2)['internal'] ]
152
- [ │ ]
153
- [ │ [ 3: ───@─── ] ]
154
- [ 3: ───#2────────────────────────────────────[ │ ]──────────────────────── ]
155
- [ [ 4: ───X─── ](loops=2)['internal'] ]
156
- [ ]
157
- [ 4: ─────────────────────────────────────────#2──────────────────────────────────── ](loops=6)['external']
143
+ [ [ 0: ───@─── ] ]
144
+ [ 0: ───[ │ ]────────────────────────────────────────────────────────── ]
145
+ [ [ 1: ───X─── ](loops=2)[internal] ]
146
+ [ │ ]
147
+ [ 1: ───#2────────────────────────────────────────────────────────────────────── ]
148
+ [ ]
149
+ [ [ 2: ───X─── ] ]
150
+ 0: ───[ 2: ───[ │ ]────────────────────────────────────────────────────────── ]──────────────────────
151
+ [ [ 3: ───@─── ](loops=2)[internal] ]
152
+ [ │ ]
153
+ [ │ [ 3: ───@─── ] ]
154
+ [ 3: ───#2──────────────────────────────────[ │ ]────────────────────── ]
155
+ [ [ 4: ───X─── ](loops=2)[internal] ]
156
+ [ ]
157
+ [ 4: ───────────────────────────────────────#2────────────────────────────────── ](loops=6)[external]
158
158
 
159
- 1: ───#2────────────────────────────────────────────────────────────────────────────────────────────────────────────
159
+ 1: ───#2──────────────────────────────────────────────────────────────────────────────────────────────────────
160
160
 
161
- 2: ───#3────────────────────────────────────────────────────────────────────────────────────────────────────────────
161
+ 2: ───#3──────────────────────────────────────────────────────────────────────────────────────────────────────
162
162
 
163
- 3: ───#4────────────────────────────────────────────────────────────────────────────────────────────────────────────
163
+ 3: ───#4──────────────────────────────────────────────────────────────────────────────────────────────────────
164
164
 
165
- 4: ───#5────────────────────────────────────────────────────────────────────────────────────────────────────────────
165
+ 4: ───#5──────────────────────────────────────────────────────────────────────────────────────────────────────
166
166
  ''',
167
167
  )
168
168
 
@@ -175,29 +175,29 @@ def test_map_operations_deep_subcircuits():
175
175
  cirq.testing.assert_has_diagram(
176
176
  unroller(c_mapped, deep=True),
177
177
  '''
178
- [ [ 0: ───Z───@───Z─── ] ]
179
- [ 0: ───[ │ ]────────────────────────────────────────────────────────────────────── ]
180
- [ [ 1: ───Z───X───Z─── ](loops=2)['internal'] ]
181
- [ │ ]
182
- [ 1: ───#2────────────────────────────────────────────────────────────────────────────────────────── ]
183
- [ ]
184
- [ [ 2: ───Z───X───Z─── ] ]
185
- 0: ───[ 2: ───[ │ ]────────────────────────────────────────────────────────────────────── ]────────────────────────
186
- [ [ 3: ───Z───@───Z─── ](loops=2)['internal'] ]
187
- [ │ ]
188
- [ │ [ 3: ───Z───@───Z─── ] ]
189
- [ 3: ───#2────────────────────────────────────────────[ │ ]──────────────────────── ]
190
- [ [ 4: ───Z───X───Z─── ](loops=2)['internal'] ]
191
- [ ]
192
- [ 4: ─────────────────────────────────────────────────#2──────────────────────────────────────────── ](loops=6)['external']
178
+ [ [ 0: ───Z───@───Z─── ] ]
179
+ [ 0: ───[ │ ]────────────────────────────────────────────────────────────────── ]
180
+ [ [ 1: ───Z───X───Z─── ](loops=2)[internal] ]
181
+ [ │ ]
182
+ [ 1: ───#2────────────────────────────────────────────────────────────────────────────────────── ]
183
+ [ ]
184
+ [ [ 2: ───Z───X───Z─── ] ]
185
+ 0: ───[ 2: ───[ │ ]────────────────────────────────────────────────────────────────── ]──────────────────────
186
+ [ [ 3: ───Z───@───Z─── ](loops=2)[internal] ]
187
+ [ │ ]
188
+ [ │ [ 3: ───Z───@───Z─── ] ]
189
+ [ 3: ───#2──────────────────────────────────────────[ │ ]────────────────────── ]
190
+ [ [ 4: ───Z───X───Z─── ](loops=2)[internal] ]
191
+ [ ]
192
+ [ 4: ───────────────────────────────────────────────#2────────────────────────────────────────── ](loops=6)[external]
193
193
 
194
- 1: ───#2────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
194
+ 1: ───#2──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
195
195
 
196
- 2: ───#3────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
196
+ 2: ───#3──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
197
197
 
198
- 3: ───#4────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
198
+ 3: ───#4──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
199
199
 
200
- 4: ───#5────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
200
+ 4: ───#5──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
201
201
  ''',
202
202
  )
203
203
 
@@ -205,6 +205,33 @@ def test_map_operations_deep_subcircuits():
205
205
  # pylint: enable=line-too-long
206
206
 
207
207
 
208
+ @pytest.mark.parametrize("deep", [False, True])
209
+ def test_map_operations_preserves_circuit_tags(deep: bool) -> None:
210
+ tag = "should be preserved"
211
+
212
+ def func(op: cirq.Operation, idx: int) -> cirq.Operation:
213
+ return cirq.Y(op.qubits[0]) if op.gate == cirq.X else op
214
+
215
+ x = cirq.X(cirq.q(0))
216
+ circuit = cirq.FrozenCircuit.from_moments(x, cirq.FrozenCircuit(x)).with_tags(tag)
217
+ mapped = cirq.map_operations(circuit, func, deep=deep)
218
+
219
+ assert mapped.tags == (tag,)
220
+
221
+
222
+ def test_map_operations_deep_preserves_subcircuit_tags():
223
+ tag = "should be preserved"
224
+
225
+ def func(op: cirq.Operation, idx: int) -> cirq.Operation:
226
+ return cirq.Y(op.qubits[0]) if op.gate == cirq.X else op
227
+
228
+ x = cirq.X(cirq.q(0))
229
+ circuit = cirq.FrozenCircuit.from_moments(x, cirq.FrozenCircuit(x).with_tags(tag))
230
+ mapped = cirq.map_operations(circuit, func, deep=True)
231
+
232
+ assert mapped[1].operations[0].circuit.tags == (tag,)
233
+
234
+
208
235
  def test_map_operations_deep_respects_tags_to_ignore():
209
236
  q = cirq.LineQubit.range(2)
210
237
  c_nested = cirq.FrozenCircuit(cirq.CX(*q), cirq.CX(*q).with_tags("ignore"), cirq.CX(*q))
@@ -296,9 +323,9 @@ def test_unroll_circuit_op_and_variants():
296
323
  cirq.testing.assert_has_diagram(
297
324
  mapped_circuit_deep,
298
325
  '''
299
- 0: ───[ 0: ───X─── ]────────────────────────────────────────────────────────────X───
326
+ 0: ───[ 0: ───X─── ]──────────────────────────────────────────────────────────X───
300
327
 
301
- 1: ────────────────────[ 1: ───[ 1: ───Z───Z─── ]['<mapped_circuit_op>']─── ]───────
328
+ 1: ────────────────────[ 1: ───[ 1: ───Z───Z─── ][<mapped_circuit_op>]─── ]───────
302
329
  ''',
303
330
  )
304
331
  for unroller in [
@@ -614,11 +641,11 @@ def test_merge_operations_merges_connected_component():
614
641
  cirq.testing.assert_has_diagram(
615
642
  c_orig,
616
643
  '''
617
- 0: ───H───@───@───H───@───X───────@───────X───X['ignore']───@───
618
- │ │ │ │
619
- 1: ───H───┼───X───────@───────Y───X───@───────Y─────────────X───
644
+ 0: ───H───@───@───H───@───X───────@───────X───X[ignore]───@───
645
+ │ │ │ │
646
+ 1: ───H───┼───X───────@───────Y───X───@───────Y───────────X───
620
647
  │ │
621
- 2: ───H───X───────────────────────────X─────────────────────────
648
+ 2: ───H───X───────────────────────────X───────────────────────
622
649
  ''',
623
650
  )
624
651
 
@@ -685,11 +712,11 @@ def test_merge_operations_to_circuit_op_merges_connected_component():
685
712
  cirq.testing.assert_has_diagram(
686
713
  c_orig,
687
714
  '''
688
- 0: ───H───@───@───H───@───X───────@───────X───X['ignore']───@───
689
- │ │ │ │
690
- 1: ───H───┼───X───────@───────Y───X───@───────Y─────────────X───
715
+ 0: ───H───@───@───H───@───X───────@───────X───X[ignore]───@───
716
+ │ │ │ │
717
+ 1: ───H───┼───X───────@───────Y───X───@───────Y───────────X───
691
718
  │ │
692
- 2: ───H───X───────────────────────────X─────────────────────────
719
+ 2: ───H───X───────────────────────────X───────────────────────
693
720
  ''',
694
721
  )
695
722
 
@@ -704,12 +731,12 @@ def test_merge_operations_to_circuit_op_merges_connected_component():
704
731
  c_new,
705
732
  '''
706
733
  [ 0: ───────@───H───@───X───@───X─── ]
707
- 0: ───H───@───────────[ │ │ │ ]─────────────────────────────────X['ignore']───@───
708
- │ [ 1: ───H───X───────@───Y───X─────── ]['merged']
709
- │ │
710
- 1: ───────┼───────────#2─────────────────────────────────────────────────────────────@───────Y─────────────X───
711
-
712
- 2: ───H───X──────────────────────────────────────────────────────────────────────────X─────────────────────────
734
+ 0: ───H───@───────────[ │ │ │ ]───────────────────────────────X[ignore]───@───
735
+ │ [ 1: ───H───X───────@───Y───X─────── ][merged]
736
+ │ │
737
+ 1: ───────┼───────────#2───────────────────────────────────────────────────────────@───────Y───────────X───
738
+
739
+ 2: ───H───X────────────────────────────────────────────────────────────────────────X───────────────────────
713
740
  ''',
714
741
  )
715
742
 
@@ -720,11 +747,11 @@ def test_merge_2q_unitaries_to_circuit_op():
720
747
  cirq.testing.assert_has_diagram(
721
748
  c_orig,
722
749
  '''
723
- 0: ───H───@───@───H───@───X───────@───────X───X['ignore']───@───
724
- │ │ │ │
725
- 1: ───H───┼───X───────@───────Y───X───@───────Y─────────────X───
750
+ 0: ───H───@───@───H───@───X───────@───────X───X[ignore]───@───
751
+ │ │ │ │
752
+ 1: ───H───┼───X───────@───────Y───X───@───────Y───────────X───
726
753
  │ │
727
- 2: ───H───X───────────────────────────X─────────────────────M───
754
+ 2: ───H───X───────────────────────────X───────────────────M───
728
755
  ''',
729
756
  )
730
757
 
@@ -734,15 +761,15 @@ def test_merge_2q_unitaries_to_circuit_op():
734
761
  cirq.testing.assert_has_diagram(
735
762
  cirq.drop_empty_moments(c_new),
736
763
  '''
737
- [ 0: ───H───@─── ] [ 0: ───────@───H───@───X───@───X─── ]
738
- 0: ───[ │ ]─────────────[ │ │ │ ]────────────────────────────────────────────X['ignore']───@───
739
- [ 2: ───H───X─── ]['merged'] [ 1: ───H───X───────@───Y───X─────── ]['merged']
740
-
741
- [ 1: ───@───Y─── ]
742
- 1: ───┼──────────────────────────────#2─────────────────────────────────────────────────[ │ ]───────────────────────────X───
743
- [ 2: ───X─────── ]['merged']
744
-
745
- 2: ───#2────────────────────────────────────────────────────────────────────────────────#2───────────────────────────────────────────M───''',
764
+ [ 0: ───H───@─── ] [ 0: ───────@───H───@───X───@───X─── ]
765
+ 0: ───[ │ ]───────────[ │ │ │ ]────────────────────────────────────────X[ignore]───@───
766
+ [ 2: ───H───X─── ][merged] [ 1: ───H───X───────@───Y───X─────── ][merged]
767
+
768
+ [ 1: ───@───Y─── ]
769
+ 1: ───┼────────────────────────────#2───────────────────────────────────────────────[ │ ]───────────────────────X───
770
+ [ 2: ───X─────── ][merged]
771
+
772
+ 2: ───#2────────────────────────────────────────────────────────────────────────────#2───────────────────────────────────────M───''',
746
773
  )
747
774
 
748
775
 
@@ -165,13 +165,13 @@ class ClassicalDataDictionaryStore(ClassicalDataStore):
165
165
  if _channel_records is None:
166
166
  _channel_records = {}
167
167
  self._records: Dict['cirq.MeasurementKey', List[Tuple[int, ...]]] = _records
168
- self._measured_qubits: Dict[
169
- 'cirq.MeasurementKey', List[Tuple['cirq.Qid', ...]]
170
- ] = _measured_qubits
168
+ self._measured_qubits: Dict['cirq.MeasurementKey', List[Tuple['cirq.Qid', ...]]] = (
169
+ _measured_qubits
170
+ )
171
171
  self._channel_records: Dict['cirq.MeasurementKey', List[int]] = _channel_records
172
- self._measurement_types: Dict[
173
- 'cirq.MeasurementKey', 'cirq.MeasurementType'
174
- ] = _measurement_types
172
+ self._measurement_types: Dict['cirq.MeasurementKey', 'cirq.MeasurementType'] = (
173
+ _measurement_types
174
+ )
175
175
 
176
176
  @property
177
177
  def records(self) -> Mapping['cirq.MeasurementKey', List[Tuple[int, ...]]]:
@@ -70,6 +70,8 @@ class _SupportsValueEquality(Protocol):
70
70
 
71
71
 
72
72
  def _value_equality_eq(self: _SupportsValueEquality, other: _SupportsValueEquality) -> bool:
73
+ if other is self:
74
+ return True
73
75
  cls_self = self._value_equality_values_cls_()
74
76
  get_cls_other = getattr(other, '_value_equality_values_cls_', None)
75
77
  if get_cls_other is None:
@@ -91,6 +93,8 @@ def _value_equality_hash(self: _SupportsValueEquality) -> int:
91
93
  def _value_equality_approx_eq(
92
94
  self: _SupportsValueEquality, other: _SupportsValueEquality, atol: float
93
95
  ) -> bool:
96
+ if other is self:
97
+ return True
94
98
  cls_self = self._value_equality_values_cls_()
95
99
  get_cls_other = getattr(other, '_value_equality_values_cls_', None)
96
100
  if get_cls_other is None:
cirq/work/sampler.py CHANGED
@@ -294,10 +294,9 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
294
294
  See docs for `cirq.Sampler.run_batch`.
295
295
  """
296
296
  params_list, repetitions = self._normalize_batch_args(programs, params_list, repetitions)
297
- return [
298
- await self.run_sweep_async(circuit, params=params, repetitions=repetitions)
299
- for circuit, params, repetitions in zip(programs, params_list, repetitions)
300
- ]
297
+ return await duet.pstarmap_async(
298
+ self.run_sweep_async, zip(programs, params_list, repetitions)
299
+ )
301
300
 
302
301
  def _normalize_batch_args(
303
302
  self,
cirq/work/sampler_test.py CHANGED
@@ -211,6 +211,31 @@ def test_sampler_run_batch():
211
211
  assert np.array_equal(result.measurements['m'], np.array([[0], [0]], dtype='uint8'))
212
212
 
213
213
 
214
+ @duet.sync
215
+ async def test_run_batch_async_calls_run_sweep_asynchronously():
216
+ """Test run_batch_async calls run_sweep_async without waiting."""
217
+ finished = []
218
+ a = cirq.LineQubit(0)
219
+ circuit1 = cirq.Circuit(cirq.X(a) ** sympy.Symbol('t'), cirq.measure(a, key='m'))
220
+ circuit2 = cirq.Circuit(cirq.Y(a) ** sympy.Symbol('t'), cirq.measure(a, key='m'))
221
+ params1 = cirq.Points('t', [0.3, 0.7])
222
+ params2 = cirq.Points('t', [0.4, 0.6])
223
+ params_list = [params1, params2]
224
+
225
+ class AsyncSampler(cirq.Sampler):
226
+ async def run_sweep_async(self, program, params, repetitions: int = 1):
227
+ if params == params1:
228
+ await duet.sleep(0.001)
229
+
230
+ finished.append(params)
231
+
232
+ await AsyncSampler().run_batch_async(
233
+ [circuit1, circuit2], params_list=params_list, repetitions=[1, 2]
234
+ )
235
+
236
+ assert finished == list(reversed(params_list))
237
+
238
+
214
239
  def test_sampler_run_batch_default_params_and_repetitions():
215
240
  sampler = cirq.ZerosSampler()
216
241
  a = cirq.LineQubit(0)
@@ -1,36 +1,29 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cirq-core
3
- Version: 1.3.0.dev20231201141002
3
+ Version: 1.4.0
4
4
  Summary: A framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
5
5
  Home-page: http://github.com/quantumlib/cirq
6
6
  Author: The Cirq Developers
7
7
  Author-email: cirq-dev@googlegroups.com
8
8
  License: Apache 2
9
- Platform: UNKNOWN
10
- Requires-Python: >=3.9.0
9
+ Requires-Python: >=3.10.0
11
10
  License-File: LICENSE
12
- Requires-Dist: duet ~=0.2.8
11
+ Requires-Dist: attrs
12
+ Requires-Dist: duet >=0.2.8
13
13
  Requires-Dist: matplotlib ~=3.0
14
14
  Requires-Dist: networkx >=2.4
15
- Requires-Dist: numpy ~=1.16
15
+ Requires-Dist: numpy ~=1.22
16
16
  Requires-Dist: pandas
17
17
  Requires-Dist: sortedcontainers ~=2.0
18
- Requires-Dist: scipy
18
+ Requires-Dist: scipy ~=1.0
19
19
  Requires-Dist: sympy
20
20
  Requires-Dist: typing-extensions >=4.2
21
21
  Requires-Dist: tqdm
22
22
  Provides-Extra: contrib
23
23
  Requires-Dist: ply >=3.6 ; extra == 'contrib'
24
- Requires-Dist: pylatex ~=1.3.0 ; extra == 'contrib'
25
- Requires-Dist: quimb ; extra == 'contrib'
24
+ Requires-Dist: pylatex ~=1.4 ; extra == 'contrib'
25
+ Requires-Dist: quimb ~=1.7 ; extra == 'contrib'
26
26
  Requires-Dist: opt-einsum ; extra == 'contrib'
27
- Requires-Dist: autoray ; extra == 'contrib'
28
- Requires-Dist: numba >=0.53.0 ; extra == 'contrib'
29
-
30
- **This is a development version of Cirq-core and may be unstable.**
31
-
32
- **For the latest stable release of Cirq-core see**
33
- `here <https://pypi.org/project/cirq-core>`__.
34
27
 
35
28
  .. image:: https://raw.githubusercontent.com/quantumlib/Cirq/main/docs/images/Cirq_logo_color.png
36
29
  :target: https://github.com/quantumlib/cirq
@@ -47,8 +40,6 @@ Installation
47
40
  ------------
48
41
 
49
42
  To install the stable version of only **cirq-core**, use `pip install cirq-core`.
50
- To install the pre-release version of only **cirq-core**, use `pip install cirq-core --pre`.
51
-
52
- To get all the optional modules installed as well, you'll have to use `pip install cirq` or `pip install cirq --pre` for the pre-release version.
53
-
43
+ To install the pre-release version of only **cirq-core**, use `pip install cirq-core~=1.0.dev`.
54
44
 
45
+ To get all the optional modules installed as well, you'll have to use `pip install cirq` or `pip install cirq~=1.0.dev` for the pre-release version.