cirq-core 1.4.0.dev20240315194126__py3-none-any.whl → 1.4.0.dev20240318170608__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/__init__.py CHANGED
@@ -240,6 +240,7 @@ from cirq.ops import (
240
240
  MatrixGate,
241
241
  MixedUnitaryChannel,
242
242
  M,
243
+ MSGate,
243
244
  measure,
244
245
  measure_each,
245
246
  measure_paulistring_terms,
cirq/_version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "1.4.0.dev20240315194126"
1
+ __version__ = "1.4.0.dev20240318170608"
@@ -157,6 +157,7 @@ def _class_resolver_dictionary() -> Dict[str, ObjectFactory]:
157
157
  'LineTopology': cirq.LineTopology,
158
158
  'Linspace': cirq.Linspace,
159
159
  'ListSweep': cirq.ListSweep,
160
+ 'cirq.MSGate': cirq.MSGate,
160
161
  'MatrixGate': cirq.MatrixGate,
161
162
  'MixedUnitaryChannel': cirq.MixedUnitaryChannel,
162
163
  'MeasurementKey': cirq.MeasurementKey,
cirq/ops/parity_gates.py CHANGED
@@ -399,6 +399,11 @@ class MSGate(XXPowGate):
399
399
  return 'cirq.ms(np.pi/2)'
400
400
  return f'cirq.ms({self._exponent!r}*np.pi/2)'
401
401
 
402
+ # the default namespace is already occupied by cirq_ionq.MSGate
403
+ @classmethod
404
+ def _json_namespace_(cls) -> str:
405
+ return 'cirq'
406
+
402
407
  def _json_dict_(self) -> Dict[str, Any]:
403
408
  return protocols.obj_to_dict_helper(self, ["rads"])
404
409
 
@@ -258,7 +258,7 @@ def test_trace_distance():
258
258
  def test_ms_arguments():
259
259
  eq_tester = cirq.testing.EqualsTester()
260
260
  eq_tester.add_equality_group(
261
- cirq.ms(np.pi / 2), cirq.ops.MSGate(rads=np.pi / 2), cirq.XXPowGate(global_shift=-0.5)
261
+ cirq.ms(np.pi / 2), cirq.MSGate(rads=np.pi / 2), cirq.XXPowGate(global_shift=-0.5)
262
262
  )
263
263
  eq_tester.add_equality_group(
264
264
  cirq.ms(np.pi / 4), cirq.XXPowGate(exponent=0.5, global_shift=-0.5)
@@ -323,15 +323,7 @@ b: ───×───────────MS(π)───
323
323
 
324
324
 
325
325
  def test_json_serialization():
326
- def custom_resolver(cirq_type: str):
327
- if cirq_type == "MSGate":
328
- return cirq.ops.MSGate
329
- return None
330
-
331
- assert cirq.read_json(
332
- json_text=cirq.to_json(cirq.ms(np.pi / 2)), resolvers=[custom_resolver]
333
- ) == cirq.ms(np.pi / 2)
334
- assert custom_resolver('X') is None
326
+ assert cirq.read_json(json_text=cirq.to_json(cirq.ms(np.pi / 2))) == cirq.ms(np.pi / 2)
335
327
 
336
328
 
337
329
  @pytest.mark.parametrize('gate_cls', (cirq.XXPowGate, cirq.YYPowGate, cirq.ZZPowGate))
@@ -0,0 +1,4 @@
1
+ {
2
+ "cirq_type": "cirq.MSGate",
3
+ "rads": 1.5707963267948966
4
+ }
@@ -0,0 +1 @@
1
+ cirq.ms(np.pi/2)
@@ -22,6 +22,7 @@ TestSpec = ModuleJsonTestSpec(
22
22
  name="cirq",
23
23
  packages=[cirq, cirq.work],
24
24
  test_data_path=pathlib.Path(__file__).parent,
25
+ custom_class_name_to_cirq_type={"MSGate": "cirq.MSGate"},
25
26
  resolver_cache=_class_resolver_dictionary(),
26
27
  not_yet_serializable=[
27
28
  'Alignment',
@@ -53,12 +53,9 @@ def _to_target_circuit_type(
53
53
 
54
54
 
55
55
  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
- )
56
+ if isinstance(target_circuit, circuits.FrozenCircuit):
57
+ return cast(CIRCUIT_TYPE, circuits.FrozenCircuit(ops).with_tags(*target_circuit.tags))
58
+ return cast(CIRCUIT_TYPE, circuits.Circuit(ops))
62
59
 
63
60
 
64
61
  def map_moments(
@@ -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))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cirq-core
3
- Version: 1.4.0.dev20240315194126
3
+ Version: 1.4.0.dev20240318170608
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
@@ -1,13 +1,13 @@
1
- cirq/__init__.py,sha256=GlOnPWDvat-Y203LsbXhkC0UnGm9HHiNx2ywz7Bkc3o,15708
1
+ cirq/__init__.py,sha256=-me8ux2uyeDMA9bO17djZH-SbpSKixOsfrvotuAJRc8,15720
2
2
  cirq/_compat.py,sha256=ogNbww9v943-ZNZcOx-ad8kGO8-jLBuS8865gQ3QA-c,29350
3
3
  cirq/_compat_test.py,sha256=Qq3ZcfgD-Nb81cEppQdJqhAyrVqXKtfXZYGXT0p-Wh0,34718
4
4
  cirq/_doc.py,sha256=yDyWUD_2JDS0gShfGRb-rdqRt9-WeL7DhkqX7np0Nko,2879
5
5
  cirq/_import.py,sha256=p9gMHJscbtDDkfHOaulvd3Aer0pwUF5AXpL89XR8dNw,8402
6
6
  cirq/_import_test.py,sha256=6K_v0riZJXOXUphHNkGA8MY-JcmGlezFaGmvrNhm3OQ,1015
7
- cirq/_version.py,sha256=auc4QKfVzWFRmDVThWti8Hf0H_zuSGJSfqWNiM6g3HU,40
7
+ cirq/_version.py,sha256=IP9DCUnAKpWQbKEXBra8_ck6RKP0bPH7OII1n5QGDL8,40
8
8
  cirq/_version_test.py,sha256=yYS6xm5-nuBRQJa9R3n41WdvFtVyY7Lb5Q8bea3VgBI,133
9
9
  cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
10
- cirq/json_resolver_cache.py,sha256=S0HaPOCUIck-vNSQlS6KxnQtle6w-2dGuSxkUbJQY9Y,13168
10
+ cirq/json_resolver_cache.py,sha256=9g_JQMmfBzTuV-3s2flUbXIgcLjs4K7LjAFFgngdG1U,13204
11
11
  cirq/py.typed,sha256=VFSlmh_lNwnaXzwY-ZuW-C2Ws5PkuDoVgBdNCs0jXJE,63
12
12
  cirq/type_workarounds.py,sha256=-qyat6dmVoz8z76I-JLrnK1vAXmY9G1Qa3LYjQ4rJlI,959
13
13
  cirq/circuits/__init__.py,sha256=UPBO-WG6VodQWDkYgJdBzKK8k9CsxHFGIENM95vh7ac,1117
@@ -323,8 +323,8 @@ cirq/ops/op_tree.py,sha256=iXsIFcQCciU7C9SiPxhd_zrp4TBGCsmnqxKDjUl1aEo,6159
323
323
  cirq/ops/op_tree_test.py,sha256=h4phqrxQwYAfyu8o4f_fLi3WP2kdVuzWqrSCWGLHo_c,5575
324
324
  cirq/ops/parallel_gate.py,sha256=RSj1SuiwbDCMWxvTmi3xz7oE2QXBFgA59emijh4JPkE,6335
325
325
  cirq/ops/parallel_gate_test.py,sha256=M6o3AyXFQrwyiOTtGxlYH09TbHdjtTxCuMjmn-ALnn0,6298
326
- cirq/ops/parity_gates.py,sha256=JJdw_A9HHiJFVlYfWxp0QPBXtgfHjQYbYH_YFjoU4K4,14208
327
- cirq/ops/parity_gates_test.py,sha256=-Ib4GO4njRHanuTMpGvz_zaQf0siUJNNd_tpEYKUOjg,11462
326
+ cirq/ops/parity_gates.py,sha256=FVXd1h-HqftRAFfYGSmz0URR_lvVG4kpwav0mxf6DtU,14354
327
+ cirq/ops/parity_gates_test.py,sha256=7C0BmJl1HuoyVzfA8-lVCTiE1qNYQhMtyQlVx2uvFKA,11244
328
328
  cirq/ops/pauli_gates.py,sha256=sqqQEKEU89cmb1pzLPnrZ5XC0LchSXid8tHLQs8xJnk,6984
329
329
  cirq/ops/pauli_gates_test.py,sha256=bHt7A2w0auWxN9gyKAVeimT1KeOHz5C_CjFHSK1V-Co,7752
330
330
  cirq/ops/pauli_interaction_gate.py,sha256=GQtK5lRw2Uh7hs2GsoRxe-VMlMTO8PxDeZNVT6_qOWI,5499
@@ -825,6 +825,8 @@ cirq/protocols/json_test_data/_YEigenState.repr,sha256=xOsv4JMPz5zf4P9o2ezAROyUE
825
825
  cirq/protocols/json_test_data/_ZEigenState.json,sha256=DnBLzEfAc-tfaaVpBy8hd29Cn5NTDwcJwxhpRZ1SpZE,127
826
826
  cirq/protocols/json_test_data/_ZEigenState.repr,sha256=V2P3aMF1iBbzud8CUvnSVrBRt7KjOPbeWdeZKMRO510,36
827
827
  cirq/protocols/json_test_data/__init__.py,sha256=9f7jgLPoGVYZTfVJ0nGw5lu0uAKXJ8rZlQi82AJNglM,641
828
+ cirq/protocols/json_test_data/cirq.MSGate.json,sha256=G_roYqHu9XgZSu1lMZbInFsefVvgZfKuRubengXuawg,63
829
+ cirq/protocols/json_test_data/cirq.MSGate.repr,sha256=grCt0Y_v0_26K-HgqtVzc8pRgS09z1s4JhjE-cAucoE,16
828
830
  cirq/protocols/json_test_data/complex.json,sha256=fGbU2uxufM6Pt-sg3sHazL0oiqusseIPOid-1sxi0Do,212
829
831
  cirq/protocols/json_test_data/complex.repr,sha256=A-Gf4uPuecYNJPvdQYJ694YCx0uy1RV1HD3MYN6WUlo,19
830
832
  cirq/protocols/json_test_data/datetime.datetime.json,sha256=fb50Dr0wfnkYrG_pBzUsIstWb9GsFHbpnh9eZKEqhAc,67
@@ -835,7 +837,7 @@ cirq/protocols/json_test_data/pandas.Index.json_inward,sha256=KENE3PlSxmtMdnikuJ
835
837
  cirq/protocols/json_test_data/pandas.Index.repr_inward,sha256=2YnQUO58RGFGvuVjmR57v25YIvPAnTgVYh0jeQYhXHo,52
836
838
  cirq/protocols/json_test_data/pandas.MultiIndex.json,sha256=pF6YdRE3Qjhsf8CeGEZQvX5AWHAWaMNQF6c661Sqrxg,233
837
839
  cirq/protocols/json_test_data/pandas.MultiIndex.repr,sha256=g4q-1zFWYG8T7IAI0anQ5aMHSFlGF2CJsAoYdZzbGa8,80
838
- cirq/protocols/json_test_data/spec.py,sha256=8s-ZCIP8I-aNIMxKsnlpv8ej9_py3Rxxrr2loU0K6W4,5531
840
+ cirq/protocols/json_test_data/spec.py,sha256=7NY4zWAt-RG5k5Y1TZLIUEKzQNGsW4QE6axboziJUG8,5593
839
841
  cirq/protocols/json_test_data/sympy.Add.json,sha256=fVilRXllnMRnQcXuoU06IlwZOWK9Kwim1t6Q_s6z97g,1000
840
842
  cirq/protocols/json_test_data/sympy.Add.repr,sha256=9L_05ZlcrFpo8QoExFAAO_kEEpc7SSqGyp0vudkRlsU,228
841
843
  cirq/protocols/json_test_data/sympy.E.json,sha256=d2NfgXTX-YhePH-I0SkkI-lSSJ6PkqTnUZ-yngh9GQk,39
@@ -1040,8 +1042,8 @@ cirq/transformers/synchronize_terminal_measurements.py,sha256=p061MYYglY6HhWYYkF
1040
1042
  cirq/transformers/synchronize_terminal_measurements_test.py,sha256=VTiw5S3s_Y31qR7ME8Mzv50LdJ_6M3DOtgwvtziQzPI,7742
1041
1043
  cirq/transformers/transformer_api.py,sha256=beDdouAulWeg4SQRwAjgc5H1jrKD0maYY32XczsHokI,16964
1042
1044
  cirq/transformers/transformer_api_test.py,sha256=f-Vup0VCUvTqJKm5kWHf6xet7sFTerLMGYzJHy8Rc5s,13045
1043
- cirq/transformers/transformer_primitives.py,sha256=zj-GYew5sioNjOxOgjIjanxxDikYiewZcc9vPVCDZz0,37544
1044
- cirq/transformers/transformer_primitives_test.py,sha256=pJhCN28Tev7F04waYRtTlgJEY8fqtBcYJZDPSPUAWLw,41319
1045
+ cirq/transformers/transformer_primitives.py,sha256=tINAM7D7_MN9QzXwa7_BJkZ6ThcfYLxolbSsQQx2oM0,37578
1046
+ cirq/transformers/transformer_primitives_test.py,sha256=TwznpAZpJue9gE1sRQAl_0n6YyXTimckgGy4-2YrEvY,42256
1045
1047
  cirq/transformers/analytical_decompositions/__init__.py,sha256=ZNtETntol3G_n6uqzGxOmBanGMbCj0QAc-5vicN2jkM,2724
1046
1048
  cirq/transformers/analytical_decompositions/clifford_decomposition.py,sha256=DsuuP91pm2dX0CO4rWwmJAJyAfuXMcA1UJK0g8krp7k,6726
1047
1049
  cirq/transformers/analytical_decompositions/clifford_decomposition_test.py,sha256=AAZh_9vEb5f2E_EItPZTlMRNdv0d47AwqTn4BytX0UI,7102
@@ -1152,8 +1154,8 @@ cirq/work/sampler.py,sha256=JEAeQQRF3bqlO9AkOf4XbrTATDI5f5JgyM_FAUCNxao,19751
1152
1154
  cirq/work/sampler_test.py,sha256=B2ZsuqGT854gQtBIAh8k0LiG9Vj5wSzcGvkxOUoTcW4,13217
1153
1155
  cirq/work/zeros_sampler.py,sha256=x1C7cup66a43n-3tm8QjhiqJa07qcJW10FxNp9jJ59Q,2356
1154
1156
  cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
1155
- cirq_core-1.4.0.dev20240315194126.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1156
- cirq_core-1.4.0.dev20240315194126.dist-info/METADATA,sha256=cJfQKWPoUGyyBxBmMYQiSWBAEraf43RA2ZqhjxVdK18,2090
1157
- cirq_core-1.4.0.dev20240315194126.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
1158
- cirq_core-1.4.0.dev20240315194126.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1159
- cirq_core-1.4.0.dev20240315194126.dist-info/RECORD,,
1157
+ cirq_core-1.4.0.dev20240318170608.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1158
+ cirq_core-1.4.0.dev20240318170608.dist-info/METADATA,sha256=9LlNx-yxMHX68BtN6ge8WxHkurWmdK7I1u4F4lAWbWA,2090
1159
+ cirq_core-1.4.0.dev20240318170608.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
1160
+ cirq_core-1.4.0.dev20240318170608.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1161
+ cirq_core-1.4.0.dev20240318170608.dist-info/RECORD,,