cirq-core 1.4.0.dev20240523005948__py3-none-any.whl → 1.4.0.dev20240523014335__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 +1 -1
- cirq/sim/classical_simulator.py +18 -2
- cirq/sim/classical_simulator_test.py +38 -0
- {cirq_core-1.4.0.dev20240523005948.dist-info → cirq_core-1.4.0.dev20240523014335.dist-info}/METADATA +1 -1
- {cirq_core-1.4.0.dev20240523005948.dist-info → cirq_core-1.4.0.dev20240523014335.dist-info}/RECORD +8 -8
- {cirq_core-1.4.0.dev20240523005948.dist-info → cirq_core-1.4.0.dev20240523014335.dist-info}/LICENSE +0 -0
- {cirq_core-1.4.0.dev20240523005948.dist-info → cirq_core-1.4.0.dev20240523014335.dist-info}/WHEEL +0 -0
- {cirq_core-1.4.0.dev20240523005948.dist-info → cirq_core-1.4.0.dev20240523014335.dist-info}/top_level.txt +0 -0
cirq/_version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "1.4.0.
|
|
1
|
+
__version__ = "1.4.0.dev20240523014335"
|
cirq/sim/classical_simulator.py
CHANGED
|
@@ -117,12 +117,25 @@ class ClassicalBasisSimState(SimulationState[ClassicalBasisState]):
|
|
|
117
117
|
|
|
118
118
|
Raises:
|
|
119
119
|
ValueError: If initial_state shape for type np.ndarray is not equal to 1.
|
|
120
|
-
If gate is not one of X,
|
|
120
|
+
If gate is not one of X, SWAP, a controlled version of X or SWAP,
|
|
121
|
+
or a measurement.
|
|
121
122
|
"""
|
|
122
123
|
if isinstance(self._state.basis, np.ndarray) and len(self._state.basis.shape) != 1:
|
|
123
124
|
raise ValueError('initial_state shape for type np.ndarray is not equal to 1')
|
|
124
125
|
gate = action.gate if isinstance(action, ops.Operation) else action
|
|
125
126
|
mapped_qubits = [self.qubit_map[i] for i in qubits]
|
|
127
|
+
|
|
128
|
+
if isinstance(gate, ops.ControlledGate):
|
|
129
|
+
control_qubits = mapped_qubits[: gate.num_controls()]
|
|
130
|
+
mapped_qubits = mapped_qubits[gate.num_controls() :]
|
|
131
|
+
|
|
132
|
+
controls_state = tuple(self._state.basis[c] for c in control_qubits)
|
|
133
|
+
if controls_state not in gate.control_values.expand():
|
|
134
|
+
# gate has no effect; controls were off
|
|
135
|
+
return True
|
|
136
|
+
|
|
137
|
+
gate = gate.sub_gate
|
|
138
|
+
|
|
126
139
|
if _is_identity(gate):
|
|
127
140
|
pass
|
|
128
141
|
elif gate == ops.X:
|
|
@@ -138,7 +151,10 @@ class ClassicalBasisSimState(SimulationState[ClassicalBasisState]):
|
|
|
138
151
|
c1, c2, q = mapped_qubits
|
|
139
152
|
self._state.basis[q] ^= self._state.basis[c1] & self._state.basis[c2]
|
|
140
153
|
else:
|
|
141
|
-
raise ValueError(
|
|
154
|
+
raise ValueError(
|
|
155
|
+
f'{gate} is not one of X, SWAP; a controlled version '
|
|
156
|
+
'of X or SWAP; or a measurement'
|
|
157
|
+
)
|
|
142
158
|
return True
|
|
143
159
|
|
|
144
160
|
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from itertools import product
|
|
15
16
|
import numpy as np
|
|
16
17
|
import pytest
|
|
17
18
|
import cirq
|
|
@@ -78,6 +79,43 @@ def test_CCNOT():
|
|
|
78
79
|
np.testing.assert_equal(results, expected_results)
|
|
79
80
|
|
|
80
81
|
|
|
82
|
+
@pytest.mark.parametrize(['initial_state'], [(list(x),) for x in product([0, 1], repeat=4)])
|
|
83
|
+
def test_CCCX(initial_state):
|
|
84
|
+
CCCX = cirq.CCNOT.controlled()
|
|
85
|
+
qubits = cirq.LineQubit.range(4)
|
|
86
|
+
|
|
87
|
+
circuit = cirq.Circuit()
|
|
88
|
+
circuit.append(CCCX(*qubits))
|
|
89
|
+
circuit.append(cirq.measure(qubits, key='key'))
|
|
90
|
+
|
|
91
|
+
final_state = initial_state.copy()
|
|
92
|
+
final_state[-1] ^= all(final_state[:-1])
|
|
93
|
+
|
|
94
|
+
sim = cirq.ClassicalStateSimulator()
|
|
95
|
+
results = sim.simulate(circuit, initial_state=initial_state).measurements['key']
|
|
96
|
+
np.testing.assert_equal(results, final_state)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@pytest.mark.parametrize(['initial_state'], [(list(x),) for x in product([0, 1], repeat=3)])
|
|
100
|
+
def test_CSWAP(initial_state):
|
|
101
|
+
CSWAP = cirq.SWAP.controlled()
|
|
102
|
+
qubits = cirq.LineQubit.range(3)
|
|
103
|
+
circuit = cirq.Circuit()
|
|
104
|
+
|
|
105
|
+
circuit = cirq.Circuit()
|
|
106
|
+
circuit.append(CSWAP(*qubits))
|
|
107
|
+
circuit.append(cirq.measure(qubits, key='key'))
|
|
108
|
+
|
|
109
|
+
a, b, c = initial_state
|
|
110
|
+
if a:
|
|
111
|
+
b, c = c, b
|
|
112
|
+
final_state = [a, b, c]
|
|
113
|
+
|
|
114
|
+
sim = cirq.ClassicalStateSimulator()
|
|
115
|
+
results = sim.simulate(circuit, initial_state=initial_state).measurements['key']
|
|
116
|
+
np.testing.assert_equal(results, final_state)
|
|
117
|
+
|
|
118
|
+
|
|
81
119
|
def test_measurement_gate():
|
|
82
120
|
q0, q1 = cirq.LineQubit.range(2)
|
|
83
121
|
circuit = cirq.Circuit()
|
{cirq_core-1.4.0.dev20240523005948.dist-info → cirq_core-1.4.0.dev20240523014335.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cirq-core
|
|
3
|
-
Version: 1.4.0.
|
|
3
|
+
Version: 1.4.0.dev20240523014335
|
|
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
|
{cirq_core-1.4.0.dev20240523005948.dist-info → cirq_core-1.4.0.dev20240523014335.dist-info}/RECORD
RENAMED
|
@@ -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=
|
|
7
|
+
cirq/_version.py,sha256=8ThAXZwHmhQTug161vJ8hY5Gx7Uyx7OxuyAtP0qO_QI,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=ytePZtNZgKjOF2NiVpUTuotB-JKZmQNOFIFdvXqsxHw,13271
|
|
@@ -887,8 +887,8 @@ cirq/qis/quantum_state_representation.py,sha256=5ybXGqjGSpSZqOn9q6OW6IBOmJs8KQek
|
|
|
887
887
|
cirq/qis/states.py,sha256=PZs1pH6Uw1M9oOXlD7-uDwVGBPTX-8tUy8RTP1Ct_pg,42015
|
|
888
888
|
cirq/qis/states_test.py,sha256=I4fHt5drqG0C36bvmU-H7DfY3zOC8CfiZFzKJvSOnFs,31813
|
|
889
889
|
cirq/sim/__init__.py,sha256=NZlRrk-RxeNOmFLdC54yEeQiiWz7wXNRhGbZKmxCTjA,2342
|
|
890
|
-
cirq/sim/classical_simulator.py,sha256=
|
|
891
|
-
cirq/sim/classical_simulator_test.py,sha256=
|
|
890
|
+
cirq/sim/classical_simulator.py,sha256=orp2WY15HNCJk60Aosq7igO3bjKcWjAAOeU_CiPK_98,9349
|
|
891
|
+
cirq/sim/classical_simulator_test.py,sha256=TxPhVNLoOBPwTlyUCOQoqwid76ZBxQfmN9IPD0yxNHI,12701
|
|
892
892
|
cirq/sim/density_matrix_simulation_state.py,sha256=XRxKsKq13OlXR7429WBbKps_jmOoCBRa6U9PzYrYrTc,14065
|
|
893
893
|
cirq/sim/density_matrix_simulation_state_test.py,sha256=uqSKZrXEPLYO7R3UW2d1y_Yq6CcyJ0drTSCjGbtzBuc,4369
|
|
894
894
|
cirq/sim/density_matrix_simulator.py,sha256=-BIY8JjmzAJDmF6tWcv5lbH1yS7UQIlKicU1AJgttfA,17462
|
|
@@ -1175,8 +1175,8 @@ cirq/work/sampler.py,sha256=JEAeQQRF3bqlO9AkOf4XbrTATDI5f5JgyM_FAUCNxao,19751
|
|
|
1175
1175
|
cirq/work/sampler_test.py,sha256=B2ZsuqGT854gQtBIAh8k0LiG9Vj5wSzcGvkxOUoTcW4,13217
|
|
1176
1176
|
cirq/work/zeros_sampler.py,sha256=x1C7cup66a43n-3tm8QjhiqJa07qcJW10FxNp9jJ59Q,2356
|
|
1177
1177
|
cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
|
|
1178
|
-
cirq_core-1.4.0.
|
|
1179
|
-
cirq_core-1.4.0.
|
|
1180
|
-
cirq_core-1.4.0.
|
|
1181
|
-
cirq_core-1.4.0.
|
|
1182
|
-
cirq_core-1.4.0.
|
|
1178
|
+
cirq_core-1.4.0.dev20240523014335.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
|
|
1179
|
+
cirq_core-1.4.0.dev20240523014335.dist-info/METADATA,sha256=qPq1REiolhtN7rFt8xItGRwlleiYemRv4bGA8ymjGnY,2000
|
|
1180
|
+
cirq_core-1.4.0.dev20240523014335.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
1181
|
+
cirq_core-1.4.0.dev20240523014335.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
|
|
1182
|
+
cirq_core-1.4.0.dev20240523014335.dist-info/RECORD,,
|
{cirq_core-1.4.0.dev20240523005948.dist-info → cirq_core-1.4.0.dev20240523014335.dist-info}/LICENSE
RENAMED
|
File without changes
|
{cirq_core-1.4.0.dev20240523005948.dist-info → cirq_core-1.4.0.dev20240523014335.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|