cirq-core 1.6.0.dev20250428201230__py3-none-any.whl → 1.6.0.dev20250429161116__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/protocols/measurement_key_protocol.py +8 -7
- cirq/protocols/pow_protocol.py +7 -7
- cirq/protocols/qasm.py +5 -3
- cirq/protocols/resolve_parameters.py +5 -3
- cirq/qis/clifford_tableau.py +11 -9
- cirq/qis/measures.py +7 -7
- cirq/qis/quantum_state_representation.py +4 -5
- cirq/qis/states.py +19 -17
- cirq/sim/classical_simulator.py +15 -14
- cirq/sim/clifford/clifford_simulator.py +19 -17
- cirq/sim/clifford/clifford_tableau_simulation_state.py +7 -4
- cirq/sim/clifford/stabilizer_ch_form_simulation_state.py +5 -3
- cirq/sim/clifford/stabilizer_sampler.py +6 -4
- cirq/sim/clifford/stabilizer_simulation_state.py +9 -9
- cirq/sim/clifford/stabilizer_state_ch_form.py +6 -4
- cirq/sim/density_matrix_simulation_state.py +17 -18
- cirq/sim/density_matrix_simulator.py +21 -19
- cirq/sim/density_matrix_utils.py +4 -2
- cirq/sim/mux.py +25 -23
- cirq/sim/simulation_product_state.py +12 -12
- cirq/sim/simulation_product_state_test.py +3 -3
- cirq/sim/simulation_state.py +23 -19
- cirq/sim/simulation_state_base.py +16 -12
- cirq/sim/simulation_state_test.py +1 -1
- cirq/sim/simulator.py +71 -72
- cirq/sim/simulator_base.py +22 -23
- cirq/sim/simulator_base_test.py +12 -9
- cirq/sim/simulator_test.py +12 -8
- cirq/sim/sparse_simulator.py +13 -11
- cirq/sim/state_vector.py +9 -6
- cirq/sim/state_vector_simulation_state.py +20 -20
- cirq/sim/state_vector_simulator.py +13 -10
- cirq/study/flatten_expressions.py +8 -5
- cirq/study/resolver.py +12 -9
- cirq/study/result.py +6 -3
- cirq/study/sweeps.py +17 -14
- cirq/testing/consistent_act_on_test.py +2 -2
- cirq/testing/consistent_controlled_gate_op_test.py +10 -6
- cirq/testing/lin_alg_utils.py +8 -7
- cirq/testing/random_circuit.py +17 -16
- cirq/testing/routing_devices.py +4 -1
- cirq/testing/sample_circuits.py +4 -1
- cirq/transformers/align.py +6 -4
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +9 -7
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +15 -13
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +7 -5
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +10 -8
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry.py +6 -3
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation.py +8 -10
- {cirq_core-1.6.0.dev20250428201230.dist-info → cirq_core-1.6.0.dev20250429161116.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250428201230.dist-info → cirq_core-1.6.0.dev20250429161116.dist-info}/RECORD +56 -56
- {cirq_core-1.6.0.dev20250428201230.dist-info → cirq_core-1.6.0.dev20250429161116.dist-info}/WHEEL +0 -0
- {cirq_core-1.6.0.dev20250428201230.dist-info → cirq_core-1.6.0.dev20250429161116.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250428201230.dist-info → cirq_core-1.6.0.dev20250429161116.dist-info}/top_level.txt +0 -0
cirq/testing/lin_alg_utils.py
CHANGED
|
@@ -11,8 +11,11 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
14
15
|
"""A testing class with utilities for checking linear algebra."""
|
|
15
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
16
19
|
from typing import Optional, TYPE_CHECKING
|
|
17
20
|
|
|
18
21
|
import numpy as np
|
|
@@ -24,7 +27,7 @@ if TYPE_CHECKING:
|
|
|
24
27
|
|
|
25
28
|
|
|
26
29
|
def random_superposition(
|
|
27
|
-
dim: int, *, random_state:
|
|
30
|
+
dim: int, *, random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
28
31
|
) -> np.ndarray:
|
|
29
32
|
"""Returns a random unit-length vector from the uniform distribution.
|
|
30
33
|
|
|
@@ -46,7 +49,7 @@ def random_superposition(
|
|
|
46
49
|
|
|
47
50
|
|
|
48
51
|
def random_density_matrix(
|
|
49
|
-
dim: int, *, random_state:
|
|
52
|
+
dim: int, *, random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
50
53
|
) -> np.ndarray:
|
|
51
54
|
"""Returns a random density matrix distributed with Hilbert-Schmidt measure.
|
|
52
55
|
|
|
@@ -68,9 +71,7 @@ def random_density_matrix(
|
|
|
68
71
|
return mat / np.trace(mat)
|
|
69
72
|
|
|
70
73
|
|
|
71
|
-
def random_unitary(
|
|
72
|
-
dim: int, *, random_state: 'cirq.RANDOM_STATE_OR_SEED_LIKE' = None
|
|
73
|
-
) -> np.ndarray:
|
|
74
|
+
def random_unitary(dim: int, *, random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None) -> np.ndarray:
|
|
74
75
|
"""Returns a random unitary matrix distributed with Haar measure.
|
|
75
76
|
|
|
76
77
|
Args:
|
|
@@ -93,7 +94,7 @@ def random_unitary(
|
|
|
93
94
|
|
|
94
95
|
|
|
95
96
|
def random_orthogonal(
|
|
96
|
-
dim: int, *, random_state:
|
|
97
|
+
dim: int, *, random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
97
98
|
) -> np.ndarray:
|
|
98
99
|
"""Returns a random orthogonal matrix distributed with Haar measure.
|
|
99
100
|
|
|
@@ -139,7 +140,7 @@ def random_special_unitary(
|
|
|
139
140
|
|
|
140
141
|
|
|
141
142
|
def random_special_orthogonal(
|
|
142
|
-
dim: int, *, random_state:
|
|
143
|
+
dim: int, *, random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
143
144
|
) -> np.ndarray:
|
|
144
145
|
"""Returns a random special orthogonal matrix distributed with Haar measure.
|
|
145
146
|
|
cirq/testing/random_circuit.py
CHANGED
|
@@ -12,27 +12,28 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
from typing import Dict, List, Optional, Sequence, TYPE_CHECKING, Union
|
|
16
18
|
|
|
17
19
|
from cirq import circuits, ops, value
|
|
18
20
|
from cirq._doc import document
|
|
19
|
-
from cirq.ops import Qid
|
|
20
21
|
|
|
21
22
|
if TYPE_CHECKING:
|
|
22
23
|
import cirq
|
|
23
24
|
|
|
24
25
|
DEFAULT_GATE_DOMAIN: Dict[ops.Gate, int] = {
|
|
25
|
-
ops.CNOT: 2,
|
|
26
|
-
ops.CZ: 2,
|
|
27
|
-
ops.H: 1,
|
|
28
|
-
ops.ISWAP: 2,
|
|
26
|
+
ops.CNOT: 2, # type: ignore[has-type]
|
|
27
|
+
ops.CZ: 2, # type: ignore[has-type]
|
|
28
|
+
ops.H: 1, # type: ignore[has-type]
|
|
29
|
+
ops.ISWAP: 2, # type: ignore[has-type]
|
|
29
30
|
ops.CZPowGate(): 2,
|
|
30
|
-
ops.S: 1,
|
|
31
|
-
ops.SWAP: 2,
|
|
32
|
-
ops.T: 1,
|
|
33
|
-
ops.X: 1,
|
|
34
|
-
ops.Y: 1,
|
|
35
|
-
ops.Z: 1,
|
|
31
|
+
ops.S: 1, # type: ignore[has-type]
|
|
32
|
+
ops.SWAP: 2, # type: ignore[has-type]
|
|
33
|
+
ops.T: 1, # type: ignore[has-type]
|
|
34
|
+
ops.X: 1, # type: ignore[has-type]
|
|
35
|
+
ops.Y: 1, # type: ignore[has-type]
|
|
36
|
+
ops.Z: 1, # type: ignore[has-type]
|
|
36
37
|
}
|
|
37
38
|
document(
|
|
38
39
|
DEFAULT_GATE_DOMAIN,
|
|
@@ -45,11 +46,11 @@ and Z gates.
|
|
|
45
46
|
|
|
46
47
|
|
|
47
48
|
def random_circuit(
|
|
48
|
-
qubits: Union[Sequence[
|
|
49
|
+
qubits: Union[Sequence[cirq.Qid], int],
|
|
49
50
|
n_moments: int,
|
|
50
51
|
op_density: float,
|
|
51
52
|
gate_domain: Optional[Dict[ops.Gate, int]] = None,
|
|
52
|
-
random_state:
|
|
53
|
+
random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None,
|
|
53
54
|
) -> circuits.Circuit:
|
|
54
55
|
"""Generates a random circuit.
|
|
55
56
|
|
|
@@ -125,9 +126,9 @@ def random_circuit(
|
|
|
125
126
|
|
|
126
127
|
def random_two_qubit_circuit_with_czs(
|
|
127
128
|
num_czs: int = 3,
|
|
128
|
-
q0: Optional[Qid] = None,
|
|
129
|
-
q1: Optional[Qid] = None,
|
|
130
|
-
random_state:
|
|
129
|
+
q0: Optional[cirq.Qid] = None,
|
|
130
|
+
q1: Optional[cirq.Qid] = None,
|
|
131
|
+
random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None,
|
|
131
132
|
) -> circuits.Circuit:
|
|
132
133
|
"""Creates a random two qubit circuit with the given number of CNOTs.
|
|
133
134
|
|
cirq/testing/routing_devices.py
CHANGED
|
@@ -11,8 +11,11 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
14
15
|
"""Provides test devices that can validate circuits during a routing procedure."""
|
|
15
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
16
19
|
from typing import TYPE_CHECKING
|
|
17
20
|
|
|
18
21
|
import networkx as nx
|
|
@@ -39,7 +42,7 @@ class RoutingTestingDevice(devices.Device):
|
|
|
39
42
|
def metadata(self) -> devices.DeviceMetadata:
|
|
40
43
|
return self._metadata
|
|
41
44
|
|
|
42
|
-
def validate_operation(self, operation:
|
|
45
|
+
def validate_operation(self, operation: cirq.Operation) -> None:
|
|
43
46
|
if not self._metadata.qubit_set.issuperset(operation.qubits):
|
|
44
47
|
raise ValueError(f'Qubits not on device: {operation.qubits!r}.')
|
|
45
48
|
|
cirq/testing/sample_circuits.py
CHANGED
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
14
17
|
from typing import TYPE_CHECKING
|
|
15
18
|
|
|
16
19
|
from cirq import circuits, ops
|
|
@@ -19,7 +22,7 @@ if TYPE_CHECKING:
|
|
|
19
22
|
import cirq
|
|
20
23
|
|
|
21
24
|
|
|
22
|
-
def nonoptimal_toffoli_circuit(q0:
|
|
25
|
+
def nonoptimal_toffoli_circuit(q0: cirq.Qid, q1: cirq.Qid, q2: cirq.Qid) -> circuits.Circuit:
|
|
23
26
|
ret = circuits.Circuit(
|
|
24
27
|
ops.Y(q2) ** 0.5,
|
|
25
28
|
ops.X(q2),
|
cirq/transformers/align.py
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
"""Transformer passes which align operations to the left or right of the circuit."""
|
|
16
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
17
19
|
import dataclasses
|
|
18
20
|
from typing import Optional, TYPE_CHECKING
|
|
19
21
|
|
|
@@ -26,8 +28,8 @@ if TYPE_CHECKING:
|
|
|
26
28
|
|
|
27
29
|
@transformer_api.transformer(add_deep_support=True)
|
|
28
30
|
def align_left(
|
|
29
|
-
circuit:
|
|
30
|
-
) ->
|
|
31
|
+
circuit: cirq.AbstractCircuit, *, context: Optional[cirq.TransformerContext] = None
|
|
32
|
+
) -> cirq.Circuit:
|
|
31
33
|
"""Align gates to the left of the circuit.
|
|
32
34
|
|
|
33
35
|
Note that tagged operations with tag in `context.tags_to_ignore` will continue to stay in their
|
|
@@ -58,8 +60,8 @@ def align_left(
|
|
|
58
60
|
|
|
59
61
|
@transformer_api.transformer(add_deep_support=True)
|
|
60
62
|
def align_right(
|
|
61
|
-
circuit:
|
|
62
|
-
) ->
|
|
63
|
+
circuit: cirq.AbstractCircuit, *, context: Optional[cirq.TransformerContext] = None
|
|
64
|
+
) -> cirq.Circuit:
|
|
63
65
|
"""Align gates to the right of the circuit.
|
|
64
66
|
|
|
65
67
|
Note that tagged operations with tag in `context.tags_to_ignore` will continue to stay in their
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
"""Utility methods to decompose Clifford gates into circuits."""
|
|
16
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
17
19
|
import functools
|
|
18
20
|
from typing import List, TYPE_CHECKING
|
|
19
21
|
|
|
@@ -29,7 +31,7 @@ def _X(
|
|
|
29
31
|
q: int,
|
|
30
32
|
args: sim.CliffordTableauSimulationState,
|
|
31
33
|
operations: List[ops.Operation],
|
|
32
|
-
qubits: List[
|
|
34
|
+
qubits: List[cirq.Qid],
|
|
33
35
|
):
|
|
34
36
|
protocols.act_on(ops.X, args, qubits=[qubits[q]], allow_decompose=False)
|
|
35
37
|
operations.append(ops.X(qubits[q]))
|
|
@@ -39,7 +41,7 @@ def _Z(
|
|
|
39
41
|
q: int,
|
|
40
42
|
args: sim.CliffordTableauSimulationState,
|
|
41
43
|
operations: List[ops.Operation],
|
|
42
|
-
qubits: List[
|
|
44
|
+
qubits: List[cirq.Qid],
|
|
43
45
|
):
|
|
44
46
|
protocols.act_on(ops.Z, args, qubits=[qubits[q]], allow_decompose=False)
|
|
45
47
|
operations.append(ops.Z(qubits[q]))
|
|
@@ -49,7 +51,7 @@ def _Sdg(
|
|
|
49
51
|
q: int,
|
|
50
52
|
args: sim.CliffordTableauSimulationState,
|
|
51
53
|
operations: List[ops.Operation],
|
|
52
|
-
qubits: List[
|
|
54
|
+
qubits: List[cirq.Qid],
|
|
53
55
|
):
|
|
54
56
|
# Apply the tableau with S^\{dagger}
|
|
55
57
|
protocols.act_on(ops.S**-1, args, qubits=[qubits[q]], allow_decompose=False)
|
|
@@ -60,7 +62,7 @@ def _H(
|
|
|
60
62
|
q: int,
|
|
61
63
|
args: sim.CliffordTableauSimulationState,
|
|
62
64
|
operations: List[ops.Operation],
|
|
63
|
-
qubits: List[
|
|
65
|
+
qubits: List[cirq.Qid],
|
|
64
66
|
):
|
|
65
67
|
protocols.act_on(ops.H, args, qubits=[qubits[q]], allow_decompose=False)
|
|
66
68
|
operations.append(ops.H(qubits[q]))
|
|
@@ -71,7 +73,7 @@ def _CNOT(
|
|
|
71
73
|
q2: int,
|
|
72
74
|
args: sim.CliffordTableauSimulationState,
|
|
73
75
|
operations: List[ops.Operation],
|
|
74
|
-
qubits: List[
|
|
76
|
+
qubits: List[cirq.Qid],
|
|
75
77
|
):
|
|
76
78
|
protocols.act_on(ops.CNOT, args, qubits=[qubits[q1], qubits[q2]], allow_decompose=False)
|
|
77
79
|
operations.append(ops.CNOT(qubits[q1], qubits[q2]))
|
|
@@ -82,14 +84,14 @@ def _SWAP(
|
|
|
82
84
|
q2: int,
|
|
83
85
|
args: sim.CliffordTableauSimulationState,
|
|
84
86
|
operations: List[ops.Operation],
|
|
85
|
-
qubits: List[
|
|
87
|
+
qubits: List[cirq.Qid],
|
|
86
88
|
):
|
|
87
89
|
protocols.act_on(ops.SWAP, args, qubits=[qubits[q1], qubits[q2]], allow_decompose=False)
|
|
88
90
|
operations.append(ops.SWAP(qubits[q1], qubits[q2]))
|
|
89
91
|
|
|
90
92
|
|
|
91
93
|
def decompose_clifford_tableau_to_operations(
|
|
92
|
-
qubits: List[
|
|
94
|
+
qubits: List[cirq.Qid], clifford_tableau: qis.CliffordTableau
|
|
93
95
|
) -> List[ops.Operation]:
|
|
94
96
|
"""Decompose an n-qubit Clifford Tableau into a list of one/two qubit operations.
|
|
95
97
|
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
from typing import List, Tuple, TYPE_CHECKING
|
|
16
18
|
|
|
17
19
|
import numpy as np
|
|
@@ -70,8 +72,8 @@ def _decompose_abc(matrix: np.ndarray) -> Tuple[np.ndarray, np.ndarray, np.ndarr
|
|
|
70
72
|
|
|
71
73
|
|
|
72
74
|
def _decompose_single_ctrl(
|
|
73
|
-
matrix: np.ndarray, control:
|
|
74
|
-
) -> List[
|
|
75
|
+
matrix: np.ndarray, control: cirq.Qid, target: cirq.Qid
|
|
76
|
+
) -> List[cirq.Operation]:
|
|
75
77
|
"""Decomposes controlled gate with one control.
|
|
76
78
|
|
|
77
79
|
See [1], chapter 5.1.
|
|
@@ -93,7 +95,7 @@ def _decompose_single_ctrl(
|
|
|
93
95
|
return result
|
|
94
96
|
|
|
95
97
|
|
|
96
|
-
def _ccnot_congruent(c0:
|
|
98
|
+
def _ccnot_congruent(c0: cirq.Qid, c1: cirq.Qid, target: cirq.Qid) -> List[cirq.Operation]:
|
|
97
99
|
"""Implements 3-qubit gate 'congruent' to CCNOT.
|
|
98
100
|
|
|
99
101
|
Returns sequence of operations which is equivalent to applying
|
|
@@ -111,8 +113,8 @@ def _ccnot_congruent(c0: 'cirq.Qid', c1: 'cirq.Qid', target: 'cirq.Qid') -> List
|
|
|
111
113
|
|
|
112
114
|
|
|
113
115
|
def decompose_multi_controlled_x(
|
|
114
|
-
controls: List[
|
|
115
|
-
) -> List[
|
|
116
|
+
controls: List[cirq.Qid], target: cirq.Qid, free_qubits: List[cirq.Qid]
|
|
117
|
+
) -> List[cirq.Operation]:
|
|
116
118
|
"""Implements action of multi-controlled Pauli X gate.
|
|
117
119
|
|
|
118
120
|
Result is guaranteed to consist exclusively of 1-qubit, CNOT and CCNOT
|
|
@@ -164,8 +166,8 @@ def decompose_multi_controlled_x(
|
|
|
164
166
|
|
|
165
167
|
|
|
166
168
|
def _decompose_su(
|
|
167
|
-
matrix: np.ndarray, controls: List[
|
|
168
|
-
) -> List[
|
|
169
|
+
matrix: np.ndarray, controls: List[cirq.Qid], target: cirq.Qid
|
|
170
|
+
) -> List[cirq.Operation]:
|
|
169
171
|
"""Decomposes controlled special unitary gate into elementary gates.
|
|
170
172
|
|
|
171
173
|
Result has O(len(controls)) operations.
|
|
@@ -190,10 +192,10 @@ def _decompose_su(
|
|
|
190
192
|
def _decompose_recursive(
|
|
191
193
|
matrix: np.ndarray,
|
|
192
194
|
power: float,
|
|
193
|
-
controls: List[
|
|
194
|
-
target:
|
|
195
|
-
free_qubits: List[
|
|
196
|
-
) -> List[
|
|
195
|
+
controls: List[cirq.Qid],
|
|
196
|
+
target: cirq.Qid,
|
|
197
|
+
free_qubits: List[cirq.Qid],
|
|
198
|
+
) -> List[cirq.Operation]:
|
|
197
199
|
"""Decomposes controlled unitary gate into elementary gates.
|
|
198
200
|
|
|
199
201
|
Result has O(len(controls)^2) operations.
|
|
@@ -215,8 +217,8 @@ def _decompose_recursive(
|
|
|
215
217
|
|
|
216
218
|
|
|
217
219
|
def decompose_multi_controlled_rotation(
|
|
218
|
-
matrix: np.ndarray, controls: List[
|
|
219
|
-
) -> List[
|
|
220
|
+
matrix: np.ndarray, controls: List[cirq.Qid], target: cirq.Qid
|
|
221
|
+
) -> List[cirq.Operation]:
|
|
220
222
|
"""Implements action of multi-controlled unitary gate.
|
|
221
223
|
|
|
222
224
|
Returns a sequence of operations, which is equivalent to applying
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
from typing import Optional, Sequence, Tuple, TYPE_CHECKING
|
|
16
18
|
|
|
17
19
|
import numpy as np
|
|
@@ -32,7 +34,7 @@ def _asinsin(x: float) -> float:
|
|
|
32
34
|
|
|
33
35
|
|
|
34
36
|
def compute_cphase_exponents_for_fsim_decomposition(
|
|
35
|
-
fsim_gate:
|
|
37
|
+
fsim_gate: cirq.FSimGate,
|
|
36
38
|
) -> Sequence[Tuple[float, float]]:
|
|
37
39
|
"""Returns intervals of CZPowGate exponents valid for FSim decomposition.
|
|
38
40
|
|
|
@@ -93,12 +95,12 @@ def compute_cphase_exponents_for_fsim_decomposition(
|
|
|
93
95
|
|
|
94
96
|
|
|
95
97
|
def decompose_cphase_into_two_fsim(
|
|
96
|
-
cphase_gate:
|
|
98
|
+
cphase_gate: cirq.CZPowGate,
|
|
97
99
|
*,
|
|
98
|
-
fsim_gate:
|
|
99
|
-
qubits: Optional[Sequence[
|
|
100
|
+
fsim_gate: cirq.FSimGate,
|
|
101
|
+
qubits: Optional[Sequence[cirq.Qid]] = None,
|
|
100
102
|
atol: float = 1e-8,
|
|
101
|
-
) ->
|
|
103
|
+
) -> cirq.OP_TREE:
|
|
102
104
|
"""Decomposes CZPowGate into two FSimGates.
|
|
103
105
|
|
|
104
106
|
This function implements the decomposition described in section VII F I
|
|
@@ -12,13 +12,15 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
|
|
16
15
|
"""Utility methods for decomposing arbitrary n-qubit (2^n x 2^n) unitary.
|
|
17
16
|
|
|
18
17
|
Based on:
|
|
19
18
|
Synthesis of Quantum Logic Circuits. Tech. rep. 2006,
|
|
20
19
|
https://arxiv.org/abs/quant-ph/0406176
|
|
21
20
|
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
22
24
|
from typing import Callable, Iterable, List, TYPE_CHECKING
|
|
23
25
|
|
|
24
26
|
import numpy as np
|
|
@@ -40,8 +42,8 @@ if TYPE_CHECKING:
|
|
|
40
42
|
|
|
41
43
|
|
|
42
44
|
def quantum_shannon_decomposition(
|
|
43
|
-
qubits:
|
|
44
|
-
) -> Iterable[
|
|
45
|
+
qubits: List[cirq.Qid], u: np.ndarray, atol: float = 1e-8
|
|
46
|
+
) -> Iterable[cirq.Operation]:
|
|
45
47
|
"""Decomposes n-qubit unitary 1-q, 2-q and GlobalPhase gates, preserving global phase.
|
|
46
48
|
|
|
47
49
|
The gates used are CX/YPow/ZPow/CNOT/GlobalPhase/CZ/PhasedXZGate/PhasedXPowGate.
|
|
@@ -139,7 +141,7 @@ def quantum_shannon_decomposition(
|
|
|
139
141
|
yield from _msb_demuxer(qubits, u1, u2)
|
|
140
142
|
|
|
141
143
|
|
|
142
|
-
def _single_qubit_decomposition(qubit:
|
|
144
|
+
def _single_qubit_decomposition(qubit: cirq.Qid, u: np.ndarray) -> Iterable[cirq.Operation]:
|
|
143
145
|
"""Decomposes single-qubit gate, and returns list of operations, keeping phase invariant.
|
|
144
146
|
|
|
145
147
|
Args:
|
|
@@ -183,8 +185,8 @@ def _single_qubit_decomposition(qubit: 'cirq.Qid', u: np.ndarray) -> Iterable['c
|
|
|
183
185
|
|
|
184
186
|
|
|
185
187
|
def _msb_demuxer(
|
|
186
|
-
demux_qubits:
|
|
187
|
-
) -> Iterable[
|
|
188
|
+
demux_qubits: List[cirq.Qid], u1: np.ndarray, u2: np.ndarray
|
|
189
|
+
) -> Iterable[cirq.Operation]:
|
|
188
190
|
"""Demultiplexes a unitary matrix that is multiplexed in its most-significant-qubit.
|
|
189
191
|
|
|
190
192
|
Decomposition structure:
|
|
@@ -246,8 +248,8 @@ def _nth_gray(n: int) -> int:
|
|
|
246
248
|
|
|
247
249
|
|
|
248
250
|
def _multiplexed_cossin(
|
|
249
|
-
cossin_qubits:
|
|
250
|
-
) -> Iterable[
|
|
251
|
+
cossin_qubits: List[cirq.Qid], angles: List[float], rot_func: Callable = ops.ry
|
|
252
|
+
) -> Iterable[cirq.Operation]:
|
|
251
253
|
"""Performs a multiplexed rotation over all qubits in this unitary matrix,
|
|
252
254
|
|
|
253
255
|
Uses ry and rz multiplexing for quantum shannon decomposition
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
"""Analytical decompositions for 2-qubit unitaries when one input qubit is in the |0> state."""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
16
19
|
from typing import List, TYPE_CHECKING
|
|
17
20
|
|
|
18
21
|
import numpy as np
|
|
@@ -25,13 +28,13 @@ if TYPE_CHECKING:
|
|
|
25
28
|
|
|
26
29
|
|
|
27
30
|
def two_qubit_matrix_to_cz_isometry(
|
|
28
|
-
q0:
|
|
29
|
-
q1:
|
|
31
|
+
q0: cirq.Qid,
|
|
32
|
+
q1: cirq.Qid,
|
|
30
33
|
mat: np.ndarray,
|
|
31
34
|
allow_partial_czs: bool = False,
|
|
32
35
|
atol: float = 1e-8,
|
|
33
36
|
clean_operations: bool = True,
|
|
34
|
-
) -> List[
|
|
37
|
+
) -> List[cirq.Operation]:
|
|
35
38
|
"""Decomposes a 2q operation into at-most 2 CZs + 1q rotations; assuming `q0` is initially |0>.
|
|
36
39
|
|
|
37
40
|
The method implements isometry from one to two qubits; assuming qubit `q0` is always in the |0>
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
"""Utility methods for efficiently preparing two qubit states."""
|
|
16
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
17
19
|
from typing import List, TYPE_CHECKING
|
|
18
20
|
|
|
19
21
|
import numpy as np
|
|
@@ -38,12 +40,8 @@ def _1q_matrices_to_ops(g0, g1, q0, q1, include_identity=False):
|
|
|
38
40
|
|
|
39
41
|
|
|
40
42
|
def prepare_two_qubit_state_using_sqrt_iswap(
|
|
41
|
-
q0:
|
|
42
|
-
|
|
43
|
-
state: 'cirq.STATE_VECTOR_LIKE',
|
|
44
|
-
*,
|
|
45
|
-
use_sqrt_iswap_inv: bool = True,
|
|
46
|
-
) -> List['cirq.Operation']:
|
|
43
|
+
q0: cirq.Qid, q1: cirq.Qid, state: cirq.STATE_VECTOR_LIKE, *, use_sqrt_iswap_inv: bool = True
|
|
44
|
+
) -> List[cirq.Operation]:
|
|
47
45
|
"""Prepares the given 2q state from |00> using at-most 1 √iSWAP gate + single qubit rotations.
|
|
48
46
|
|
|
49
47
|
Entangled states are prepared using exactly 1 √iSWAP gate while product states are prepared
|
|
@@ -77,8 +75,8 @@ def prepare_two_qubit_state_using_sqrt_iswap(
|
|
|
77
75
|
|
|
78
76
|
|
|
79
77
|
def prepare_two_qubit_state_using_cz(
|
|
80
|
-
q0:
|
|
81
|
-
) -> List[
|
|
78
|
+
q0: cirq.Qid, q1: cirq.Qid, state: cirq.STATE_VECTOR_LIKE
|
|
79
|
+
) -> List[cirq.Operation]:
|
|
82
80
|
"""Prepares the given 2q state from |00> using at-most 1 CZ gate + single qubit rotations.
|
|
83
81
|
|
|
84
82
|
Entangled states are prepared using exactly 1 CZ gate while product states are prepared
|
|
@@ -110,8 +108,8 @@ def prepare_two_qubit_state_using_cz(
|
|
|
110
108
|
|
|
111
109
|
|
|
112
110
|
def prepare_two_qubit_state_using_iswap(
|
|
113
|
-
q0:
|
|
114
|
-
) -> List[
|
|
111
|
+
q0: cirq.Qid, q1: cirq.Qid, state: cirq.STATE_VECTOR_LIKE, use_iswap_inv: bool = False
|
|
112
|
+
) -> List[cirq.Operation]:
|
|
115
113
|
"""Prepares the given 2q state from |00> using at-most 1 ISWAP gate + single qubit rotations.
|
|
116
114
|
|
|
117
115
|
Entangled states are prepared using exactly 1 ISWAP gate while product states are prepared
|
{cirq_core-1.6.0.dev20250428201230.dist-info → cirq_core-1.6.0.dev20250429161116.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cirq-core
|
|
3
|
-
Version: 1.6.0.
|
|
3
|
+
Version: 1.6.0.dev20250429161116
|
|
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
|