cirq-core 1.3.0.dev20231110184552__py3-none-any.whl → 1.3.0.dev20231113194555__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
@@ -1 +1 @@
1
- __version__ = "1.3.0.dev20231110184552"
1
+ __version__ = "1.3.0.dev20231113194555"
cirq/ops/parity_gates.py CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  """Quantum gates that phase with respect to product-of-pauli observables."""
16
16
 
17
- from typing import Any, Dict, List, Optional, Tuple, Union, TYPE_CHECKING
17
+ from typing import Any, Dict, List, Optional, Tuple, Union, TYPE_CHECKING, Sequence
18
18
  from typing_extensions import Self
19
19
 
20
20
  import numpy as np
@@ -22,7 +22,15 @@ import numpy as np
22
22
  from cirq import protocols, value
23
23
  from cirq._compat import proper_repr
24
24
  from cirq._doc import document
25
- from cirq.ops import gate_features, eigen_gate, common_gates, pauli_gates
25
+ from cirq.ops import (
26
+ gate_features,
27
+ eigen_gate,
28
+ common_gates,
29
+ pauli_gates,
30
+ clifford_gate,
31
+ pauli_interaction_gate,
32
+ )
33
+
26
34
 
27
35
  if TYPE_CHECKING:
28
36
  import cirq
@@ -87,25 +95,29 @@ class XXPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
87
95
  return abs(np.sin(self._exponent * 0.5 * np.pi))
88
96
 
89
97
  def _decompose_into_clifford_with_qubits_(self, qubits):
90
- from cirq.ops.clifford_gate import SingleQubitCliffordGate
91
- from cirq.ops.pauli_interaction_gate import PauliInteractionGate
92
-
93
98
  if self.exponent % 2 == 0:
94
99
  return []
95
100
  if self.exponent % 2 == 0.5:
96
101
  return [
97
- PauliInteractionGate(pauli_gates.X, False, pauli_gates.X, False).on(*qubits),
98
- SingleQubitCliffordGate.X_sqrt.on_each(*qubits),
102
+ pauli_interaction_gate.PauliInteractionGate(
103
+ pauli_gates.X, False, pauli_gates.X, False
104
+ ).on(*qubits),
105
+ clifford_gate.SingleQubitCliffordGate.X_sqrt.on_each(*qubits),
99
106
  ]
100
107
  if self.exponent % 2 == 1:
101
- return [SingleQubitCliffordGate.X.on_each(*qubits)]
108
+ return [clifford_gate.SingleQubitCliffordGate.X.on_each(*qubits)]
102
109
  if self.exponent % 2 == 1.5:
103
110
  return [
104
- PauliInteractionGate(pauli_gates.X, False, pauli_gates.X, False).on(*qubits),
105
- SingleQubitCliffordGate.X_nsqrt.on_each(*qubits),
111
+ pauli_interaction_gate.PauliInteractionGate(
112
+ pauli_gates.X, False, pauli_gates.X, False
113
+ ).on(*qubits),
114
+ clifford_gate.SingleQubitCliffordGate.X_nsqrt.on_each(*qubits),
106
115
  ]
107
116
  return NotImplemented
108
117
 
118
+ def _has_stabilizer_effect_(self) -> bool:
119
+ return self.exponent % 2 in (0, 0.5, 1, 1.5)
120
+
109
121
  def _decompose_(self, qubits: Tuple['cirq.Qid', ...]) -> 'cirq.OP_TREE':
110
122
  yield common_gates.YPowGate(exponent=-0.5).on_each(*qubits)
111
123
  yield ZZPowGate(exponent=self.exponent, global_shift=self.global_shift)(*qubits)
@@ -192,25 +204,29 @@ class YYPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
192
204
  return abs(np.sin(self._exponent * 0.5 * np.pi))
193
205
 
194
206
  def _decompose_into_clifford_with_qubits_(self, qubits):
195
- from cirq.ops.clifford_gate import SingleQubitCliffordGate
196
- from cirq.ops.pauli_interaction_gate import PauliInteractionGate
197
-
198
207
  if self.exponent % 2 == 0:
199
208
  return []
200
209
  if self.exponent % 2 == 0.5:
201
210
  return [
202
- PauliInteractionGate(pauli_gates.Y, False, pauli_gates.Y, False).on(*qubits),
203
- SingleQubitCliffordGate.Y_sqrt.on_each(*qubits),
211
+ pauli_interaction_gate.PauliInteractionGate(
212
+ pauli_gates.Y, False, pauli_gates.Y, False
213
+ ).on(*qubits),
214
+ clifford_gate.SingleQubitCliffordGate.Y_sqrt.on_each(*qubits),
204
215
  ]
205
216
  if self.exponent % 2 == 1:
206
- return [SingleQubitCliffordGate.Y.on_each(*qubits)]
217
+ return [clifford_gate.SingleQubitCliffordGate.Y.on_each(*qubits)]
207
218
  if self.exponent % 2 == 1.5:
208
219
  return [
209
- PauliInteractionGate(pauli_gates.Y, False, pauli_gates.Y, False).on(*qubits),
210
- SingleQubitCliffordGate.Y_nsqrt.on_each(*qubits),
220
+ pauli_interaction_gate.PauliInteractionGate(
221
+ pauli_gates.Y, False, pauli_gates.Y, False
222
+ ).on(*qubits),
223
+ clifford_gate.SingleQubitCliffordGate.Y_nsqrt.on_each(*qubits),
211
224
  ]
212
225
  return NotImplemented
213
226
 
227
+ def _has_stabilizer_effect_(self) -> bool:
228
+ return self.exponent % 2 in (0, 0.5, 1, 1.5)
229
+
214
230
  def _decompose_(self, qubits: Tuple['cirq.Qid', ...]) -> 'cirq.OP_TREE':
215
231
  yield common_gates.XPowGate(exponent=0.5).on_each(*qubits)
216
232
  yield ZZPowGate(exponent=self.exponent, global_shift=self.global_shift)(*qubits)
@@ -265,6 +281,34 @@ class ZZPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
265
281
  exponent=-2 * self.exponent, global_shift=-self.global_shift / 2
266
282
  )(qubits[0], qubits[1])
267
283
 
284
+ def _decompose_into_clifford_with_qubits_(
285
+ self, qubits: Sequence['cirq.Qid']
286
+ ) -> Sequence[Union['cirq.Operation', Sequence['cirq.Operation']]]:
287
+ if not self._has_stabilizer_effect_():
288
+ return NotImplemented
289
+ if self.exponent % 2 == 0:
290
+ return []
291
+ if self.exponent % 2 == 1:
292
+ return clifford_gate.SingleQubitCliffordGate.Z.on_each(*qubits)
293
+
294
+ if self.exponent % 2 == 0.5:
295
+ return [
296
+ pauli_interaction_gate.PauliInteractionGate(
297
+ pauli_gates.Z, False, pauli_gates.Z, False
298
+ ).on(*qubits),
299
+ clifford_gate.SingleQubitCliffordGate.Z_sqrt.on_each(*qubits),
300
+ ]
301
+ else:
302
+ return [
303
+ pauli_interaction_gate.PauliInteractionGate(
304
+ pauli_gates.Z, False, pauli_gates.Z, False
305
+ ).on(*qubits),
306
+ clifford_gate.SingleQubitCliffordGate.Z_nsqrt.on_each(*qubits),
307
+ ]
308
+
309
+ def _has_stabilizer_effect_(self) -> bool:
310
+ return self.exponent % 2 in (0, 0.5, 1, 1.5)
311
+
268
312
  def _eigen_components(self) -> List[Tuple[float, np.ndarray]]:
269
313
  return [(0, np.diag([1, 0, 0, 1])), (1, np.diag([0, 1, 1, 0]))]
270
314
 
@@ -332,3 +332,26 @@ def test_json_serialization():
332
332
  json_text=cirq.to_json(cirq.ms(np.pi / 2)), resolvers=[custom_resolver]
333
333
  ) == cirq.ms(np.pi / 2)
334
334
  assert custom_resolver('X') is None
335
+
336
+
337
+ @pytest.mark.parametrize('gate_cls', (cirq.XXPowGate, cirq.YYPowGate, cirq.ZZPowGate))
338
+ @pytest.mark.parametrize(
339
+ 'exponent,is_clifford',
340
+ ((0, True), (0.5, True), (0.75, False), (1, True), (1.5, True), (-1.5, True)),
341
+ )
342
+ def test_clifford_protocols(gate_cls: type[cirq.EigenGate], exponent: float, is_clifford: bool):
343
+ gate = gate_cls(exponent=exponent)
344
+ assert hasattr(gate, '_decompose_into_clifford_with_qubits_')
345
+ if is_clifford:
346
+ clifford_decomposition = cirq.Circuit(
347
+ gate._decompose_into_clifford_with_qubits_(cirq.LineQubit.range(2))
348
+ )
349
+ assert cirq.has_stabilizer_effect(gate)
350
+ assert cirq.has_stabilizer_effect(clifford_decomposition)
351
+ if exponent == 0:
352
+ assert clifford_decomposition == cirq.Circuit()
353
+ else:
354
+ np.testing.assert_allclose(cirq.unitary(gate), cirq.unitary(clifford_decomposition))
355
+ else:
356
+ assert not cirq.has_stabilizer_effect(gate)
357
+ assert gate._decompose_into_clifford_with_qubits_(cirq.LineQubit.range(2)) is NotImplemented
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cirq-core
3
- Version: 1.3.0.dev20231110184552
3
+ Version: 1.3.0.dev20231113194555
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,7 +4,7 @@ cirq/_compat_test.py,sha256=84X6ELsb5fv3Hc0_ly8-IQfMnCNQN6tHs6GZFrnuNyI,35005
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=lT_23hxwpV7W1Gz23xtwHXCnKrcctqsBmP6RojOwPfU,40
7
+ cirq/_version.py,sha256=FjRRrLDsJxdXy5VWun6wvHHdgdMRUX6a2fMdwR8zajc,40
8
8
  cirq/_version_test.py,sha256=Ea3ZNdQKZBsZrSc9xle7TUdT9bUINs-qezPruQ_m38s,133
9
9
  cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
10
10
  cirq/json_resolver_cache.py,sha256=S0HaPOCUIck-vNSQlS6KxnQtle6w-2dGuSxkUbJQY9Y,13168
@@ -321,8 +321,8 @@ cirq/ops/op_tree.py,sha256=iXsIFcQCciU7C9SiPxhd_zrp4TBGCsmnqxKDjUl1aEo,6159
321
321
  cirq/ops/op_tree_test.py,sha256=h4phqrxQwYAfyu8o4f_fLi3WP2kdVuzWqrSCWGLHo_c,5575
322
322
  cirq/ops/parallel_gate.py,sha256=RSj1SuiwbDCMWxvTmi3xz7oE2QXBFgA59emijh4JPkE,6335
323
323
  cirq/ops/parallel_gate_test.py,sha256=M6o3AyXFQrwyiOTtGxlYH09TbHdjtTxCuMjmn-ALnn0,6298
324
- cirq/ops/parity_gates.py,sha256=OgPZZpkSBRBNMwWcuHbZi8rr8Gi_45QsVzRgRNjrR5M,12777
325
- cirq/ops/parity_gates_test.py,sha256=5a_wP3iHzxU2JQnFxlhhWwxAyzfiD6VGFZ0mf-e4p2w,10401
324
+ cirq/ops/parity_gates.py,sha256=JJdw_A9HHiJFVlYfWxp0QPBXtgfHjQYbYH_YFjoU4K4,14208
325
+ cirq/ops/parity_gates_test.py,sha256=-Ib4GO4njRHanuTMpGvz_zaQf0siUJNNd_tpEYKUOjg,11462
326
326
  cirq/ops/pauli_gates.py,sha256=pIZ0VsuDuwTAnEz4O-O6fh4PZLmCTHNOQE-obdP73gY,6932
327
327
  cirq/ops/pauli_gates_test.py,sha256=bHt7A2w0auWxN9gyKAVeimT1KeOHz5C_CjFHSK1V-Co,7752
328
328
  cirq/ops/pauli_interaction_gate.py,sha256=GQtK5lRw2Uh7hs2GsoRxe-VMlMTO8PxDeZNVT6_qOWI,5499
@@ -1146,8 +1146,8 @@ cirq/work/sampler.py,sha256=JVv1vvfa6EgFiR3UeDk44U186dCrioH2NZXueCgsb9w,19828
1146
1146
  cirq/work/sampler_test.py,sha256=zo1Hj6sn6fLs_WZMxYRApBqgBsldmptn74NL0jhNukc,12325
1147
1147
  cirq/work/zeros_sampler.py,sha256=D3hbNZC-jXKuNAWg2OUiUuT8pmDV_WFnEfMank6In4o,2357
1148
1148
  cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
1149
- cirq_core-1.3.0.dev20231110184552.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1150
- cirq_core-1.3.0.dev20231110184552.dist-info/METADATA,sha256=g_mvVjCx2CMn11aAyuhxtYcOOIZQPoT-9MGj5dsXq0Q,2077
1151
- cirq_core-1.3.0.dev20231110184552.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
1152
- cirq_core-1.3.0.dev20231110184552.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1153
- cirq_core-1.3.0.dev20231110184552.dist-info/RECORD,,
1149
+ cirq_core-1.3.0.dev20231113194555.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1150
+ cirq_core-1.3.0.dev20231113194555.dist-info/METADATA,sha256=Msv4xdyzlrHSLx_xY7xmlpnvblh2CqWYGyTx7jcjdDg,2077
1151
+ cirq_core-1.3.0.dev20231113194555.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
1152
+ cirq_core-1.3.0.dev20231113194555.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1153
+ cirq_core-1.3.0.dev20231113194555.dist-info/RECORD,,