cirq-core 1.7.0.dev20250908175529__py3-none-any.whl → 1.7.0.dev20250911065641__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.dev20250908175529"
31
+ __version__ = "1.7.0.dev20250911065641"
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.dev20250908175529"
6
+ assert cirq.__version__ == "1.7.0.dev20250911065641"
@@ -48,6 +48,7 @@ class QasmLexer:
48
48
  'ID',
49
49
  'ARROW',
50
50
  'EQ',
51
+ 'AND',
51
52
  ] + list(reserved.values())
52
53
 
53
54
  def t_newline(self, t):
@@ -101,6 +102,10 @@ class QasmLexer:
101
102
  """=="""
102
103
  return t
103
104
 
105
+ def t_AND(self, t):
106
+ """&&"""
107
+ return t
108
+
104
109
  def t_ID(self, t):
105
110
  r"""[a-zA-Z_][a-zA-Z\d_]*"""
106
111
  if t.value in QasmLexer.reserved:
@@ -1100,19 +1100,34 @@ class QasmParser:
1100
1100
 
1101
1101
  p[0] = [ops.ResetChannel().on(qreg[i]) for i in range(len(qreg))]
1102
1102
 
1103
+ # condition list
1104
+ # condition_list : carg EQ NATURAL_NUMBER
1105
+ # | condition_list AND carg EQ NATURAL_NUMBER
1106
+
1107
+ def p_condition_list_single(self, p):
1108
+ """condition_list : carg EQ NATURAL_NUMBER"""
1109
+ p[0] = [(p[1], p[3])]
1110
+
1111
+ def p_condition_list_and(self, p):
1112
+ """condition_list : condition_list AND carg EQ NATURAL_NUMBER"""
1113
+ p[0] = p[1] + [(p[3], p[5])]
1114
+
1103
1115
  # if operations
1104
1116
  # if : IF '(' carg EQ NATURAL_NUMBER ')' ID qargs
1105
1117
 
1106
1118
  def p_if(self, p):
1107
- """if : IF '(' carg EQ NATURAL_NUMBER ')' gate_op"""
1108
- # We have to split the register into bits (since that's what measurement does above),
1109
- # and create one condition per bit, checking against that part of the binary value.
1119
+ """if : IF '(' condition_list ')' gate_op"""
1120
+ # For each condition, we have to split the register into bits (since that's what
1121
+ # measurement does above), and create one condition per bit, checking against that part of
1122
+ # the binary value.
1110
1123
  conditions = []
1111
- for i, key in enumerate(p[3]):
1112
- v = (p[5] >> i) & 1
1113
- conditions.append(sympy.Eq(sympy.Symbol(key), v))
1124
+ for cond in p[3]:
1125
+ carg, val = cond
1126
+ for i, key in enumerate(carg):
1127
+ v = (val >> i) & 1
1128
+ conditions.append(sympy.Eq(sympy.Symbol(key), v))
1114
1129
  p[0] = [
1115
- ops.ClassicallyControlledOperation(conditions=conditions, sub_operation=tuple(p[7])[0])
1130
+ ops.ClassicallyControlledOperation(conditions=conditions, sub_operation=tuple(p[5])[0])
1116
1131
  ]
1117
1132
 
1118
1133
  def p_gate_params_multiple(self, p):
@@ -294,12 +294,50 @@ def test_classical_control_multi_bit() -> None:
294
294
  ct.assert_same_circuits(parsed_qasm.circuit, expected_circuit)
295
295
  assert parsed_qasm.qregs == {'q': 2}
296
296
 
297
- # Note that this will *not* round-trip, but there's no good way around that due to the
298
- # difference in how Cirq and QASM do multi-bit measurements.
299
- with pytest.raises(ValueError, match='QASM does not support multiple conditions'):
297
+ # Note that this will *not* round-trip in QASM 2.0, but there's no good way around that due
298
+ # to the difference in how Cirq and QASM 2.0 do multi-bit measurements.
299
+ # Exporting multi-controlled operations in QASM 3.0 is supported with explicit '&&' between
300
+ # conditions.
301
+ with pytest.raises(
302
+ ValueError,
303
+ match='QASM 2.0 does not support multiple conditions. Consider exporting with QASM 3.0.',
304
+ ):
300
305
  _ = cirq.qasm(parsed_qasm.circuit)
301
306
 
302
307
 
308
+ def test_classical_control_multi_cond_and() -> None:
309
+ qasm = """OPENQASM 3.0;
310
+ include "stdgates.inc";
311
+ qubit[2] q;
312
+ bit[2] a;
313
+
314
+ a[0] = measure q[0];
315
+ a[1] = measure q[1];
316
+
317
+ if (a[0]==1 && a[1]==0) cx q[0],q[1];
318
+ """
319
+ parser = QasmParser()
320
+
321
+ q_0 = cirq.NamedQubit('q_0')
322
+ q_1 = cirq.NamedQubit('q_1')
323
+
324
+ # Expect two independent conditions: a_0 == 1 and a_1 == 0
325
+ expected_circuit = cirq.Circuit(
326
+ cirq.measure(q_0, key='a_0'),
327
+ cirq.measure(q_1, key='a_1'),
328
+ cirq.CNOT(q_0, q_1).with_classical_controls(
329
+ sympy.Eq(sympy.Symbol('a_0'), 1), sympy.Eq(sympy.Symbol('a_1'), 0)
330
+ ),
331
+ )
332
+
333
+ parsed_qasm = parser.parse(qasm)
334
+
335
+ assert parsed_qasm.supportedFormat
336
+
337
+ ct.assert_same_circuits(parsed_qasm.circuit, expected_circuit)
338
+ assert parsed_qasm.qregs == {'q': 2}
339
+
340
+
303
341
  def test_CX_gate_not_enough_args() -> None:
304
342
  qasm = """OPENQASM 2.0;
305
343
  qreg q[2];
@@ -234,9 +234,12 @@ class ClassicallyControlledOperation(raw_types.Operation):
234
234
 
235
235
  def _qasm_(self, args: cirq.QasmArgs) -> str | None:
236
236
  args.validate_version('2.0', '3.0')
237
- if len(self._conditions) > 1:
238
- raise ValueError('QASM does not support multiple conditions.')
237
+ if args.version == "2.0" and len(self._conditions) > 1:
238
+ raise ValueError(
239
+ 'QASM 2.0 does not support multiple conditions. Consider exporting with QASM 3.0.'
240
+ )
239
241
  subop_qasm = protocols.qasm(self._sub_operation, args=args)
240
242
  if not self._conditions:
241
243
  return subop_qasm
242
- return f'if ({protocols.qasm(self._conditions[0], args=args)}) {subop_qasm}'
244
+ condition_qasm = " && ".join(protocols.qasm(c, args=args) for c in self._conditions)
245
+ return f'if ({condition_qasm}) {subop_qasm}'
@@ -281,8 +281,32 @@ def test_qasm_multiple_conditions() -> None:
281
281
  sympy.Eq(sympy.Symbol('a'), 0), sympy.Eq(sympy.Symbol('b'), 0)
282
282
  ),
283
283
  )
284
- with pytest.raises(ValueError, match='QASM does not support multiple conditions'):
285
- _ = cirq.qasm(circuit)
284
+ with pytest.raises(
285
+ ValueError,
286
+ match='QASM 2.0 does not support multiple conditions. Consider exporting with QASM 3.0.',
287
+ ):
288
+ _ = cirq.qasm(circuit, args=cirq.QasmArgs(version='2.0'))
289
+
290
+ qasm = cirq.qasm(circuit, args=cirq.QasmArgs(version='3.0'))
291
+ assert (
292
+ qasm
293
+ == f"""// Generated from Cirq v{cirq.__version__}
294
+
295
+ OPENQASM 3.0;
296
+ include "stdgates.inc";
297
+
298
+
299
+ // Qubits: [q(0), q(1)]
300
+ qubit[2] q;
301
+ bit[1] m_a;
302
+ bit[1] m_b;
303
+
304
+
305
+ m_a[0] = measure q[0];
306
+ m_b[0] = measure q[0];
307
+ if (m_a==0 && m_b==0) x q[1];
308
+ """
309
+ )
286
310
 
287
311
 
288
312
  @pytest.mark.parametrize('sim', ALL_SIMULATORS)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cirq-core
3
- Version: 1.7.0.dev20250908175529
3
+ Version: 1.7.0.dev20250911065641
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=peD3jdd4i1zz-kBXjyBiWStm84FTXi0JoeG5K60G1Os,1206
8
- cirq/_version_test.py,sha256=irjfu-J0IKWfdEDgUtT48B73Y-gKsscTkP7J1vN8c0c,155
7
+ cirq/_version.py,sha256=Go2wwqS6uXaLb2-LFRp-MU91zKOL-ZjCGSkbI9Xout4,1206
8
+ cirq/_version_test.py,sha256=yoE7HlOdIzRCj0UO0qpo7Baaws-kh1jAkELb0op1LVc,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
@@ -117,10 +117,10 @@ cirq/contrib/paulistring/recombine_test.py,sha256=ydCc2JxmmjZ8TR-Ojyy5lIRed_P-n6
117
117
  cirq/contrib/paulistring/separate.py,sha256=h3UHkJp2dAQn9wrW57Z2s6GvfnPZwRMzTHULoyJVfkw,3955
118
118
  cirq/contrib/paulistring/separate_test.py,sha256=mp_ixjxS9-YypnJkgApFzSV0QGJt0SDG23S34Ni57QY,1311
119
119
  cirq/contrib/qasm_import/__init__.py,sha256=RKX0vGDC2Pe5rH5rM4ClXdvtrAU16ePFImQpiJtJVNo,744
120
- cirq/contrib/qasm_import/_lexer.py,sha256=myIldLE-8oBr6QdHbHk0_Ub1CuORbhU53vsGg04K1iw,2935
120
+ cirq/contrib/qasm_import/_lexer.py,sha256=dG91z4Nsl3uXKjwXoYNnLEQhHovz7QNu49jBXJBt7Rk,3009
121
121
  cirq/contrib/qasm_import/_lexer_test.py,sha256=yaWshvgmwXNHPM6Gy01IPdv_baksSN5FGk1J6fhloRU,7341
122
- cirq/contrib/qasm_import/_parser.py,sha256=7mh7PB4ngub1K48RWulJ0adWx--LdkFKLBh7j6rhyEg,43526
123
- cirq/contrib/qasm_import/_parser_test.py,sha256=V96NsSVVAmDqFNz36KCzk0bAJg2UbBZOwIsWJnYpGaA,67648
122
+ cirq/contrib/qasm_import/_parser.py,sha256=Q-OlSaaf0ORGhUMJmMRP_h5lRiyKZrWgMn1_hxJ8gjo,44024
123
+ cirq/contrib/qasm_import/_parser_test.py,sha256=lhBVVkx8Yt5iqwvmgWR1XRKXdxCRiEMFrh-sEtJqlX0,68713
124
124
  cirq/contrib/qasm_import/exception.py,sha256=DdqXaHmZU1TaxaHqXW23yp9bqXxdxqkq4tErGd9VHj8,731
125
125
  cirq/contrib/qasm_import/qasm.py,sha256=k_uX-ITaxHRcrP87kuUNgudloG_ns0HURJLoyq4scqU,989
126
126
  cirq/contrib/qasm_import/qasm_test.py,sha256=mwgl7dIOt50hvxTVTiy1HpVxAjyBSb59R3_Hi-5LUIU,1906
@@ -287,8 +287,8 @@ cirq/ops/arithmetic_operation.py,sha256=cokwokyzKa3zJkyxopP81fTRMutHfI277ZObKw9E
287
287
  cirq/ops/arithmetic_operation_test.py,sha256=F5fPQF_sRWi8qyP_SgDzJ8kfX0jUVMj59_VOPpbXH_0,4938
288
288
  cirq/ops/boolean_hamiltonian.py,sha256=x25fraM9NNs-XzDKDl2AZ1AMpkVovfe-dNm_0wOolyI,14927
289
289
  cirq/ops/boolean_hamiltonian_test.py,sha256=_4mFFrbO9C21oZYutr_pl01_bqDDxvgY_h4DWKGkse0,8630
290
- cirq/ops/classically_controlled_operation.py,sha256=Oro9yC5-2p7_O5IpHz-qHAmnry79qOfiRL-BKmVbnpQ,10290
291
- cirq/ops/classically_controlled_operation_test.py,sha256=OedFFoAwS4WnHKG58xgjhbKFgKebhYyP8I7AU4a0m9k,50425
290
+ cirq/ops/classically_controlled_operation.py,sha256=EjhW86dz6d6EwEupM6Rb9MWedb6nRusLOlaaFudEVbk,10445
291
+ cirq/ops/classically_controlled_operation_test.py,sha256=-LDfOotkjxdXJXACVoteWkgmyaTuCcmV4Vy3DHZaWvY,50861
292
292
  cirq/ops/clifford_gate.py,sha256=F4RiKZcf8PT1oUR0PfXPrIgDUcr9FJkwppPW39dpM2M,40078
293
293
  cirq/ops/clifford_gate_test.py,sha256=nuIGDqc7AWf5KJY3JJSe4mt8egLlcyuf5oorX_aBdsU,41268
294
294
  cirq/ops/common_channels.py,sha256=ZZa2JCyPtrKfGhcAGCUUzA4qym8S9isKs-xs-TEkhKs,37022
@@ -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.dev20250908175529.dist-info/licenses/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1238
- cirq_core-1.7.0.dev20250908175529.dist-info/METADATA,sha256=fXvmqayZ0OHs9WbYqQ-ujSuM3BgFtd91eDyQEKUEHCY,4758
1239
- cirq_core-1.7.0.dev20250908175529.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
1240
- cirq_core-1.7.0.dev20250908175529.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1241
- cirq_core-1.7.0.dev20250908175529.dist-info/RECORD,,
1237
+ cirq_core-1.7.0.dev20250911065641.dist-info/licenses/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1238
+ cirq_core-1.7.0.dev20250911065641.dist-info/METADATA,sha256=Q3XoM__mKjWrpwbt7HxfpuE92Ou3ZRczDtgV5v2zRBs,4758
1239
+ cirq_core-1.7.0.dev20250911065641.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
1240
+ cirq_core-1.7.0.dev20250911065641.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1241
+ cirq_core-1.7.0.dev20250911065641.dist-info/RECORD,,