cirq-core 1.7.0.dev20251028035559__py3-none-any.whl → 1.7.0.dev20251030221000__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.dev20251028035559"
31
+ __version__ = "1.7.0.dev20251030221000"
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.dev20251028035559"
6
+ assert cirq.__version__ == "1.7.0.dev20251030221000"
@@ -75,10 +75,12 @@ class QasmUGate(ops.Gate):
75
75
 
76
76
  def _decompose_(self, qubits):
77
77
  q = qubits[0]
78
+ phase_correction_half_turns = (self.phi + self.lmda) / 2
78
79
  return [
79
80
  ops.rz(self.lmda * np.pi).on(q),
80
81
  ops.ry(self.theta * np.pi).on(q),
81
82
  ops.rz(self.phi * np.pi).on(q),
83
+ ops.global_phase_operation(1j ** (2 * phase_correction_half_turns)),
82
84
  ]
83
85
 
84
86
  def _value_equality_values_(self):
@@ -29,6 +29,17 @@ def _make_qubits(n):
29
29
  return [cirq.NamedQubit(f'q{i}') for i in range(n)]
30
30
 
31
31
 
32
+ def _qiskit_ugate_unitary(gate: QasmUGate) -> np.ndarray:
33
+ # Ref: https://quantum.cloud.ibm.com/docs/en/api/qiskit/qiskit.circuit.library.U3Gate#u3gate
34
+ th, ph, lm = np.pi * np.array([gate.theta, gate.phi, gate.lmda])
35
+ return np.array(
36
+ [
37
+ [np.cos(th / 2), -np.exp(1j * lm) * np.sin(th / 2)],
38
+ [np.exp(1j * ph) * np.sin(th / 2), np.exp(1j * (ph + lm)) * np.cos(th / 2)],
39
+ ]
40
+ )
41
+
42
+
32
43
  def test_u_gate_repr() -> None:
33
44
  gate = QasmUGate(0.1, 0.2, 0.3)
34
45
  assert repr(gate) == 'cirq.circuits.qasm_output.QasmUGate(theta=0.1, phi=0.2, lmda=0.3)'
@@ -43,6 +54,20 @@ def test_u_gate_eq() -> None:
43
54
  cirq.approx_eq(gate4, gate3, atol=1e-16)
44
55
 
45
56
 
57
+ @pytest.mark.parametrize("_", range(10))
58
+ def test_u_gate_from_qiskit_ugate_unitary(_) -> None:
59
+ # QasmUGate at (theta, phi, lmda) is the same as QasmUGate at
60
+ # (2 - theta, phi + 1, lmda + 1) and a global phase factor of -1.
61
+ # QasmUGate.from_matrix resolves theta at [0, 1] and ignores possible global
62
+ # phase. To avoid phase discrepancy we limit theta to the [0, 1] interval.
63
+ theta = np.random.uniform(0, 1)
64
+ phi = np.random.uniform(0, 2)
65
+ lmda = np.random.uniform(0, 2)
66
+ u = _qiskit_ugate_unitary(QasmUGate(theta, phi, lmda))
67
+ g = QasmUGate.from_matrix(u)
68
+ np.testing.assert_allclose(cirq.unitary(g), u, atol=1e-7)
69
+
70
+
46
71
  def test_qasm_two_qubit_gate_repr() -> None:
47
72
  cirq.testing.assert_equivalent_repr(
48
73
  QasmTwoQubitGate.from_matrix(cirq.testing.random_unitary(4))
@@ -53,13 +78,14 @@ def test_qasm_u_qubit_gate_unitary() -> None:
53
78
  u = cirq.testing.random_unitary(2)
54
79
  g = QasmUGate.from_matrix(u)
55
80
  cirq.testing.assert_allclose_up_to_global_phase(cirq.unitary(g), u, atol=1e-7)
56
-
57
81
  cirq.testing.assert_implements_consistent_protocols(g)
82
+ np.testing.assert_allclose(cirq.unitary(g), _qiskit_ugate_unitary(g), atol=1e-7)
58
83
 
59
84
  u = cirq.unitary(cirq.Y)
60
85
  g = QasmUGate.from_matrix(u)
61
86
  cirq.testing.assert_allclose_up_to_global_phase(cirq.unitary(g), u, atol=1e-7)
62
87
  cirq.testing.assert_implements_consistent_protocols(g)
88
+ np.testing.assert_allclose(cirq.unitary(g), _qiskit_ugate_unitary(g), atol=1e-7)
63
89
 
64
90
 
65
91
  def test_qasm_two_qubit_gate_unitary() -> None:
@@ -200,7 +226,7 @@ ry(pi*-0.25) q[0];
200
226
  )
201
227
 
202
228
 
203
- def test_qasm_global_pahse() -> None:
229
+ def test_qasm_global_phase() -> None:
204
230
  output = cirq.QasmOutput((cirq.global_phase_operation(np.exp(1j * 5))), ())
205
231
  assert (
206
232
  str(output)
@@ -1089,8 +1089,8 @@ two_qubit_gates = [
1089
1089
  # Mapping of two-qubit gates and `num_params`
1090
1090
  two_qubit_param_gates = {
1091
1091
  # TODO: fix and enable commented gates below
1092
- # ('cu1', cirq.ControlledGate(QasmUGate(0, 0, 0.1 / np.pi))): 1,
1093
- # ('cu3', cirq.ControlledGate(QasmUGate(0.1 / np.pi, 0.2 / np.pi, 0.3 / np.pi))): 3,
1092
+ ('cu1', cirq.ControlledGate(QasmUGate(0, 0, 0.1 / np.pi))): 1,
1093
+ ('cu3', cirq.ControlledGate(QasmUGate(0.1 / np.pi, 0.2 / np.pi, 0.3 / np.pi))): 3,
1094
1094
  # ('cu', cirq.ControlledGate(QasmUGate(0.1 / np.pi, 0.2 / np.pi, 0.3 / np.pi))): 3,
1095
1095
  ('crx', cirq.ControlledGate(cirq.rx(0.1))): 1,
1096
1096
  ('cry', cirq.ControlledGate(cirq.ry(0.1))): 1,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cirq-core
3
- Version: 1.7.0.dev20251028035559
3
+ Version: 1.7.0.dev20251030221000
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=28ZskY9ZtZ_4GS1oXPUgklKnJqmAE-rkUfzcsJ0--nA,2941
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=hwKIrLaPuF0ICgE1qbNArfVRn9cZA8_8VnpdaPSokDM,1206
8
- cirq/_version_test.py,sha256=kvN_UM8XK-zjfJ6SXpp97upPv198bIXsvNPxFrqa4GI,155
7
+ cirq/_version.py,sha256=EbXecXIaSvPrEu2RIww54PsEeOXmhQk0K6BxVKSAvPQ,1206
8
+ cirq/_version_test.py,sha256=NSxK57phcgzEyT1HVVrE1JhK1jdZuebiR34bOxq7c8c,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
@@ -28,8 +28,8 @@ cirq/circuits/moment.py,sha256=NZo497gTrPHuhgJT_zTaYZU2UP9oMdDkdV8urHbBDi4,28338
28
28
  cirq/circuits/moment_test.py,sha256=wTfFl3yret5d5NTsUW1hAoATEZ0iZJ0tFiXHBKgkMUs,34255
29
29
  cirq/circuits/optimization_pass.py,sha256=W_YYo_9uy5h4ijU_In5n7gG3EvCVp1cJbE1pHD9ci74,6481
30
30
  cirq/circuits/optimization_pass_test.py,sha256=FvCCOZrqVQLYrf_BUAZ6M-sm6dMv00_xsvpN25Op1BA,5914
31
- cirq/circuits/qasm_output.py,sha256=qclnyiEnRzkcr0JqzzABuiHD3INkiALmhl1jCW0AYNk,13079
32
- cirq/circuits/qasm_output_test.py,sha256=e2TsMMVZLzyCYh6U3umPtusxmeiLJDunmsgFRa5p7E0,14048
31
+ cirq/circuits/qasm_output.py,sha256=BcOjhLTFFlH1qR4WTtpHyt0OdQ5HebfDUPor-nNBlo8,13225
32
+ cirq/circuits/qasm_output_test.py,sha256=fma97it7yftr2bapoAW02yn3-lZbVDJ5LTE6ev-SiFw,15297
33
33
  cirq/circuits/text_diagram_drawer.py,sha256=G2fJcoyUP0ikrhTluFo4lULCEXKJI0dai5lBtHm0f14,16485
34
34
  cirq/circuits/text_diagram_drawer_test.py,sha256=YBe8zT7BDENoR-gA3l77mtRj6vxY3kVVZ4FqBO_WwsY,11031
35
35
  cirq/contrib/__init__.py,sha256=DSA8bHVvPSivnEtLS2WmAa89pzGxK8u2MyMHwpJ3HSM,1121
@@ -120,7 +120,7 @@ cirq/contrib/qasm_import/__init__.py,sha256=RKX0vGDC2Pe5rH5rM4ClXdvtrAU16ePFImQp
120
120
  cirq/contrib/qasm_import/_lexer.py,sha256=dG91z4Nsl3uXKjwXoYNnLEQhHovz7QNu49jBXJBt7Rk,3009
121
121
  cirq/contrib/qasm_import/_lexer_test.py,sha256=yaWshvgmwXNHPM6Gy01IPdv_baksSN5FGk1J6fhloRU,7341
122
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
123
+ cirq/contrib/qasm_import/_parser_test.py,sha256=i-QKBCBvHgv2q5enW6HCdEmMy_l7s6MRJsj7ID22mDw,68709
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
@@ -1246,8 +1246,8 @@ cirq/work/sampler.py,sha256=rxbMWvrhu3gfNSBjZKozw28lLKVvBAS_1EGyPdYe8Xg,19041
1246
1246
  cirq/work/sampler_test.py,sha256=SsMrRvLDYELyOAWLKISjkdEfrBwLYWRsT6D8WrsLM3Q,13533
1247
1247
  cirq/work/zeros_sampler.py,sha256=Fs2JWwq0n9zv7_G5Rm-9vPeHUag7uctcMOHg0JTkZpc,2371
1248
1248
  cirq/work/zeros_sampler_test.py,sha256=lQLgQDGBLtfImryys2HzQ2jOSGxHgc7-koVBUhv8qYk,3345
1249
- cirq_core-1.7.0.dev20251028035559.dist-info/licenses/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1250
- cirq_core-1.7.0.dev20251028035559.dist-info/METADATA,sha256=V4zXcqoE990QTFmY9VzWqvWLSCTec-DJVfIMWESOK8s,4757
1251
- cirq_core-1.7.0.dev20251028035559.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
1252
- cirq_core-1.7.0.dev20251028035559.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1253
- cirq_core-1.7.0.dev20251028035559.dist-info/RECORD,,
1249
+ cirq_core-1.7.0.dev20251030221000.dist-info/licenses/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
1250
+ cirq_core-1.7.0.dev20251030221000.dist-info/METADATA,sha256=jCHxJK2S9HhKocMNBmedVsNOP6ecW1L2YVPircjxlvQ,4757
1251
+ cirq_core-1.7.0.dev20251030221000.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
1252
+ cirq_core-1.7.0.dev20251030221000.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
1253
+ cirq_core-1.7.0.dev20251030221000.dist-info/RECORD,,