cirq-core 1.4.0.dev20240430181951__py3-none-any.whl → 1.4.0.dev20240506164407__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.4.0.dev20240430181951"
1
+ __version__ = "1.4.0.dev20240506164407"
cirq/ops/clifford_gate.py CHANGED
@@ -400,7 +400,11 @@ class CliffordGate(raw_types.Gate, CommonCliffordGates):
400
400
  # By definition, Clifford Gate should always return True.
401
401
  return True
402
402
 
403
- def __pow__(self, exponent) -> 'CliffordGate':
403
+ def __pow__(self, exponent: float) -> 'CliffordGate':
404
+ if exponent != int(exponent):
405
+ return NotImplemented
406
+ exponent = int(exponent)
407
+
404
408
  if exponent == -1:
405
409
  return CliffordGate.from_clifford_tableau(self.clifford_tableau.inverse())
406
410
  if exponent == 0:
@@ -409,18 +413,24 @@ class CliffordGate(raw_types.Gate, CommonCliffordGates):
409
413
  )
410
414
  if exponent == 1:
411
415
  return self
412
- if exponent > 0 and int(exponent) == exponent:
413
- base_tableau = self.clifford_tableau.copy()
414
- for _ in range(int(exponent) - 1):
415
- base_tableau = base_tableau.then(self.clifford_tableau)
416
- return CliffordGate.from_clifford_tableau(base_tableau)
417
- if exponent < 0 and int(exponent) == exponent:
418
- base_tableau = self.clifford_tableau.copy()
419
- for _ in range(int(-exponent) - 1):
420
- base_tableau = base_tableau.then(self.clifford_tableau)
421
- return CliffordGate.from_clifford_tableau(base_tableau.inverse())
422
416
 
423
- return NotImplemented
417
+ base_tableau = self.clifford_tableau.copy()
418
+ if exponent < 0:
419
+ base_tableau = base_tableau.inverse()
420
+ exponent = abs(exponent)
421
+
422
+ # https://cp-algorithms.com/algebra/binary-exp.html
423
+ aux = qis.CliffordTableau(
424
+ num_qubits=self.clifford_tableau.n
425
+ ) # this tableau collects the odd terms
426
+ while exponent > 1:
427
+ if exponent & 1:
428
+ aux = aux.then(base_tableau)
429
+ base_tableau = base_tableau.then(base_tableau)
430
+ exponent >>= 1
431
+
432
+ base_tableau = base_tableau.then(aux)
433
+ return CliffordGate.from_clifford_tableau(base_tableau)
424
434
 
425
435
  def __repr__(self) -> str:
426
436
  return f"Clifford Gate with Tableau:\n {self.clifford_tableau._str_full_()}"
@@ -129,7 +129,9 @@ class StabilizerState(
129
129
 
130
130
  class CliffordTableau(StabilizerState):
131
131
  """Tableau representation of a stabilizer state
132
- (based on Aaronson and Gottesman 2006).
132
+
133
+ References:
134
+ - [Aaronson and Gottesman](https://arxiv.org/abs/quant-ph/0406196)
133
135
 
134
136
  The tableau stores the stabilizer generators of
135
137
  the state using three binary arrays: xs, zs, and rs.
@@ -71,6 +71,7 @@ class ConstantGauge(Gauge):
71
71
  post_q1: Tuple[ops.Gate, ...] = field(
72
72
  default=(), converter=lambda g: (g,) if isinstance(g, ops.Gate) else tuple(g)
73
73
  )
74
+ swap_qubits: bool = False
74
75
 
75
76
  def sample(self, gate: ops.Gate, prng: np.random.Generator) -> "ConstantGauge":
76
77
  return self
@@ -85,6 +86,41 @@ class ConstantGauge(Gauge):
85
86
  """A tuple (ops to apply to q0, ops to apply to q1)."""
86
87
  return self.post_q0, self.post_q1
87
88
 
89
+ def on(self, q0: ops.Qid, q1: ops.Qid) -> ops.Operation:
90
+ """Returns the operation that replaces the two qubit gate."""
91
+ if self.swap_qubits:
92
+ return self.two_qubit_gate(q1, q0)
93
+ return self.two_qubit_gate(q0, q1)
94
+
95
+
96
+ @frozen
97
+ class SameGateGauge(Gauge):
98
+ """Same as ConstantGauge but the new two-qubit gate equals the old gate."""
99
+
100
+ pre_q0: Tuple[ops.Gate, ...] = field(
101
+ default=(), converter=lambda g: (g,) if isinstance(g, ops.Gate) else tuple(g)
102
+ )
103
+ pre_q1: Tuple[ops.Gate, ...] = field(
104
+ default=(), converter=lambda g: (g,) if isinstance(g, ops.Gate) else tuple(g)
105
+ )
106
+ post_q0: Tuple[ops.Gate, ...] = field(
107
+ default=(), converter=lambda g: (g,) if isinstance(g, ops.Gate) else tuple(g)
108
+ )
109
+ post_q1: Tuple[ops.Gate, ...] = field(
110
+ default=(), converter=lambda g: (g,) if isinstance(g, ops.Gate) else tuple(g)
111
+ )
112
+ swap_qubits: bool = False
113
+
114
+ def sample(self, gate: ops.Gate, prng: np.random.Generator) -> ConstantGauge:
115
+ return ConstantGauge(
116
+ two_qubit_gate=gate,
117
+ pre_q0=self.pre_q0,
118
+ pre_q1=self.pre_q1,
119
+ post_q0=self.post_q0,
120
+ post_q1=self.post_q1,
121
+ swap_qubits=self.swap_qubits,
122
+ )
123
+
88
124
 
89
125
  def _select(choices: Sequence[Gauge], probabilites: np.ndarray, prng: np.random.Generator) -> Gauge:
90
126
  return choices[prng.choice(len(choices), p=probabilites)]
@@ -154,7 +190,7 @@ class GaugeTransformer:
154
190
  gauge = self.gauge_selector(rng).sample(op.gate, rng)
155
191
  q0, q1 = op.qubits
156
192
  left.extend([g(q) for g in gs] for q, gs in zip(op.qubits, gauge.pre))
157
- center.append(gauge.two_qubit_gate(q0, q1))
193
+ center.append(gauge.on(q0, q1))
158
194
  right.extend([g(q) for g in gs] for q, gs in zip(op.qubits, gauge.post))
159
195
  else:
160
196
  center.append(op)
@@ -17,17 +17,17 @@
17
17
  from cirq.transformers.gauge_compiling.gauge_compiling import (
18
18
  GaugeTransformer,
19
19
  GaugeSelector,
20
- ConstantGauge,
20
+ SameGateGauge,
21
21
  )
22
22
  from cirq import ops
23
23
 
24
24
  SpinInversionGaugeSelector = GaugeSelector(
25
25
  gauges=[
26
- ConstantGauge(two_qubit_gate=ops.ZZ, pre_q0=ops.X, post_q0=ops.X),
27
- ConstantGauge(two_qubit_gate=ops.ZZ, pre_q1=ops.X, post_q1=ops.X),
26
+ SameGateGauge(pre_q0=ops.X, post_q0=ops.X, pre_q1=ops.X, post_q1=ops.X),
27
+ SameGateGauge(),
28
28
  ]
29
29
  )
30
30
 
31
31
  SpinInversionGaugeTransformer = GaugeTransformer(
32
- target=ops.ZZ, gauge_selector=SpinInversionGaugeSelector
32
+ target=ops.GateFamily(ops.ZZPowGate), gauge_selector=SpinInversionGaugeSelector
33
33
  )
@@ -12,12 +12,26 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
-
16
15
  import cirq
17
16
  from cirq.transformers.gauge_compiling import SpinInversionGaugeTransformer
18
17
  from cirq.transformers.gauge_compiling.gauge_compiling_test_utils import GaugeTester
19
18
 
20
19
 
21
- class TestSpinInversionGauge(GaugeTester):
20
+ class TestSpinInversionGauge_0(GaugeTester):
22
21
  two_qubit_gate = cirq.ZZ
23
22
  gauge_transformer = SpinInversionGaugeTransformer
23
+
24
+
25
+ class TestSpinInversionGauge_1(GaugeTester):
26
+ two_qubit_gate = cirq.ZZ**0.1
27
+ gauge_transformer = SpinInversionGaugeTransformer
28
+
29
+
30
+ class TestSpinInversionGauge_2(GaugeTester):
31
+ two_qubit_gate = cirq.ZZ**-1
32
+ gauge_transformer = SpinInversionGaugeTransformer
33
+
34
+
35
+ class TestSpinInversionGauge_3(GaugeTester):
36
+ two_qubit_gate = cirq.ZZ**0.3
37
+ gauge_transformer = SpinInversionGaugeTransformer
@@ -12,18 +12,53 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- """A Gauge transformer for CZ**0.5 gate."""
15
+ """A Gauge transformer for CZ**0.5 and CZ**-0.5 gates."""
16
+
17
+
18
+ from typing import TYPE_CHECKING
19
+ import numpy as np
16
20
 
17
21
  from cirq.transformers.gauge_compiling.gauge_compiling import (
18
22
  GaugeTransformer,
19
23
  GaugeSelector,
20
24
  ConstantGauge,
25
+ Gauge,
21
26
  )
22
- from cirq.ops.common_gates import CZ
23
- from cirq import ops
27
+ from cirq.ops import CZ, S, X, Gateset
28
+
29
+ if TYPE_CHECKING:
30
+ import cirq
31
+
32
+ _SQRT_CZ = CZ**0.5
33
+ _ADJ_S = S**-1
24
34
 
25
- SqrtCZGaugeSelector = GaugeSelector(
26
- gauges=[ConstantGauge(pre_q0=ops.X, post_q0=ops.X, post_q1=ops.Z**0.5, two_qubit_gate=CZ**-0.5)]
27
- )
28
35
 
29
- SqrtCZGaugeTransformer = GaugeTransformer(target=CZ**0.5, gauge_selector=SqrtCZGaugeSelector)
36
+ class SqrtCZGauge(Gauge):
37
+
38
+ def weight(self) -> float:
39
+ return 3.0
40
+
41
+ def sample(self, gate: 'cirq.Gate', prng: np.random.Generator) -> ConstantGauge:
42
+ if prng.choice([True, False]):
43
+ return ConstantGauge(two_qubit_gate=gate)
44
+ swap_qubits = prng.choice([True, False])
45
+ if swap_qubits:
46
+ return ConstantGauge(
47
+ pre_q1=X,
48
+ post_q1=X,
49
+ post_q0=S if gate == _SQRT_CZ else _ADJ_S,
50
+ two_qubit_gate=gate**-1,
51
+ swap_qubits=True,
52
+ )
53
+ else:
54
+ return ConstantGauge(
55
+ pre_q0=X,
56
+ post_q0=X,
57
+ post_q1=S if gate == _SQRT_CZ else _ADJ_S,
58
+ two_qubit_gate=gate**-1,
59
+ )
60
+
61
+
62
+ SqrtCZGaugeTransformer = GaugeTransformer(
63
+ target=Gateset(_SQRT_CZ, _SQRT_CZ**-1), gauge_selector=GaugeSelector(gauges=[SqrtCZGauge()])
64
+ )
@@ -12,7 +12,6 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
-
16
15
  import cirq
17
16
  from cirq.transformers.gauge_compiling import SqrtCZGaugeTransformer
18
17
  from cirq.transformers.gauge_compiling.gauge_compiling_test_utils import GaugeTester
@@ -21,3 +20,8 @@ from cirq.transformers.gauge_compiling.gauge_compiling_test_utils import GaugeTe
21
20
  class TestSqrtCZGauge(GaugeTester):
22
21
  two_qubit_gate = cirq.CZ**0.5
23
22
  gauge_transformer = SqrtCZGaugeTransformer
23
+
24
+
25
+ class TestAdjointSqrtCZGauge(GaugeTester):
26
+ two_qubit_gate = cirq.CZ**-0.5
27
+ gauge_transformer = SqrtCZGaugeTransformer
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cirq-core
3
- Version: 1.4.0.dev20240430181951
3
+ Version: 1.4.0.dev20240506164407
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=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=sl6JoWpxiZDtf2vZLNMuq-vBb6mXIBq5SXaP3tQKItw,40
7
+ cirq/_version.py,sha256=ssE6yg0quJRx6t90raQtx0xyl-ZWXvP37SExL_xDZBA,40
8
8
  cirq/_version_test.py,sha256=yYS6xm5-nuBRQJa9R3n41WdvFtVyY7Lb5Q8bea3VgBI,133
9
9
  cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
10
10
  cirq/json_resolver_cache.py,sha256=9g_JQMmfBzTuV-3s2flUbXIgcLjs4K7LjAFFgngdG1U,13204
@@ -269,7 +269,7 @@ cirq/ops/boolean_hamiltonian.py,sha256=hjmzBvWiZnb18JfdhId-dVxt2VmbyAbqMSFAPWV7s
269
269
  cirq/ops/boolean_hamiltonian_test.py,sha256=1ey5yfYZPKZDsfM3jpCPAOpbPs_y8i4K_WvDK2d5_4Y,8518
270
270
  cirq/ops/classically_controlled_operation.py,sha256=bMqKutwzqbvN2r7mOVOI12HTPDGSJLkhQQgfAcTtbDU,9166
271
271
  cirq/ops/classically_controlled_operation_test.py,sha256=MNU0Adff4kTosqsrQ3PUT3ARcZee_PkchT6u0xDl8Qg,48039
272
- cirq/ops/clifford_gate.py,sha256=xTAGYR24u__ctlY2fNsWYTQcJof4euRYMGN8cdERV2E,39235
272
+ cirq/ops/clifford_gate.py,sha256=ARbHGptZxQo6kX9QTrh_kZ89N7lW6V3GQSE3o-1kixU,39366
273
273
  cirq/ops/clifford_gate_test.py,sha256=NF_if1X8LCMA9hy0vBO7lxvVPdumlvMMnI2XRQ-RLpk,37472
274
274
  cirq/ops/common_channels.py,sha256=mVGEta2wnaWOhRCXQO6gUj9Zll3rtXqpY-PRYcJ8m1U,38282
275
275
  cirq/ops/common_channels_test.py,sha256=EL_PxbqD3KPC8ioihiukhmW8bUdclqqigKoFyUQpmIM,29690
@@ -873,7 +873,7 @@ cirq/protocols/json_test_data/sympy.pi.repr,sha256=ZQS0my0esr3dWTZ3mWlqgR63uorPC
873
873
  cirq/qis/__init__.py,sha256=C_gnZt9CNWEE0I1IAZE0liNVIv-aphUohIHJih-szDg,1836
874
874
  cirq/qis/channels.py,sha256=AxKgLUbWLrb1pz9xLtSpYm_stjN-IWOwLFYC9YZSons,12798
875
875
  cirq/qis/channels_test.py,sha256=iqkSyfvx_c2ZpJKAVEsFyZRmKpzNrJsyFjHbaJUMqcQ,14454
876
- cirq/qis/clifford_tableau.py,sha256=Ik1ogTElaB3nJCPCGj1yqxMdpu404AbZjkVOVYZOins,25305
876
+ cirq/qis/clifford_tableau.py,sha256=X25eCXWEUWzoB-x6cna4LdLMFVNxUiIEUxKHJkkc2aE,25353
877
877
  cirq/qis/clifford_tableau_test.py,sha256=Z-5YSysJw2H3AfgZxhptvUMr5GUjUFgPcAUdcust9Qk,18441
878
878
  cirq/qis/measures.py,sha256=-e2mStl9882z4mbLwWtbdmmdJilmf6Ex2b_jSXhMX3c,12194
879
879
  cirq/qis/measures_test.py,sha256=3LTTGdvuFfZWmFyWFeUHpg1yGc9z0VE8j7Kd7J7y8i4,10092
@@ -1074,16 +1074,16 @@ cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py,sha2
1074
1074
  cirq/transformers/gauge_compiling/__init__.py,sha256=dmgVx7_yfsO9TarOCMBfVuZjza_6_MmUyAfM_eo698E,1146
1075
1075
  cirq/transformers/gauge_compiling/cz_gauge.py,sha256=TNZviXFu4j-lCF87QMGYVdb2RC_ePHLdI6FRCqh9go4,2550
1076
1076
  cirq/transformers/gauge_compiling/cz_gauge_test.py,sha256=_2RMzwuMoqytgsVZEET2m6QsGoZ2_uWgBfSGGvhZEWo,854
1077
- cirq/transformers/gauge_compiling/gauge_compiling.py,sha256=GCYpaZIUxkcz16s8DI64dtpHhSGiIy6JIplvM6GUklc,6662
1077
+ cirq/transformers/gauge_compiling/gauge_compiling.py,sha256=7jUg2MHVX2V8SzH7r27e_BUUA_p5l15-Qv8lLlhGasQ,7948
1078
1078
  cirq/transformers/gauge_compiling/gauge_compiling_test.py,sha256=xVeoaaMuenlp_pxqmZO89kJEeBV0iapK7-JDTUuC7Lg,1565
1079
1079
  cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py,sha256=6mpF2ftcDtWQEsZNr-m16GkDOn5WBWV08JB4ZS5rf8M,3408
1080
1080
  cirq/transformers/gauge_compiling/gauge_compiling_test_utils_test.py,sha256=HQw1xeko9OAD0PCuKcehUiy8mbxeRza4nE-6E8MGVME,1584
1081
1081
  cirq/transformers/gauge_compiling/iswap_gauge.py,sha256=UGJ_061h65Rfgb9LWREjxC8OSt01ZqP9TGnacL8VAuk,3500
1082
1082
  cirq/transformers/gauge_compiling/iswap_gauge_test.py,sha256=HEIIwKlX5ixau1e_etSUj5NvYOVTT-Gc3kuHcyKAeJ4,866
1083
- cirq/transformers/gauge_compiling/spin_inversion_gauge.py,sha256=BMt1g2h23J9jb6LTlZsNczMKIY8J0duHhZNu0jRB48M,1107
1084
- cirq/transformers/gauge_compiling/spin_inversion_gauge_test.py,sha256=PtbHNvh6Oz-n6Tn0fdvpgHGgaPuJQPlJ8UfHd59-dks,887
1085
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py,sha256=l0Dkz2a7_ljKzzP-Rr9f_yY4pqJ8TGY_R-FVEkBb77I,1050
1086
- cirq/transformers/gauge_compiling/sqrt_cz_gauge_test.py,sha256=wB_WezbTBbkwnTs7hz_tXmU4syuMulGirDDDjzqvNt0,871
1083
+ cirq/transformers/gauge_compiling/spin_inversion_gauge.py,sha256=gfjSlQdo13GfBPlrkQoHPWWzouiV7yYr7JAaB85NSGY,1086
1084
+ cirq/transformers/gauge_compiling/spin_inversion_gauge_test.py,sha256=FJwl11VPNXkf_v0WjCg9VxNKAplZ_5bZR7guOfnK-aI,1292
1085
+ cirq/transformers/gauge_compiling/sqrt_cz_gauge.py,sha256=32OGTcYT3tBFEQ1GQlrssc1wtwCcSvk4ZC0I1XD1QXg,1869
1086
+ cirq/transformers/gauge_compiling/sqrt_cz_gauge_test.py,sha256=RwjadOOJfa2Qf7iryTIMJLPzeDMNqFkP6Tewjq68gJI,997
1087
1087
  cirq/transformers/gauge_compiling/sqrt_iswap_gauge.py,sha256=dqQa-UWq31bE_jF3KMhU76sND5GuqTpEp9-wVuXdWVM,3126
1088
1088
  cirq/transformers/gauge_compiling/sqrt_iswap_gauge_test.py,sha256=0CLZoLw-WK3aKEIoaKBrQZ-qvaprOVLad-dVyWFmSiU,882
1089
1089
  cirq/transformers/heuristic_decompositions/__init__.py,sha256=2KBAUk-vsVku-HuahLbDQxp8bjEQMZUUNiBz_cvUMUw,831
@@ -1169,8 +1169,8 @@ cirq/work/sampler.py,sha256=JEAeQQRF3bqlO9AkOf4XbrTATDI5f5JgyM_FAUCNxao,19751
1169
1169
  cirq/work/sampler_test.py,sha256=B2ZsuqGT854gQtBIAh8k0LiG9Vj5wSzcGvkxOUoTcW4,13217
1170
1170
  cirq/work/zeros_sampler.py,sha256=x1C7cup66a43n-3tm8QjhiqJa07qcJW10FxNp9jJ59Q,2356
1171
1171
  cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
1172
- cirq_core-1.4.0.dev20240430181951.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1173
- cirq_core-1.4.0.dev20240430181951.dist-info/METADATA,sha256=ridrMaAz813yPBhStGmnK4X6S_TW3CoO7VnVs8HH4nI,2098
1174
- cirq_core-1.4.0.dev20240430181951.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
1175
- cirq_core-1.4.0.dev20240430181951.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1176
- cirq_core-1.4.0.dev20240430181951.dist-info/RECORD,,
1172
+ cirq_core-1.4.0.dev20240506164407.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1173
+ cirq_core-1.4.0.dev20240506164407.dist-info/METADATA,sha256=6ilalyHUj2Tq2g4Fwy6ptYf4dX8Hq7prrwYw5AYJT28,2098
1174
+ cirq_core-1.4.0.dev20240506164407.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
1175
+ cirq_core-1.4.0.dev20240506164407.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1176
+ cirq_core-1.4.0.dev20240506164407.dist-info/RECORD,,