cirq-core 1.5.0.dev20250303232646__py3-none-any.whl → 1.5.0.dev20250304001340__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, 10, 0): # pragma: no cover
28
28
  'of cirq (e.g. "python -m pip install cirq==1.1.*")'
29
29
  )
30
30
 
31
- __version__ = "1.5.0.dev20250303232646"
31
+ __version__ = "1.5.0.dev20250304001340"
cirq/_version_test.py CHANGED
@@ -3,4 +3,4 @@ import cirq
3
3
 
4
4
 
5
5
  def test_version():
6
- assert cirq.__version__ == "1.5.0.dev20250303232646"
6
+ assert cirq.__version__ == "1.5.0.dev20250304001340"
@@ -38,3 +38,5 @@ from cirq.transformers.gauge_compiling.iswap_gauge import (
38
38
  from cirq.transformers.gauge_compiling.sqrt_iswap_gauge import (
39
39
  SqrtISWAPGaugeTransformer as SqrtISWAPGaugeTransformer,
40
40
  )
41
+
42
+ from cirq.transformers.gauge_compiling.cphase_gauge import CPhaseGaugeTransformer
@@ -0,0 +1,146 @@
1
+ # Copyright 2025 The Cirq Developers
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """A Gauge Transformer for the cphase gate."""
16
+
17
+ import cirq.transformers.gauge_compiling.sqrt_cz_gauge as sqrt_cz_gauge
18
+
19
+ from cirq.transformers.gauge_compiling.gauge_compiling import (
20
+ GaugeTransformer,
21
+ GaugeSelector,
22
+ ConstantGauge,
23
+ Gauge,
24
+ TwoQubitGateSymbolizer,
25
+ )
26
+ from cirq import ops
27
+ import numpy as np
28
+
29
+
30
+ class CPhasePauliGauge(Gauge):
31
+ """Gauges for the cphase gate (CZPowGate).
32
+
33
+ We identify 16 distinct gauges, corresponding to the 16 two-qubit Pauli operators that can be
34
+ inserted before the cphase gate. When an anticommuting gate is inserted, the cphase angle is
35
+ negated (or equivalently, the exponent of the CZPowGate is negated), so both postive and
36
+ negative angles should be calibrated to use this.
37
+ """
38
+
39
+ def weight(self) -> float:
40
+ return 1.0
41
+
42
+ def _get_new_post(self, exponent: float, pre: ops.Gate) -> ops.Gate:
43
+ """Identify the new single-qubit gate that needs to be inserted in the case that both pre
44
+ gates are X or Y.
45
+
46
+ Args:
47
+ exponent: The exponent of the CZPowGate that is getting transformed.
48
+ pre: The gate (X or Y) that is inserted on a given qubit.
49
+
50
+ Returns:
51
+ The single-qubit gate to insert after the CZPowGate on the same qubit.
52
+
53
+ Raises:
54
+ ValueError: If pre is not X or Y.
55
+ """
56
+ if pre == ops.X:
57
+ return ops.PhasedXPowGate(exponent=1, phase_exponent=exponent / 2)
58
+ elif pre == ops.Y:
59
+ return ops.PhasedXZGate.from_zyz_exponents(z0=-exponent, y=1, z1=0)
60
+ else:
61
+ raise ValueError("pre should be cirq.X or cirq.Y") # pragma: no cover
62
+
63
+ def _get_constant_gauge(
64
+ self, gate: ops.CZPowGate, pre_q0: ops.Gate, pre_q1: ops.Gate
65
+ ) -> ConstantGauge:
66
+ """Get the ConstantGauge corresponding to a given pre_q0 and pre_q1.
67
+
68
+ Args:
69
+ gate: The particular cphase gate to transform.
70
+ pre_q0: The Pauli (I, X, Y, or Z) to insert before the cphase gate on q0.
71
+ pre_q1: The Pauli (I, X, Y, or Z) to insert before the cphase gate on q1.
72
+
73
+ Returns:
74
+ The ConstantGauge implementing the given transformation.
75
+
76
+ Raises:
77
+ ValueError: If pre_q0 and pre_q1 are not both in {I, X, Y, Z}.
78
+ """
79
+
80
+ exponent = gate.exponent
81
+ commuting_paulis = {ops.I, ops.Z}
82
+ anticommuting_paulis = {ops.X, ops.Y}
83
+ if pre_q0 in commuting_paulis and pre_q1 in commuting_paulis:
84
+ return ConstantGauge(
85
+ two_qubit_gate=gate, pre_q0=pre_q0, pre_q1=pre_q1, post_q0=pre_q0, post_q1=pre_q1
86
+ )
87
+ elif pre_q0 in anticommuting_paulis and pre_q1 in commuting_paulis:
88
+ new_gate = ops.CZ ** (-exponent)
89
+ post_q1 = ops.Z ** (exponent) if pre_q1 == ops.I else ops.Z ** (1 + exponent)
90
+ return ConstantGauge(
91
+ two_qubit_gate=new_gate,
92
+ pre_q0=pre_q0,
93
+ pre_q1=pre_q1,
94
+ post_q0=pre_q0,
95
+ post_q1=post_q1,
96
+ )
97
+ elif pre_q0 in commuting_paulis and pre_q1 in anticommuting_paulis:
98
+ new_gate = ops.CZ ** (-exponent)
99
+ post_q0 = ops.Z ** (exponent) if pre_q0 == ops.I else ops.Z ** (1 + exponent)
100
+ return ConstantGauge(
101
+ two_qubit_gate=new_gate,
102
+ pre_q0=pre_q0,
103
+ pre_q1=pre_q1,
104
+ post_q0=post_q0,
105
+ post_q1=pre_q1,
106
+ )
107
+ elif pre_q0 in anticommuting_paulis and pre_q1 in anticommuting_paulis:
108
+ return ConstantGauge(
109
+ two_qubit_gate=gate,
110
+ pre_q0=pre_q0,
111
+ pre_q1=pre_q1,
112
+ post_q0=self._get_new_post(exponent, pre_q0),
113
+ post_q1=self._get_new_post(exponent, pre_q1),
114
+ )
115
+ else:
116
+ raise ValueError("pre_q0 and pre_q1 should be X, Y, Z, or I") # pragma: no cover
117
+
118
+ def sample(self, gate: ops.Gate, prng: np.random.Generator) -> ConstantGauge:
119
+ """Sample the 16 cphase gauges at random.
120
+
121
+ Args:
122
+ gate: The CZPowGate to transform.
123
+ prng: The pseudorandom number generator.
124
+
125
+ Returns:
126
+ A ConstantGauge implementing the transformation.
127
+
128
+ Raises:
129
+ TypeError: if gate is not a CZPowGate
130
+ """
131
+
132
+ if not type(gate) == ops.CZPowGate:
133
+ raise TypeError("gate must be a CZPowGate") # pragma: no cover
134
+ pre_q0, pre_q1 = prng.choice(np.array([ops.I, ops.X, ops.Y, ops.Z]), size=2, replace=True)
135
+ return self._get_constant_gauge(gate, pre_q0, pre_q1)
136
+
137
+
138
+ CPhaseGaugeSelector = GaugeSelector(gauges=[CPhasePauliGauge()])
139
+
140
+ CPhaseGaugeTransformer = GaugeTransformer(
141
+ target=ops.Gateset(ops.CZPowGate),
142
+ gauge_selector=CPhaseGaugeSelector,
143
+ two_qubit_gate_symbolizer=TwoQubitGateSymbolizer(
144
+ symbolizer_fn=sqrt_cz_gauge._symbolize_as_cz_pow, n_symbols=1
145
+ ),
146
+ )
@@ -0,0 +1,47 @@
1
+ # Copyright 2025 The Cirq Developers
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import cirq
16
+ from cirq.transformers.gauge_compiling.cphase_gauge import CPhaseGaugeTransformer
17
+ from cirq.transformers.gauge_compiling.gauge_compiling_test_utils import GaugeTester
18
+
19
+
20
+ class TestCPhaseGauge_0_3(GaugeTester):
21
+ two_qubit_gate = cirq.CZ**0.3
22
+ gauge_transformer = CPhaseGaugeTransformer
23
+ sweep_must_pass = True
24
+
25
+
26
+ class TestCPhaseGauge_m0_3(GaugeTester):
27
+ two_qubit_gate = cirq.CZ ** (-0.3)
28
+ gauge_transformer = CPhaseGaugeTransformer
29
+ sweep_must_pass = True
30
+
31
+
32
+ class TestCPhaseGauge_0_1(GaugeTester):
33
+ two_qubit_gate = cirq.CZ**0.1
34
+ gauge_transformer = CPhaseGaugeTransformer
35
+ sweep_must_pass = True
36
+
37
+
38
+ class TestCPhaseGauge_m0_1(GaugeTester):
39
+ two_qubit_gate = cirq.CZ ** (-0.1)
40
+ gauge_transformer = CPhaseGaugeTransformer
41
+ sweep_must_pass = True
42
+
43
+
44
+ class TestCPhaseGauge_0_7(GaugeTester):
45
+ two_qubit_gate = cirq.CZ**0.7
46
+ gauge_transformer = CPhaseGaugeTransformer
47
+ sweep_must_pass = True
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cirq-core
3
- Version: 1.5.0.dev20250303232646
3
+ Version: 1.5.0.dev20250304001340
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=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=5ZYL8YisEAJmvf7uCiOE__WF4XbQiu82jV2Ci4emFc8,1206
8
- cirq/_version_test.py,sha256=f2hAsut7CTpxQp2HzLKtCb8j7VkWefO4tTKWTgjnRFk,147
7
+ cirq/_version.py,sha256=Dzqivn_TVHWzOySxo3ExUHJouUjPe5gJGukS6exIIlY,1206
8
+ cirq/_version_test.py,sha256=bdf3qF5aQ3Utq_Fcf598raGjw7f6_wUrdVW02qS9wPc,147
9
9
  cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
10
10
  cirq/json_resolver_cache.py,sha256=p-vEOa-8GQ2cFIAdze-kd6C1un1uRvtujVPljVKaHBg,13557
11
11
  cirq/py.typed,sha256=VFSlmh_lNwnaXzwY-ZuW-C2Ws5PkuDoVgBdNCs0jXJE,63
@@ -1104,7 +1104,9 @@ cirq/transformers/analytical_decompositions/two_qubit_to_ms.py,sha256=Awr7WvaJe_
1104
1104
  cirq/transformers/analytical_decompositions/two_qubit_to_ms_test.py,sha256=85MbuIAos7o1371wXs_KH-Bk6jsPqSBKAx9GJ9c-wVo,4160
1105
1105
  cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py,sha256=F_XpM4ApYHxV6hbWnV3C7Ud9L1BnpvBHBXShPh2mP3k,25397
1106
1106
  cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py,sha256=eKOzjWkR7xs-CL2oPj__nWXR0LL9oO42wEHibnvWq-o,20618
1107
- cirq/transformers/gauge_compiling/__init__.py,sha256=eG8ghJrue39O5Ijla_VhKrxhgr2oWGIXHEcMKqSRkCM,1439
1107
+ cirq/transformers/gauge_compiling/__init__.py,sha256=cEcoLT8TONEE_r_sL_deLUvOQv64C1j6NN-5JtK0b1E,1522
1108
+ cirq/transformers/gauge_compiling/cphase_gauge.py,sha256=gJyNgic-_hxo1hjkDSAq1q8s8HaZ-rH734kkSZ0wQCc,5540
1109
+ cirq/transformers/gauge_compiling/cphase_gauge_test.py,sha256=GRVE5aKeTsbWzl7bTxvZuSrEjdXfeoKm1TQW6mfxQt0,1526
1108
1110
  cirq/transformers/gauge_compiling/cz_gauge.py,sha256=TNZviXFu4j-lCF87QMGYVdb2RC_ePHLdI6FRCqh9go4,2550
1109
1111
  cirq/transformers/gauge_compiling/cz_gauge_test.py,sha256=sHEgEEI_z9-Ka5ChN2JmtoYcEHhNYHysOjGJzaaKkoA,881
1110
1112
  cirq/transformers/gauge_compiling/gauge_compiling.py,sha256=4g2IyjGqEHD7KkawXlprhNLfbeSyz3QdWIHPAjqeGFo,18846
@@ -1202,8 +1204,8 @@ cirq/work/sampler.py,sha256=bE5tmVkcR6cZZMLETxDfHehdsYUMbx2RvBeIBetehI4,19187
1202
1204
  cirq/work/sampler_test.py,sha256=hL2UWx3dz2ukZVNxWftiKVvJcQoLplLZdQm-k1QcA40,13282
1203
1205
  cirq/work/zeros_sampler.py,sha256=x1C7cup66a43n-3tm8QjhiqJa07qcJW10FxNp9jJ59Q,2356
1204
1206
  cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
1205
- cirq_core-1.5.0.dev20250303232646.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1206
- cirq_core-1.5.0.dev20250303232646.dist-info/METADATA,sha256=TBd_aS_DbyScMMaiBdcHbYTa0I_sEka249ESOSWtzw8,4817
1207
- cirq_core-1.5.0.dev20250303232646.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
1208
- cirq_core-1.5.0.dev20250303232646.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1209
- cirq_core-1.5.0.dev20250303232646.dist-info/RECORD,,
1207
+ cirq_core-1.5.0.dev20250304001340.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1208
+ cirq_core-1.5.0.dev20250304001340.dist-info/METADATA,sha256=opWOGsU1nsxZKvWown91TUWQ0MYKxZrf-OGTcvcMiLw,4817
1209
+ cirq_core-1.5.0.dev20250304001340.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
1210
+ cirq_core-1.5.0.dev20250304001340.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1211
+ cirq_core-1.5.0.dev20250304001340.dist-info/RECORD,,