cirq-core 1.7.0.dev20250829182632__py3-none-any.whl → 1.7.0.dev20250830071655__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/_version_test.py +1 -1
- cirq/sim/classical_simulator.py +23 -13
- cirq/sim/classical_simulator_test.py +31 -4
- {cirq_core-1.7.0.dev20250829182632.dist-info → cirq_core-1.7.0.dev20250830071655.dist-info}/METADATA +1 -1
- {cirq_core-1.7.0.dev20250829182632.dist-info → cirq_core-1.7.0.dev20250830071655.dist-info}/RECORD +9 -9
- {cirq_core-1.7.0.dev20250829182632.dist-info → cirq_core-1.7.0.dev20250830071655.dist-info}/WHEEL +0 -0
- {cirq_core-1.7.0.dev20250829182632.dist-info → cirq_core-1.7.0.dev20250830071655.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.7.0.dev20250829182632.dist-info → cirq_core-1.7.0.dev20250830071655.dist-info}/top_level.txt +0 -0
cirq/_version.py
CHANGED
cirq/_version_test.py
CHANGED
cirq/sim/classical_simulator.py
CHANGED
|
@@ -77,7 +77,7 @@ class ClassicalBasisSimState(SimulationState[ClassicalBasisState]):
|
|
|
77
77
|
|
|
78
78
|
def __init__(
|
|
79
79
|
self,
|
|
80
|
-
initial_state: int |
|
|
80
|
+
initial_state: int | Sequence[int] = 0,
|
|
81
81
|
qubits: Sequence[cirq.Qid] | None = None,
|
|
82
82
|
classical_data: cirq.ClassicalDataStore | None = None,
|
|
83
83
|
):
|
|
@@ -85,25 +85,32 @@ class ClassicalBasisSimState(SimulationState[ClassicalBasisState]):
|
|
|
85
85
|
|
|
86
86
|
Args:
|
|
87
87
|
qubits: The qubits to simulate.
|
|
88
|
-
initial_state: The initial state for the simulation.
|
|
88
|
+
initial_state: The initial state for the simulation. Accepts int or Sequence[int].
|
|
89
89
|
classical_data: The classical data container for the simulation.
|
|
90
90
|
|
|
91
91
|
Raises:
|
|
92
92
|
ValueError: If qubits not provided and initial_state is int.
|
|
93
|
-
|
|
93
|
+
If initial_state is not an int or Sequence[int].
|
|
94
|
+
If initial_state is a np.ndarray and its shape is not 1-dimensional.
|
|
94
95
|
|
|
95
96
|
An initial_state value of type integer is parsed in big endian order.
|
|
96
97
|
"""
|
|
97
98
|
if isinstance(initial_state, int):
|
|
98
99
|
if qubits is None:
|
|
99
|
-
raise ValueError('qubits must be provided if initial_state is not
|
|
100
|
+
raise ValueError('qubits must be provided if initial_state is not Sequence[int]')
|
|
100
101
|
state = ClassicalBasisState(
|
|
101
102
|
big_endian_int_to_bits(initial_state, bit_count=len(qubits))
|
|
102
103
|
)
|
|
103
|
-
elif isinstance(initial_state,
|
|
104
|
-
|
|
104
|
+
elif isinstance(initial_state, np.ndarray):
|
|
105
|
+
if initial_state.ndim != 1:
|
|
106
|
+
raise ValueError(
|
|
107
|
+
f'initial_state must be 1-dimensional, got shape {initial_state.shape}'
|
|
108
|
+
)
|
|
109
|
+
state = ClassicalBasisState(list(initial_state))
|
|
110
|
+
elif isinstance(initial_state, Sequence) and not isinstance(initial_state, (str, bytes)):
|
|
111
|
+
state = ClassicalBasisState(list(initial_state))
|
|
105
112
|
else:
|
|
106
|
-
raise ValueError('initial_state must be an int or
|
|
113
|
+
raise ValueError('initial_state must be an int or Sequence[int]')
|
|
107
114
|
super().__init__(state=state, qubits=qubits, classical_data=classical_data)
|
|
108
115
|
|
|
109
116
|
def _act_on_fallback_(self, action, qubits: Sequence[cirq.Qid], allow_decompose: bool = True):
|
|
@@ -118,12 +125,9 @@ class ClassicalBasisSimState(SimulationState[ClassicalBasisState]):
|
|
|
118
125
|
True if the operation was applied successfully.
|
|
119
126
|
|
|
120
127
|
Raises:
|
|
121
|
-
ValueError: If
|
|
122
|
-
|
|
123
|
-
or a measurement.
|
|
128
|
+
ValueError: If gate is not one of X, SWAP, QubitPermutationGate, a controlled version
|
|
129
|
+
of X or SWAP, or a measurement.
|
|
124
130
|
"""
|
|
125
|
-
if isinstance(self._state.basis, np.ndarray) and len(self._state.basis.shape) != 1:
|
|
126
|
-
raise ValueError('initial_state shape for type np.ndarray is not equal to 1')
|
|
127
131
|
gate = action.gate if isinstance(action, ops.Operation) else action
|
|
128
132
|
mapped_qubits = [self.qubit_map[i] for i in qubits]
|
|
129
133
|
|
|
@@ -152,9 +156,15 @@ class ClassicalBasisSimState(SimulationState[ClassicalBasisState]):
|
|
|
152
156
|
elif gate == ops.TOFFOLI:
|
|
153
157
|
c1, c2, q = mapped_qubits
|
|
154
158
|
self._state.basis[q] ^= self._state.basis[c1] & self._state.basis[c2]
|
|
159
|
+
elif isinstance(gate, ops.QubitPermutationGate):
|
|
160
|
+
perm = gate.permutation
|
|
161
|
+
basis = self._state.basis
|
|
162
|
+
original_values = [basis[q] for q in mapped_qubits]
|
|
163
|
+
for i, q in enumerate(mapped_qubits):
|
|
164
|
+
basis[perm[i]] = original_values[i]
|
|
155
165
|
else:
|
|
156
166
|
raise ValueError(
|
|
157
|
-
f'{gate} is not one of X, SWAP; a controlled version '
|
|
167
|
+
f'{gate} is not one of X, SWAP, QubitPermutationGate; a controlled version '
|
|
158
168
|
'of X or SWAP; or a measurement'
|
|
159
169
|
)
|
|
160
170
|
return True
|
|
@@ -60,6 +60,25 @@ def test_Swap():
|
|
|
60
60
|
np.testing.assert_equal(results, expected_results)
|
|
61
61
|
|
|
62
62
|
|
|
63
|
+
@pytest.mark.parametrize(
|
|
64
|
+
"n,perm,state",
|
|
65
|
+
[
|
|
66
|
+
(n, np.random.permutation(n).tolist(), np.random.choice(2, size=n))
|
|
67
|
+
for n in np.random.randint(3, 8, size=10)
|
|
68
|
+
],
|
|
69
|
+
)
|
|
70
|
+
def test_qubit_permutation_gate(n, perm, state):
|
|
71
|
+
qubits = cirq.LineQubit.range(n)
|
|
72
|
+
perm_gate = cirq.QubitPermutationGate(perm)
|
|
73
|
+
circuit = cirq.Circuit(perm_gate(*qubits), cirq.measure(*qubits, key='key'))
|
|
74
|
+
sim = cirq.ClassicalStateSimulator()
|
|
75
|
+
result = sim.simulate(circuit, initial_state=state)
|
|
76
|
+
expected = [0] * n
|
|
77
|
+
for i in range(n):
|
|
78
|
+
expected[perm[i]] = state[i]
|
|
79
|
+
np.testing.assert_equal(result.measurements['key'], expected)
|
|
80
|
+
|
|
81
|
+
|
|
63
82
|
def test_CCNOT():
|
|
64
83
|
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
65
84
|
circuit = cirq.Circuit()
|
|
@@ -209,6 +228,14 @@ def test_multiple_gates_order():
|
|
|
209
228
|
np.testing.assert_equal(results, expected_results)
|
|
210
229
|
|
|
211
230
|
|
|
231
|
+
def test_tuple_initial_state():
|
|
232
|
+
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
233
|
+
circuit = cirq.Circuit(cirq.X(q0), cirq.measure(q0, q1, q2, key='key'))
|
|
234
|
+
sim = cirq.ClassicalStateSimulator()
|
|
235
|
+
result = sim.simulate(circuit, initial_state=(0, 1, 0))
|
|
236
|
+
np.testing.assert_equal(result.measurements['key'], [1, 1, 0])
|
|
237
|
+
|
|
238
|
+
|
|
212
239
|
def test_param_resolver():
|
|
213
240
|
gate = cirq.CNOT ** sympy.Symbol('t')
|
|
214
241
|
q0, q1 = cirq.LineQubit.range(2)
|
|
@@ -333,11 +360,11 @@ def test_create_invalid_partial_simulation_state_from_np():
|
|
|
333
360
|
qs = cirq.LineQubit.range(2)
|
|
334
361
|
classical_data = cirq.value.ClassicalDataDictionaryStore()
|
|
335
362
|
sim = cirq.ClassicalStateSimulator()
|
|
336
|
-
|
|
337
|
-
initial_state=initial_state, qubits=qs, classical_data=classical_data
|
|
338
|
-
)
|
|
363
|
+
|
|
339
364
|
with pytest.raises(ValueError):
|
|
340
|
-
|
|
365
|
+
sim._create_partial_simulation_state(
|
|
366
|
+
initial_state=initial_state, qubits=qs, classical_data=classical_data
|
|
367
|
+
)
|
|
341
368
|
|
|
342
369
|
|
|
343
370
|
def test_noise_model():
|
{cirq_core-1.7.0.dev20250829182632.dist-info → cirq_core-1.7.0.dev20250830071655.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cirq-core
|
|
3
|
-
Version: 1.7.0.
|
|
3
|
+
Version: 1.7.0.dev20250830071655
|
|
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.7.0.dev20250829182632.dist-info → cirq_core-1.7.0.dev20250830071655.dist-info}/RECORD
RENAMED
|
@@ -4,8 +4,8 @@ cirq/_compat_test.py,sha256=emXpdD5ZvwLRlFAoQB8YatmZyU3b4e9jg6FppMTUhkU,33900
|
|
|
4
4
|
cirq/_doc.py,sha256=BrnoABo1hk5RgB3Cgww4zLHUfiyFny0F1V-tOMCbdaU,2909
|
|
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=
|
|
8
|
-
cirq/_version_test.py,sha256=
|
|
7
|
+
cirq/_version.py,sha256=89_n9l7GTTFr5L0DdWoffVJrYaceWrThnFNbpquDK9s,1206
|
|
8
|
+
cirq/_version_test.py,sha256=zwzPZMxwnURyDdJQONG4_yX15orDvG3INfbsTqFa2nA,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
|
|
@@ -932,8 +932,8 @@ cirq/qis/quantum_state_representation.py,sha256=usrQ4eTty-rGnG3w9nvWmz0Yb9Vt83q3
|
|
|
932
932
|
cirq/qis/states.py,sha256=FkUp-pOj_a1rd6U9t3xaq7PK8KPNKsq54AWmkpLulDY,41775
|
|
933
933
|
cirq/qis/states_test.py,sha256=vTvZE0Y-WL7gD7g5gy0HendmrHfbh-qPZ6KsDJH7aAg,31849
|
|
934
934
|
cirq/sim/__init__.py,sha256=J209uAbjmgzER-48Q-FkRUWQ1FlG6-1c7GK11owZIW4,3452
|
|
935
|
-
cirq/sim/classical_simulator.py,sha256=
|
|
936
|
-
cirq/sim/classical_simulator_test.py,sha256=
|
|
935
|
+
cirq/sim/classical_simulator.py,sha256=nGpFSpntqOdmzI2TV5uIBbkJbwoHIXrBZhN62ksHccc,9793
|
|
936
|
+
cirq/sim/classical_simulator_test.py,sha256=SUR9PSk8LDoX3BRnUMD4efJpLe435ofgkgcXM3_TAEs,13646
|
|
937
937
|
cirq/sim/density_matrix_simulation_state.py,sha256=EW_iOJutp5jKJfM9gZhBjkAkD7ZLmukN3t8mP0quzLE,13968
|
|
938
938
|
cirq/sim/density_matrix_simulation_state_test.py,sha256=bjiDTclg9g83dLfmuYpZxMy1o_JlucRbbKXw8wgG20I,4469
|
|
939
939
|
cirq/sim/density_matrix_simulator.py,sha256=ZvXfKs0IxBTtu93Eq207WA9hXXv4CUfvxyAzq3eXAEc,17490
|
|
@@ -1234,8 +1234,8 @@ cirq/work/sampler.py,sha256=rxbMWvrhu3gfNSBjZKozw28lLKVvBAS_1EGyPdYe8Xg,19041
|
|
|
1234
1234
|
cirq/work/sampler_test.py,sha256=SsMrRvLDYELyOAWLKISjkdEfrBwLYWRsT6D8WrsLM3Q,13533
|
|
1235
1235
|
cirq/work/zeros_sampler.py,sha256=Fs2JWwq0n9zv7_G5Rm-9vPeHUag7uctcMOHg0JTkZpc,2371
|
|
1236
1236
|
cirq/work/zeros_sampler_test.py,sha256=lQLgQDGBLtfImryys2HzQ2jOSGxHgc7-koVBUhv8qYk,3345
|
|
1237
|
-
cirq_core-1.7.0.
|
|
1238
|
-
cirq_core-1.7.0.
|
|
1239
|
-
cirq_core-1.7.0.
|
|
1240
|
-
cirq_core-1.7.0.
|
|
1241
|
-
cirq_core-1.7.0.
|
|
1237
|
+
cirq_core-1.7.0.dev20250830071655.dist-info/licenses/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
|
|
1238
|
+
cirq_core-1.7.0.dev20250830071655.dist-info/METADATA,sha256=tmV0lKSVxxOWAH0P9c2dy8yqwZ_SlV-Uh_J9TPUhNGE,4819
|
|
1239
|
+
cirq_core-1.7.0.dev20250830071655.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
1240
|
+
cirq_core-1.7.0.dev20250830071655.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
|
|
1241
|
+
cirq_core-1.7.0.dev20250830071655.dist-info/RECORD,,
|
{cirq_core-1.7.0.dev20250829182632.dist-info → cirq_core-1.7.0.dev20250830071655.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|