cirq-core 1.7.0.dev20250725224902__py3-none-any.whl → 1.7.0.dev20250731033642__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.

Potentially problematic release.


This version of cirq-core might be problematic. Click here for more details.

cirq/_version.py CHANGED
@@ -28,4 +28,4 @@ if sys.version_info < (3, 11, 0): # pragma: no cover
28
28
  'of Cirq (e.g. "python -m pip install cirq==1.5.0")'
29
29
  )
30
30
 
31
- __version__ = "1.7.0.dev20250725224902"
31
+ __version__ = "1.7.0.dev20250731033642"
cirq/_version_test.py CHANGED
@@ -3,4 +3,4 @@ import cirq
3
3
 
4
4
 
5
5
  def test_version() -> None:
6
- assert cirq.__version__ == "1.7.0.dev20250725224902"
6
+ assert cirq.__version__ == "1.7.0.dev20250731033642"
cirq/ops/fsim_gate.py CHANGED
@@ -350,7 +350,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
350
350
 
351
351
  @staticmethod
352
352
  def from_matrix(u: np.ndarray) -> PhasedFSimGate | None:
353
- """Contruct a PhasedFSimGate from unitary.
353
+ """Constructs a PhasedFSimGate from unitary.
354
354
 
355
355
  Args:
356
356
  u: A unitary matrix representing a PhasedFSimGate.
@@ -149,26 +149,6 @@ def _merge_single_qubit_ops_to_phxz(
149
149
  return gate.on(q)
150
150
 
151
151
 
152
- def _try_merge_single_qubit_ops_of_two_moments(m1: Moment, m2: Moment) -> tuple[Moment, ...]:
153
- """Merge single qubit ops of 2 moments if possible, returns 2 moments otherwise."""
154
- for q in m1.qubits & m2.qubits:
155
- op1 = m1.operation_at(q)
156
- op2 = m2.operation_at(q)
157
- if any(
158
- not (_is_single_qubit_operation(op) and has_unitary(op))
159
- for op in [op1, op2]
160
- if op is not None
161
- ):
162
- return (m1, m2)
163
- merged_ops: set[ops.Operation] = set()
164
- # Merge all operators on q to a single op.
165
- for q in m1.qubits | m2.qubits:
166
- # ops_on_q may contain 1 op or 2 ops.
167
- ops_on_q = [op for op in [m.operation_at(q) for m in [m1, m2]] if op is not None]
168
- merged_ops.add(_merge_single_qubit_ops_to_phxz(q, tuple(ops_on_q)))
169
- return (Moment(merged_ops),)
170
-
171
-
172
152
  def _calc_pulled_through(moment: Moment, input_pauli_ops: ops.PauliString) -> ops.PauliString:
173
153
  """Calculates the pulled_through such that circuit(input_pauli_ops, moment.clifford_ops) is
174
154
  equivalent to circuit(moment.clifford_ops, pulled_through).
@@ -251,7 +231,7 @@ def add_dynamical_decoupling(
251
231
  # (pulled_through, moment) -> (new_moment, updated_moment, updated_pulled_through)
252
232
  # Moments structure changes are split into 3 steps:
253
233
  # 1, (..., last_moment, pulled_through1, moment, ...)
254
- # -> (..., try_merge(last_moment, new_moment or None), pulled_through2, moment, ...)
234
+ # -> (..., last_moment, new_moment or None, pulled_through2, moment, ...)
255
235
  # 2, (..., pulled_through2, moment, ...) -> (..., pulled_through3, updated_moment, ...)
256
236
  # 3, (..., pulled_through3, updated_moment, ...)
257
237
  # -> (..., updated_moment, pulled_through4, ...)
@@ -261,7 +241,7 @@ def add_dynamical_decoupling(
261
241
  # unitary representation (e.g., measure gates). If there are remaining pulled through ops,
262
242
  # insert into a new moment before current moment.
263
243
  stop_pulling_through_qubits: set[ops.Qid] = _get_stop_qubits(moment)
264
- new_moment_ops = []
244
+ new_moment_ops: list[ops.Operation] = []
265
245
  for q in stop_pulling_through_qubits:
266
246
  # Insert the remaining pulled_through
267
247
  remaining_pulled_through_gate = pulled_through.get(q)
@@ -271,24 +251,11 @@ def add_dynamical_decoupling(
271
251
  dd_iter_by_qubits[q] = cycle(base_dd_sequence)
272
252
  # Need to insert a new moment before current moment
273
253
  if new_moment_ops:
274
- moments_to_be_appended = _try_merge_single_qubit_ops_of_two_moments(
275
- transformed_moments[-1], Moment(new_moment_ops)
276
- )
277
- if len(moments_to_be_appended) == 1:
278
- transformed_moments.pop()
279
- transformed_moments.append(moments_to_be_appended[0])
280
- else: # Fill insertable idle moments in the new moment using dd sequence
281
- for q in orig_circuit.all_qubits() - stop_pulling_through_qubits:
282
- if (
283
- busy_moment_range_by_qubit[q][0]
284
- < moment_id
285
- <= busy_moment_range_by_qubit[q][1]
286
- ):
287
- new_moment_ops.append(_update_pulled_through(q, next(dd_iter_by_qubits[q])))
288
- moments_to_be_appended = _try_merge_single_qubit_ops_of_two_moments(
289
- transformed_moments.pop(), Moment(new_moment_ops)
290
- )
291
- transformed_moments.extend(moments_to_be_appended)
254
+ # Fill insertable idle moments in the new moment using dd sequence
255
+ for q in orig_circuit.all_qubits() - stop_pulling_through_qubits:
256
+ if busy_moment_range_by_qubit[q][0] < moment_id <= busy_moment_range_by_qubit[q][1]:
257
+ new_moment_ops.append(_update_pulled_through(q, next(dd_iter_by_qubits[q])))
258
+ transformed_moments.append(Moment(new_moment_ops))
292
259
 
293
260
  # Step 2, calc updated_moment with insertions / merges.
294
261
  updated_moment_ops: set[cirq.Operation] = set()
@@ -332,10 +299,6 @@ def add_dynamical_decoupling(
332
299
  for affected_q, combined_op_in_pauli in pulled_through.items():
333
300
  ending_moment_ops.append(combined_op_in_pauli.on(affected_q))
334
301
  if ending_moment_ops:
335
- transformed_moments.extend(
336
- _try_merge_single_qubit_ops_of_two_moments(
337
- transformed_moments.pop(), Moment(ending_moment_ops)
338
- )
339
- )
302
+ transformed_moments.append(Moment(ending_moment_ops))
340
303
 
341
304
  return Circuit.from_moments(*transformed_moments)
@@ -533,9 +533,9 @@ def test_multiple_clifford_pieces_case1():
533
533
 
534
534
  b: ───H───H───H───H───@^0.5───H───H───H───H───
535
535
  Output:
536
- a: ───H───X───H───PhXZ(a=0.5,x=0,z=-1)───@───────X───H───X───PhXZ(a=0.5,x=0.5,z=-1)───
537
-
538
- b: ───H───H───H───H──────────────────────@^0.5───H───H───H───H────────────────────────
536
+ a: ───H───X───H───X───Y───@───────X───H───X───PhXZ(a=0.5,x=0.5,z=-1)───
537
+
538
+ b: ───H───H───H───H───────@^0.5───H───H───H───H────────────────────────
539
539
  """
540
540
  a = cirq.NamedQubit('a')
541
541
  b = cirq.NamedQubit('b')
@@ -551,22 +551,11 @@ def test_multiple_clifford_pieces_case1():
551
551
  cirq.Moment(H(b)),
552
552
  cirq.Moment(H(a), H(b)),
553
553
  ),
554
- expected_circuit=cirq.Circuit(
555
- cirq.Moment(H(a), H(b)),
556
- cirq.Moment(H(b), X(a)),
557
- cirq.Moment(H(a), H(b)),
558
- cirq.Moment(
559
- H(b), cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0, z_exponent=-1).on(a)
560
- ),
561
- cirq.Moment(CZPowGate(exponent=0.5).on(a, b)),
562
- cirq.Moment(H(b), X(a)),
563
- cirq.Moment(H(a), H(b)),
564
- cirq.Moment(H(b), X(a)),
565
- cirq.Moment(
566
- H(b),
567
- cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0.5, z_exponent=-1).on(a),
568
- ),
569
- ),
554
+ expected_circuit="""
555
+ a: ───H───X───H───X───Y───@───────X───H───X───PhXZ(a=0.5,x=0.5,z=-1)───
556
+
557
+ b: ───H───H───H───H───────@^0.5───H───H───H───H────────────────────────
558
+ """,
570
559
  schema="XX_PAIR",
571
560
  )
572
561
 
@@ -658,14 +647,6 @@ def test_with_non_clifford_measurements():
658
647
  2: ───H───@───H───@───────M───
659
648
 
660
649
  3: ───────────H───@───H───M───
661
- Output:
662
- 0: ───────────H───@───PhXZ(a=0.5,x=0.5,z=0)───M───
663
-
664
- 1: ───H───@───X───@───X───────────────────────M───
665
-
666
- 2: ───H───@───H───@───I───────────────────────M───
667
-
668
- 3: ───────────H───@───H───────────────────────M───
669
650
  """
670
651
  qubits = cirq.LineQubit.range(4)
671
652
  assert_dd(
@@ -677,21 +658,15 @@ def test_with_non_clifford_measurements():
677
658
  cirq.Moment([H(qubits[i]) for i in [0, 3]]),
678
659
  cirq.Moment([cirq.M(qubits[i]) for i in [0, 1, 2, 3]]),
679
660
  ),
680
- expected_circuit=cirq.Circuit(
681
- cirq.Moment([H(qubits[i]) for i in [1, 2]]),
682
- cirq.Moment(CZ(*qubits[1:3])),
683
- cirq.Moment([H(qubits[i]) for i in [0, 2, 3]] + [X(qubits[1])]),
684
- cirq.Moment(CZ(*qubits[0:2]), CZ(*qubits[2:])),
685
- cirq.Moment(
686
- H(qubits[3]),
687
- cirq.I(qubits[2]),
688
- X(qubits[1]),
689
- cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0.5, z_exponent=0).on(
690
- qubits[0]
691
- ),
692
- ),
693
- cirq.Moment([cirq.M(qubits[i]) for i in [0, 1, 2, 3]]),
694
- ),
661
+ expected_circuit="""
662
+ 0: ───────────H───@───H───X───M───
663
+
664
+ 1: ───H───@───X───@───X───────M───
665
+
666
+ 2: ───H───@───H───@───X───X───M───
667
+
668
+ 3: ───────────H───@───H───────M───
669
+ """,
695
670
  schema="XX_PAIR",
696
671
  single_qubit_gate_moments_only=True,
697
672
  )
@@ -844,11 +819,58 @@ def test_merge_before_non_cliffords():
844
819
  assert_dd(
845
820
  input_circuit=input_circuit,
846
821
  expected_circuit="""
847
- 0: ───X───X───X──────────────────────────────────────────M───
822
+ 0: ───X───X───X───────────────────────X──────────────────────X───M───
848
823
 
849
- 1: ───X───X───PhXZ(a=-1.25,x=1,z=0)───FSim(0, 0.0637π)───M───
850
-
851
- 2: ───X───X───S───────────────────────FSim(0, 0.0637π)───M───
824
+ 1: ───X───X───PhXZ(a=-1,x=0,z=-0.5)───Y───FSim(0, 0.0637π)───────M───
825
+
826
+ 2: ───X───X───S───────────────────────────FSim(0, 0.0637π)───────M───
852
827
  """,
853
828
  schema="XX_PAIR",
854
829
  )
830
+
831
+
832
+ @pytest.mark.parametrize(
833
+ 'single_qubit_gate_moments_only, expected_diagram',
834
+ [
835
+ (
836
+ True,
837
+ # With single_qubit_gate_moments_only=True, the second DD gate on q2
838
+ # is inserted in a new moment after the CZ gate.
839
+ """
840
+ 0: ───X───X───@───────M───
841
+
842
+ 1: ───X───X───@───────M───
843
+
844
+ 2: ───X───X───────X───M───
845
+ """,
846
+ ),
847
+ (
848
+ False,
849
+ # With single_qubit_gate_moments_only=False, the second DD gate on q2
850
+ # is inserted in the same moment as the CZ gate.
851
+ """
852
+ 0: ───X───X───@───M───
853
+
854
+ 1: ───X───X───@───M───
855
+
856
+ 2: ───X───X───X───M───
857
+ """,
858
+ ),
859
+ ],
860
+ )
861
+ def test_single_qubit_gate_moments_only_true_vs_false(
862
+ single_qubit_gate_moments_only, expected_diagram
863
+ ):
864
+ q0, q1, q2 = cirq.LineQubit.range(3)
865
+ input_circuit = cirq.Circuit(
866
+ cirq.Moment([X(q) for q in [q0, q1, q2]]),
867
+ cirq.Moment([X(q) for q in [q0, q1]]),
868
+ cirq.Moment(CZ(q0, q1)),
869
+ cirq.Moment([cirq.M(q) for q in [q0, q1, q2]]),
870
+ )
871
+ assert_dd(
872
+ input_circuit=input_circuit,
873
+ expected_circuit=expected_diagram,
874
+ schema="XX_PAIR",
875
+ single_qubit_gate_moments_only=single_qubit_gate_moments_only,
876
+ )
cirq/value/condition.py CHANGED
@@ -154,7 +154,7 @@ class BitMaskKeyCondition(Condition):
154
154
  - BitMaskKeyCondition.create_not_equal_mask('a', 13) -> (a & 13) != 13
155
155
 
156
156
  The bits in the bitmask have the same order as the qubits passed to `cirq.measure(...)`. That's
157
- the most significant bit corresponds to the the first (left most) qubit.
157
+ the most significant bit corresponds to the first (left most) qubit.
158
158
 
159
159
  Attributes:
160
160
  - key: Measurement key.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cirq-core
3
- Version: 1.7.0.dev20250725224902
3
+ Version: 1.7.0.dev20250731033642
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
@@ -4,8 +4,8 @@ cirq/_compat_test.py,sha256=emXpdD5ZvwLRlFAoQB8YatmZyU3b4e9jg6FppMTUhkU,33900
4
4
  cirq/_doc.py,sha256=BrnoABo1hk5RgB3Cgww4zLHUfiyFny0F1V-tOMCbdaU,2909
5
5
  cirq/_import.py,sha256=ixBu4EyGl46Ram2cP3p5eZVEFDW5L2DS-VyTjz4N9iw,8429
6
6
  cirq/_import_test.py,sha256=oF4izzOVZLc7NZ0aZHFcGv-r01eiFFt_JORx_x7_D4s,1089
7
- cirq/_version.py,sha256=r2eDmtAP2xJC2APkN6aWn6RnWNOsjA2XcuXUC7X1yOg,1206
8
- cirq/_version_test.py,sha256=-vnO8SJPG1hypDpea4Knu5oCTIqBChxjPoSOEnnJaGY,155
7
+ cirq/_version.py,sha256=KShezFCx52rfaMrHCedcLGxJCNfMrY-BiWuz3gtOxWQ,1206
8
+ cirq/_version_test.py,sha256=q4e0Zl2TyYgZdF0zJR56Q9wuQDRxPMCI-JMyAao14k8,155
9
9
  cirq/conftest.py,sha256=wSDKNdIQRDfLnXvOCWD3erheOw8JHRhdfQ53EyTUIXg,1239
10
10
  cirq/json_resolver_cache.py,sha256=A5DIgFAY1hUNt9vai_C3-gGBv24116CJMzQxMcXOax4,13726
11
11
  cirq/py.typed,sha256=VFSlmh_lNwnaXzwY-ZuW-C2Ws5PkuDoVgBdNCs0jXJE,63
@@ -311,7 +311,7 @@ cirq/ops/eigen_gate.py,sha256=OoUpOwHw6VZ2CpH0Qb-eQLD4c-cjj8wFwBr8NEc7C0g,17788
311
311
  cirq/ops/eigen_gate_test.py,sha256=3ZN7texyQ_svk8YAaH3liZiGAgq_SBpNb46nIzKYfWM,16909
312
312
  cirq/ops/fourier_transform.py,sha256=JMledJB0tPjLlIlG9bfapJSqass94rXkAheXragQxq8,7455
313
313
  cirq/ops/fourier_transform_test.py,sha256=sX5TfZd9-n1WTyZcqOQ0x6yyI8k6rasywijMo3bc1ls,6426
314
- cirq/ops/fsim_gate.py,sha256=xsk5xfEaUTcGeGV852KTuoE7mxlCHEXg2HZlyiszkd0,20035
314
+ cirq/ops/fsim_gate.py,sha256=Qs7FLsNXR7K2jNVZ8I9o9YLvOb6cC6iBnAvZAHERNk0,20037
315
315
  cirq/ops/fsim_gate_test.py,sha256=QgckC2fij30grZJoO6HnQHdGkKcwtiegedEBRid3wF0,25858
316
316
  cirq/ops/gate_features.py,sha256=OfjsIGftnGpNUDAYwSP4obG0FsMrHYfp49ZOjbvbmNE,1085
317
317
  cirq/ops/gate_features_test.py,sha256=JYPunTBr48CQoIOB1wk2QEdPwtnmE-FxUoF6a4ZeRB8,2407
@@ -1071,8 +1071,8 @@ cirq/transformers/drop_empty_moments.py,sha256=uZJG9FpUNyA1Mi0xLDuVuhj_siZhPZ1_s
1071
1071
  cirq/transformers/drop_empty_moments_test.py,sha256=h6Pji0z0o9KOB7fnSHseWpIAhzvxWurF_flg9XWm_YI,1959
1072
1072
  cirq/transformers/drop_negligible_operations.py,sha256=eP2dP_n0BYlr8aZ1wnD8YWsqCtwN0l0O6p45RbXEpfM,2097
1073
1073
  cirq/transformers/drop_negligible_operations_test.py,sha256=32mS4QQ8tiH3wBAAgbUU8LgwWDmvreRVEDZML_kgxyo,3859
1074
- cirq/transformers/dynamical_decoupling.py,sha256=nVYH0vNIflfnB-gp8awMb0xv8lo_FYkeMJNBoBtCUQg,15053
1075
- cirq/transformers/dynamical_decoupling_test.py,sha256=UXYBxc_8lnq-pqMBgj5qhPEXnYv6bccMjiIBtEMTGTQ,44728
1074
+ cirq/transformers/dynamical_decoupling.py,sha256=LP0Hrp7XqfVRmSy_wQX85GKPgK1Vy2_HCt8OyySFL2s,13484
1075
+ cirq/transformers/dynamical_decoupling_test.py,sha256=wQUCw99ODghLmluox9-3rg-w_A1vEVa96dFmKXWC2m0,45171
1076
1076
  cirq/transformers/eject_phased_paulis.py,sha256=ZeVEh614OihWZtHyaBBtgpWj_dUxQGXDzf4NmBlzbeM,14725
1077
1077
  cirq/transformers/eject_phased_paulis_test.py,sha256=AOMmOq3fWFGm2_qDyocjtF9fK7GAhC0kF550mkjtPx4,15791
1078
1078
  cirq/transformers/eject_z.py,sha256=3u0Q0WGGAxmZuPnyiU4q04gJMnY--0nvhF4eotnSl9k,5803
@@ -1181,7 +1181,7 @@ cirq/value/angle.py,sha256=6YP1RWv8IrruvgxvqlCYxcabYRE8bXrbV_Jx66Jfuvs,3285
1181
1181
  cirq/value/angle_test.py,sha256=jKLd1hkY-Tb22krD-WkJjfqFy9EJIIZCAL57__FgW_c,3608
1182
1182
  cirq/value/classical_data.py,sha256=mPkDGZb4I0a1qSgY-T01NLzkJSgSpKpU_o_EQQEn3mc,11517
1183
1183
  cirq/value/classical_data_test.py,sha256=q1QMT17E-X9kcaPw1oQqx3Hwnq3hyht24HaK3z7Udpo,5332
1184
- cirq/value/condition.py,sha256=sl2ol2vyVIQba3YQVXqVI_IgglFMGcDlw7vrCjo9wFk,11920
1184
+ cirq/value/condition.py,sha256=lJJcFiqG-r68DhhS01DS6HhQw0pDwbNq71bvH1Famec,11916
1185
1185
  cirq/value/condition_test.py,sha256=oEdim5nOYYY8UPU91H2xhb9MH8EC2WbMXTQ_DruHVO0,12949
1186
1186
  cirq/value/digits.py,sha256=-3HTHqEQqy5evUz8aLE6ruw0NV3ncuPrc5asRMQ-sQ4,6063
1187
1187
  cirq/value/digits_test.py,sha256=WDeUQTnDqZXh4JjWu_qEkzCFAtd8x1UlN9I2yjdDV3g,3848
@@ -1234,8 +1234,8 @@ cirq/work/sampler.py,sha256=rxbMWvrhu3gfNSBjZKozw28lLKVvBAS_1EGyPdYe8Xg,19041
1234
1234
  cirq/work/sampler_test.py,sha256=SsMrRvLDYELyOAWLKISjkdEfrBwLYWRsT6D8WrsLM3Q,13533
1235
1235
  cirq/work/zeros_sampler.py,sha256=Fs2JWwq0n9zv7_G5Rm-9vPeHUag7uctcMOHg0JTkZpc,2371
1236
1236
  cirq/work/zeros_sampler_test.py,sha256=lQLgQDGBLtfImryys2HzQ2jOSGxHgc7-koVBUhv8qYk,3345
1237
- cirq_core-1.7.0.dev20250725224902.dist-info/licenses/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1238
- cirq_core-1.7.0.dev20250725224902.dist-info/METADATA,sha256=pjLVRz2hk-OGPcFaUZk9Dtmb0_WK2zbygv9eb3i1MI0,4857
1239
- cirq_core-1.7.0.dev20250725224902.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
1240
- cirq_core-1.7.0.dev20250725224902.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1241
- cirq_core-1.7.0.dev20250725224902.dist-info/RECORD,,
1237
+ cirq_core-1.7.0.dev20250731033642.dist-info/licenses/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1238
+ cirq_core-1.7.0.dev20250731033642.dist-info/METADATA,sha256=MabVVhwl7jA51FJZwTWLOehQ3NfI7PP9Zh8iv6NngkQ,4857
1239
+ cirq_core-1.7.0.dev20250731033642.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
1240
+ cirq_core-1.7.0.dev20250731033642.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1241
+ cirq_core-1.7.0.dev20250731033642.dist-info/RECORD,,