cirq-core 1.6.0.dev20250702012506__py3-none-any.whl → 1.6.0.dev20250702211226__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/circuits/circuit.py +4 -2
- cirq/circuits/circuit_operation.py +2 -2
- cirq/circuits/circuit_test.py +157 -148
- cirq/circuits/moment_test.py +61 -51
- cirq/circuits/optimization_pass.py +1 -1
- cirq/circuits/text_diagram_drawer.py +6 -6
- cirq/conftest.py +4 -3
- cirq/contrib/acquaintance/bipartite_test.py +10 -8
- cirq/contrib/acquaintance/devices_test.py +3 -3
- cirq/contrib/acquaintance/executor_test.py +8 -6
- cirq/contrib/acquaintance/gates.py +1 -1
- cirq/contrib/acquaintance/gates_test.py +18 -16
- cirq/contrib/acquaintance/inspection_utils.py +7 -3
- cirq/contrib/acquaintance/permutation_test.py +24 -17
- cirq/contrib/acquaintance/shift_swap_network_test.py +7 -6
- cirq/contrib/acquaintance/strategies/quartic_paired_test.py +8 -6
- cirq/contrib/bayesian_network/bayesian_network_gate.py +2 -2
- cirq/contrib/bayesian_network/bayesian_network_gate_test.py +10 -8
- cirq/contrib/circuitdag/circuit_dag.py +2 -2
- cirq/contrib/circuitdag/circuit_dag_test.py +15 -15
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +7 -3
- cirq/contrib/graph_device/graph_device.py +6 -5
- cirq/contrib/graph_device/graph_device_test.py +16 -14
- cirq/contrib/graph_device/hypergraph.py +2 -2
- cirq/contrib/graph_device/hypergraph_test.py +11 -11
- cirq/contrib/graph_device/uniform_graph_device_test.py +9 -3
- cirq/contrib/hacks/disable_validation.py +4 -1
- cirq/contrib/json.py +2 -2
- cirq/contrib/noise_models/noise_models.py +5 -5
- cirq/contrib/noise_models/noise_models_test.py +4 -0
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +7 -6
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +6 -9
- cirq/contrib/qcircuit/qcircuit_diagram_info.py +1 -1
- cirq/contrib/qcircuit/qcircuit_diagram_info_test.py +2 -1
- cirq/contrib/qcircuit/qcircuit_pdf.py +1 -1
- cirq/contrib/quantum_volume/quantum_volume_test.py +17 -16
- cirq/contrib/quimb/density_matrix.py +1 -1
- cirq/contrib/quimb/density_matrix_test.py +7 -7
- cirq/devices/noise_model_test.py +16 -14
- {cirq_core-1.6.0.dev20250702012506.dist-info → cirq_core-1.6.0.dev20250702211226.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250702012506.dist-info → cirq_core-1.6.0.dev20250702211226.dist-info}/RECORD +46 -46
- {cirq_core-1.6.0.dev20250702012506.dist-info → cirq_core-1.6.0.dev20250702211226.dist-info}/WHEEL +0 -0
- {cirq_core-1.6.0.dev20250702012506.dist-info → cirq_core-1.6.0.dev20250702211226.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250702012506.dist-info → cirq_core-1.6.0.dev20250702211226.dist-info}/top_level.txt +0 -0
|
@@ -30,7 +30,9 @@ class ComputationalBasisState(cirq.qis.QuantumStateRepresentation):
|
|
|
30
30
|
def copy(self, deep_copy_buffers: bool = True) -> ComputationalBasisState:
|
|
31
31
|
return ComputationalBasisState(self.basis) # pragma: no cover
|
|
32
32
|
|
|
33
|
-
def measure(
|
|
33
|
+
def measure(
|
|
34
|
+
self, axes: Sequence[int], seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
35
|
+
) -> list[int]:
|
|
34
36
|
return [self.basis[i] for i in axes]
|
|
35
37
|
|
|
36
38
|
|
|
@@ -49,7 +51,7 @@ class ComputationalBasisSimState(cirq.SimulationState[ComputationalBasisState]):
|
|
|
49
51
|
return True
|
|
50
52
|
|
|
51
53
|
|
|
52
|
-
def create_test_circuit():
|
|
54
|
+
def create_test_circuit() -> cirq.Circuit:
|
|
53
55
|
q0, q1 = cirq.LineQid.range(2, dimension=3)
|
|
54
56
|
x = cirq.XPowGate(dimension=3)
|
|
55
57
|
return cirq.Circuit(
|
|
@@ -143,7 +145,9 @@ class ComputationalBasisProductState(cirq.qis.QuantumStateRepresentation):
|
|
|
143
145
|
def copy(self, deep_copy_buffers: bool = True) -> ComputationalBasisProductState:
|
|
144
146
|
return ComputationalBasisProductState(self.basis)
|
|
145
147
|
|
|
146
|
-
def measure(
|
|
148
|
+
def measure(
|
|
149
|
+
self, axes: Sequence[int], seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
150
|
+
) -> list[int]:
|
|
147
151
|
return [self.basis[i] for i in axes]
|
|
148
152
|
|
|
149
153
|
def kron(self, other: ComputationalBasisProductState) -> ComputationalBasisProductState:
|
|
@@ -16,7 +16,7 @@ from __future__ import annotations
|
|
|
16
16
|
|
|
17
17
|
import abc
|
|
18
18
|
import itertools
|
|
19
|
-
from typing import cast, Iterable, TYPE_CHECKING
|
|
19
|
+
from typing import Any, cast, Hashable, Iterable, NoReturn, TYPE_CHECKING
|
|
20
20
|
|
|
21
21
|
from cirq import devices, ops, value
|
|
22
22
|
from cirq.contrib.graph_device.hypergraph import UndirectedHypergraph
|
|
@@ -98,7 +98,7 @@ def is_crosstalk_graph(graph: UndirectedHypergraph) -> bool:
|
|
|
98
98
|
return True
|
|
99
99
|
|
|
100
100
|
|
|
101
|
-
def raise_crosstalk_error(*ops: ops.Operation):
|
|
101
|
+
def raise_crosstalk_error(*ops: ops.Operation) -> NoReturn:
|
|
102
102
|
raise ValueError(f'crosstalk on {ops}')
|
|
103
103
|
|
|
104
104
|
|
|
@@ -156,11 +156,11 @@ class UndirectedGraphDevice(devices.Device):
|
|
|
156
156
|
return cast(tuple['cirq.Qid', ...], tuple(sorted(self.device_graph.vertices)))
|
|
157
157
|
|
|
158
158
|
@property
|
|
159
|
-
def edges(self):
|
|
159
|
+
def edges(self) -> tuple[frozenset[Hashable], ...]:
|
|
160
160
|
return tuple(sorted(self.device_graph.edges))
|
|
161
161
|
|
|
162
162
|
@property
|
|
163
|
-
def labelled_edges(self):
|
|
163
|
+
def labelled_edges(self) -> dict[frozenset, Any]:
|
|
164
164
|
return self.device_graph.labelled_edges
|
|
165
165
|
|
|
166
166
|
def get_device_edge_from_op(self, operation: ops.Operation) -> UndirectedGraphDeviceEdge:
|
|
@@ -185,6 +185,7 @@ class UndirectedGraphDevice(devices.Device):
|
|
|
185
185
|
self.crosstalk_graph._adjacency_lists.get(frozenset(operation.qubits), ())
|
|
186
186
|
)
|
|
187
187
|
for crosstalk_edge in adjacent_crosstalk_edges:
|
|
188
|
+
# pylint: disable=unreachable
|
|
188
189
|
label = self.crosstalk_graph.labelled_edges[crosstalk_edge]
|
|
189
190
|
validator = (
|
|
190
191
|
raise_crosstalk_error(operation, *other_operations) if (label is None) else label
|
|
@@ -194,7 +195,7 @@ class UndirectedGraphDevice(devices.Device):
|
|
|
194
195
|
):
|
|
195
196
|
validator(operation, *crosstalk_operations)
|
|
196
197
|
|
|
197
|
-
def validate_moment(self, moment: cirq.Moment):
|
|
198
|
+
def validate_moment(self, moment: cirq.Moment) -> None:
|
|
198
199
|
super().validate_moment(moment)
|
|
199
200
|
ops = moment.operations
|
|
200
201
|
for i, op in enumerate(ops):
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
+
from typing import Any, Hashable, Iterable
|
|
18
|
+
|
|
17
19
|
import pytest
|
|
18
20
|
|
|
19
21
|
import cirq
|
|
@@ -21,7 +23,7 @@ import cirq.contrib.graph_device as ccgd
|
|
|
21
23
|
import cirq.contrib.graph_device.graph_device as ccgdgd
|
|
22
24
|
|
|
23
25
|
|
|
24
|
-
def test_fixed_duration_undirected_graph_device_edge_eq():
|
|
26
|
+
def test_fixed_duration_undirected_graph_device_edge_eq() -> None:
|
|
25
27
|
e = ccgd.FixedDurationUndirectedGraphDeviceEdge(cirq.Duration(picos=4))
|
|
26
28
|
f = ccgd.FixedDurationUndirectedGraphDeviceEdge(cirq.Duration(picos=4))
|
|
27
29
|
g = ccgd.FixedDurationUndirectedGraphDeviceEdge(cirq.Duration(picos=5))
|
|
@@ -30,15 +32,15 @@ def test_fixed_duration_undirected_graph_device_edge_eq():
|
|
|
30
32
|
assert e != 4
|
|
31
33
|
|
|
32
34
|
|
|
33
|
-
def test_unconstrained_undirected_graph_device_edge_eq():
|
|
35
|
+
def test_unconstrained_undirected_graph_device_edge_eq() -> None:
|
|
34
36
|
e = ccgdgd._UnconstrainedUndirectedGraphDeviceEdge()
|
|
35
37
|
f = ccgd.UnconstrainedUndirectedGraphDeviceEdge
|
|
36
38
|
assert e == f
|
|
37
39
|
assert e != 3
|
|
38
40
|
|
|
39
41
|
|
|
40
|
-
def test_is_undirected_device_graph():
|
|
41
|
-
assert not ccgd.is_undirected_device_graph('abc')
|
|
42
|
+
def test_is_undirected_device_graph() -> None:
|
|
43
|
+
assert not ccgd.is_undirected_device_graph('abc') # type: ignore[arg-type]
|
|
42
44
|
graph = ccgd.UndirectedHypergraph()
|
|
43
45
|
assert ccgd.is_undirected_device_graph(graph)
|
|
44
46
|
a, b, c, d, e = cirq.LineQubit.range(5)
|
|
@@ -52,9 +54,9 @@ def test_is_undirected_device_graph():
|
|
|
52
54
|
assert not ccgd.is_undirected_device_graph(graph)
|
|
53
55
|
|
|
54
56
|
|
|
55
|
-
def test_is_crosstalk_graph():
|
|
57
|
+
def test_is_crosstalk_graph() -> None:
|
|
56
58
|
a, b, c, d, e, f = cirq.LineQubit.range(6)
|
|
57
|
-
assert not ccgd.is_crosstalk_graph('abc')
|
|
59
|
+
assert not ccgd.is_crosstalk_graph('abc') # type: ignore[arg-type]
|
|
58
60
|
graph = ccgd.UndirectedHypergraph()
|
|
59
61
|
graph.add_vertex('abc')
|
|
60
62
|
assert not ccgd.is_crosstalk_graph(graph)
|
|
@@ -76,14 +78,14 @@ def test_is_crosstalk_graph():
|
|
|
76
78
|
assert not ccgd.is_crosstalk_graph(graph)
|
|
77
79
|
|
|
78
80
|
|
|
79
|
-
def test_unconstrained_undirected_graph_device_edge():
|
|
81
|
+
def test_unconstrained_undirected_graph_device_edge() -> None:
|
|
80
82
|
edge = ccgd.UnconstrainedUndirectedGraphDeviceEdge
|
|
81
83
|
qubits = cirq.LineQubit.range(2)
|
|
82
84
|
assert edge.duration_of(cirq.X(qubits[0])) == cirq.Duration(picos=0)
|
|
83
85
|
assert edge.duration_of(cirq.CZ(*qubits[:2])) == cirq.Duration(picos=0)
|
|
84
86
|
|
|
85
87
|
|
|
86
|
-
def test_graph_device():
|
|
88
|
+
def test_graph_device() -> None:
|
|
87
89
|
one_qubit_duration = cirq.Duration(picos=10)
|
|
88
90
|
two_qubit_duration = cirq.Duration(picos=1)
|
|
89
91
|
one_qubit_edge = ccgd.FixedDurationUndirectedGraphDeviceEdge(one_qubit_duration)
|
|
@@ -95,7 +97,7 @@ def test_graph_device():
|
|
|
95
97
|
|
|
96
98
|
n_qubits = 4
|
|
97
99
|
qubits = cirq.LineQubit.range(n_qubits)
|
|
98
|
-
edges = {
|
|
100
|
+
edges: dict[Iterable[Hashable], Any] = {
|
|
99
101
|
(cirq.LineQubit(i), cirq.LineQubit((i + 1) % n_qubits)): two_qubit_edge
|
|
100
102
|
for i in range(n_qubits)
|
|
101
103
|
}
|
|
@@ -111,8 +113,8 @@ def test_graph_device():
|
|
|
111
113
|
|
|
112
114
|
assert ccgd.is_undirected_device_graph(device_graph)
|
|
113
115
|
with pytest.raises(TypeError):
|
|
114
|
-
ccgd.UndirectedGraphDevice('abc')
|
|
115
|
-
constraint_edges = {
|
|
116
|
+
ccgd.UndirectedGraphDevice('abc') # type: ignore[arg-type]
|
|
117
|
+
constraint_edges: dict[Iterable[Hashable], Any] = {
|
|
116
118
|
(frozenset(cirq.LineQubit.range(2)), frozenset(cirq.LineQubit.range(2, 4))): None,
|
|
117
119
|
(
|
|
118
120
|
frozenset(cirq.LineQubit.range(1, 3)),
|
|
@@ -123,7 +125,7 @@ def test_graph_device():
|
|
|
123
125
|
assert ccgd.is_crosstalk_graph(crosstalk_graph)
|
|
124
126
|
|
|
125
127
|
with pytest.raises(TypeError):
|
|
126
|
-
ccgd.UndirectedGraphDevice(device_graph, crosstalk_graph='abc')
|
|
128
|
+
ccgd.UndirectedGraphDevice(device_graph, crosstalk_graph='abc') # type: ignore[arg-type]
|
|
127
129
|
|
|
128
130
|
graph_device = ccgd.UndirectedGraphDevice(device_graph)
|
|
129
131
|
assert graph_device.crosstalk_graph == ccgd.UndirectedHypergraph()
|
|
@@ -141,7 +143,7 @@ def test_graph_device():
|
|
|
141
143
|
with pytest.raises(ValueError):
|
|
142
144
|
graph_device.validate_operation(cirq.CNOT(qubits[0], qubits[2]))
|
|
143
145
|
with pytest.raises(AttributeError):
|
|
144
|
-
graph_device.validate_operation(list((2, 3)))
|
|
146
|
+
graph_device.validate_operation(list((2, 3))) # type: ignore[arg-type]
|
|
145
147
|
|
|
146
148
|
moment = cirq.Moment([cirq.CNOT(*qubits[:2]), cirq.CNOT(*qubits[2:])])
|
|
147
149
|
with pytest.raises(ValueError):
|
|
@@ -155,7 +157,7 @@ def test_graph_device():
|
|
|
155
157
|
graph_device.validate_moment(moment)
|
|
156
158
|
|
|
157
159
|
|
|
158
|
-
def test_graph_device_copy_and_add():
|
|
160
|
+
def test_graph_device_copy_and_add() -> None:
|
|
159
161
|
a, b, c, d, e, f = cirq.LineQubit.range(6)
|
|
160
162
|
device_graph = ccgd.UndirectedHypergraph(labelled_edges={(a, b): None, (c, d): None})
|
|
161
163
|
crosstalk_graph = ccgd.UndirectedHypergraph(
|
|
@@ -71,7 +71,7 @@ class UndirectedHypergraph:
|
|
|
71
71
|
self._adjacency_lists[neighbor].difference_update((edge,))
|
|
72
72
|
del self._adjacency_lists[vertex]
|
|
73
73
|
|
|
74
|
-
def remove_vertices(self, vertices):
|
|
74
|
+
def remove_vertices(self, vertices) -> None:
|
|
75
75
|
for vertex in vertices:
|
|
76
76
|
self.remove_vertex(vertex)
|
|
77
77
|
|
|
@@ -82,7 +82,7 @@ class UndirectedHypergraph:
|
|
|
82
82
|
self._adjacency_lists[vertex].update((vertices,))
|
|
83
83
|
self._labelled_edges[vertices] = label
|
|
84
84
|
|
|
85
|
-
def add_edges(self, edges: dict[Iterable[Hashable], Any]):
|
|
85
|
+
def add_edges(self, edges: dict[Iterable[Hashable], Any]) -> None:
|
|
86
86
|
for vertices, label in edges.items():
|
|
87
87
|
self.add_edge(vertices, label)
|
|
88
88
|
|
|
@@ -21,7 +21,7 @@ import pytest
|
|
|
21
21
|
import cirq.contrib.graph_device as ccgd
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
def test_update_edge_label():
|
|
24
|
+
def test_update_edge_label() -> None:
|
|
25
25
|
edge = frozenset(range(3))
|
|
26
26
|
graph = ccgd.UndirectedHypergraph(labelled_edges={edge: 'a'})
|
|
27
27
|
assert graph.labelled_edges[edge] == 'a'
|
|
@@ -29,7 +29,7 @@ def test_update_edge_label():
|
|
|
29
29
|
assert graph.labelled_edges[edge] == 'b'
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
def test_hypergraph():
|
|
32
|
+
def test_hypergraph() -> None:
|
|
33
33
|
vertices = range(4)
|
|
34
34
|
graph = ccgd.UndirectedHypergraph(vertices=vertices)
|
|
35
35
|
assert graph.vertices == tuple(vertices)
|
|
@@ -55,7 +55,7 @@ def test_hypergraph():
|
|
|
55
55
|
for _ in range(10)
|
|
56
56
|
],
|
|
57
57
|
)
|
|
58
|
-
def test_eq(vertices, edges):
|
|
58
|
+
def test_eq(vertices, edges) -> None:
|
|
59
59
|
vertices = set(vertices).union(*edges)
|
|
60
60
|
graph_initialized = ccgd.UndirectedHypergraph(vertices=vertices, labelled_edges=edges)
|
|
61
61
|
graph_added_parallel = ccgd.UndirectedHypergraph()
|
|
@@ -69,15 +69,15 @@ def test_eq(vertices, edges):
|
|
|
69
69
|
assert graph_initialized == graph_added_parallel == graph_added_sequential
|
|
70
70
|
|
|
71
71
|
|
|
72
|
-
def test_random_hypergraph():
|
|
72
|
+
def test_random_hypergraph() -> None:
|
|
73
73
|
n_vertices = 4
|
|
74
74
|
graph = ccgd.UndirectedHypergraph.random(n_vertices, {1: 1.0})
|
|
75
|
-
assert sorted(graph.vertices) == sorted(range(n_vertices))
|
|
75
|
+
assert sorted(graph.vertices) == sorted(range(n_vertices)) # type: ignore[type-var]
|
|
76
76
|
assert set(graph.labelled_edges.values()) == set((None,))
|
|
77
77
|
assert tuple(len(edge) for edge in graph.edges) == (1,) * n_vertices
|
|
78
78
|
|
|
79
79
|
|
|
80
|
-
def test_copy():
|
|
80
|
+
def test_copy() -> None:
|
|
81
81
|
graph_original = ccgd.UndirectedHypergraph(labelled_edges={(0, 1): None})
|
|
82
82
|
graph_copy = graph_original.__copy__()
|
|
83
83
|
assert graph_copy == graph_original
|
|
@@ -85,20 +85,20 @@ def test_copy():
|
|
|
85
85
|
assert graph_copy != graph_original
|
|
86
86
|
|
|
87
87
|
|
|
88
|
-
def test_iadd():
|
|
88
|
+
def test_iadd() -> None:
|
|
89
89
|
graph = ccgd.UndirectedHypergraph(labelled_edges={(0, 1): None})
|
|
90
90
|
addend = ccgd.UndirectedHypergraph(labelled_edges={(1, 2): None})
|
|
91
91
|
graph += addend
|
|
92
92
|
assert set(graph.edges) == set(frozenset(e) for e in ((0, 1), (1, 2)))
|
|
93
|
-
assert sorted(graph.vertices) == [0, 1, 2]
|
|
93
|
+
assert sorted(graph.vertices) == [0, 1, 2] # type: ignore[type-var]
|
|
94
94
|
|
|
95
95
|
|
|
96
|
-
def test_add():
|
|
96
|
+
def test_add() -> None:
|
|
97
97
|
first_addend = ccgd.UndirectedHypergraph(labelled_edges={('a', 'b'): None})
|
|
98
98
|
second_addend = ccgd.UndirectedHypergraph(labelled_edges={('c', 'b'): None})
|
|
99
99
|
graph_sum = first_addend + second_addend
|
|
100
|
-
assert sorted(first_addend.vertices) == list('ab')
|
|
101
|
-
assert sorted(second_addend.vertices) == list('bc')
|
|
100
|
+
assert sorted(first_addend.vertices) == list('ab') # type: ignore[type-var]
|
|
101
|
+
assert sorted(second_addend.vertices) == list('bc') # type: ignore[type-var]
|
|
102
102
|
assert sorted(graph_sum.vertices) == list('abc')
|
|
103
103
|
assert sorted(first_addend.edges) == [frozenset('ab')]
|
|
104
104
|
assert sorted(second_addend.edges) == [frozenset('bc')]
|
|
@@ -14,21 +14,27 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
+
from typing import TYPE_CHECKING
|
|
18
|
+
|
|
17
19
|
import pytest
|
|
18
20
|
|
|
19
21
|
import cirq
|
|
20
22
|
import cirq.contrib.graph_device as ccgd
|
|
21
23
|
|
|
24
|
+
if TYPE_CHECKING:
|
|
25
|
+
from cirq.contrib.graph_device.graph_device import UndirectedGraphDeviceEdge
|
|
26
|
+
|
|
22
27
|
|
|
23
|
-
def test_empty_uniform_undirected_linear_device():
|
|
28
|
+
def test_empty_uniform_undirected_linear_device() -> None:
|
|
24
29
|
n_qubits = 4
|
|
30
|
+
edge_labels: dict[int, UndirectedGraphDeviceEdge | None]
|
|
25
31
|
edge_labels = {}
|
|
26
32
|
device = ccgd.uniform_undirected_linear_device(n_qubits, edge_labels)
|
|
27
33
|
assert device.qubits == tuple()
|
|
28
34
|
assert device.edges == tuple()
|
|
29
35
|
|
|
30
36
|
|
|
31
|
-
def test_negative_arity_arg_uniform_undirected_linear_device():
|
|
37
|
+
def test_negative_arity_arg_uniform_undirected_linear_device() -> None:
|
|
32
38
|
with pytest.raises(ValueError):
|
|
33
39
|
ccgd.uniform_undirected_linear_device(5, {-1: None})
|
|
34
40
|
with pytest.raises(ValueError):
|
|
@@ -36,7 +42,7 @@ def test_negative_arity_arg_uniform_undirected_linear_device():
|
|
|
36
42
|
|
|
37
43
|
|
|
38
44
|
@pytest.mark.parametrize('arity', range(1, 5))
|
|
39
|
-
def test_regular_uniform_undirected_linear_device(arity):
|
|
45
|
+
def test_regular_uniform_undirected_linear_device(arity) -> None:
|
|
40
46
|
n_qubits = 10
|
|
41
47
|
edge_labels = {arity: None}
|
|
42
48
|
device = ccgd.uniform_undirected_linear_device(n_qubits, edge_labels)
|
|
@@ -17,10 +17,13 @@
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
import contextlib
|
|
20
|
+
from collections.abc import Generator
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
@contextlib.contextmanager
|
|
23
|
-
def disable_op_validation(
|
|
24
|
+
def disable_op_validation(
|
|
25
|
+
*, accept_debug_responsibility: bool = False
|
|
26
|
+
) -> Generator[None, None, None]:
|
|
24
27
|
if not accept_debug_responsibility:
|
|
25
28
|
raise ValueError(
|
|
26
29
|
"WARNING! Using disable_op_validation with invalid ops can cause "
|
cirq/contrib/json.py
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
from __future__ import annotations
|
|
5
5
|
|
|
6
|
-
from cirq.protocols.json_serialization import DEFAULT_RESOLVERS
|
|
6
|
+
from cirq.protocols.json_serialization import DEFAULT_RESOLVERS, ObjectFactory
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
def contrib_class_resolver(cirq_type: str):
|
|
9
|
+
def contrib_class_resolver(cirq_type: str) -> ObjectFactory | None:
|
|
10
10
|
"""Extend cirq's JSON API with resolvers for cirq contrib classes."""
|
|
11
11
|
from cirq.contrib.acquaintance import SwapPermutationGate
|
|
12
12
|
from cirq.contrib.bayesian_network import BayesianNetworkGate
|
|
@@ -42,7 +42,7 @@ class DepolarizingNoiseModel(devices.NoiseModel):
|
|
|
42
42
|
self.qubit_noise_gate = ops.DepolarizingChannel(depol_prob)
|
|
43
43
|
self._prepend = prepend
|
|
44
44
|
|
|
45
|
-
def noisy_moment(self, moment: cirq.Moment, system_qubits: Sequence[cirq.Qid]):
|
|
45
|
+
def noisy_moment(self, moment: cirq.Moment, system_qubits: Sequence[cirq.Qid]) -> cirq.OP_TREE:
|
|
46
46
|
if validate_all_measurements(moment) or self.is_virtual_moment(moment): # pragma: no cover
|
|
47
47
|
return moment
|
|
48
48
|
|
|
@@ -78,7 +78,7 @@ class ReadoutNoiseModel(devices.NoiseModel):
|
|
|
78
78
|
self.readout_noise_gate = ops.BitFlipChannel(bitflip_prob)
|
|
79
79
|
self._prepend = prepend
|
|
80
80
|
|
|
81
|
-
def noisy_moment(self, moment: cirq.Moment, system_qubits: Sequence[cirq.Qid]):
|
|
81
|
+
def noisy_moment(self, moment: cirq.Moment, system_qubits: Sequence[cirq.Qid]) -> cirq.OP_TREE:
|
|
82
82
|
if self.is_virtual_moment(moment):
|
|
83
83
|
return moment
|
|
84
84
|
if validate_all_measurements(moment):
|
|
@@ -115,7 +115,7 @@ class DampedReadoutNoiseModel(devices.NoiseModel):
|
|
|
115
115
|
self.readout_decay_gate = ops.AmplitudeDampingChannel(decay_prob)
|
|
116
116
|
self._prepend = prepend
|
|
117
117
|
|
|
118
|
-
def noisy_moment(self, moment: cirq.Moment, system_qubits: Sequence[cirq.Qid]):
|
|
118
|
+
def noisy_moment(self, moment: cirq.Moment, system_qubits: Sequence[cirq.Qid]) -> cirq.OP_TREE:
|
|
119
119
|
if self.is_virtual_moment(moment):
|
|
120
120
|
return moment
|
|
121
121
|
if validate_all_measurements(moment):
|
|
@@ -148,7 +148,7 @@ class DepolarizingWithReadoutNoiseModel(devices.NoiseModel):
|
|
|
148
148
|
self.qubit_noise_gate = ops.DepolarizingChannel(depol_prob)
|
|
149
149
|
self.readout_noise_gate = ops.BitFlipChannel(bitflip_prob)
|
|
150
150
|
|
|
151
|
-
def noisy_moment(self, moment: cirq.Moment, system_qubits: Sequence[cirq.Qid]):
|
|
151
|
+
def noisy_moment(self, moment: cirq.Moment, system_qubits: Sequence[cirq.Qid]) -> cirq.OP_TREE:
|
|
152
152
|
if validate_all_measurements(moment):
|
|
153
153
|
return [circuits.Moment(self.readout_noise_gate(q) for q in system_qubits), moment]
|
|
154
154
|
return [moment, circuits.Moment(self.qubit_noise_gate(q) for q in system_qubits)]
|
|
@@ -178,7 +178,7 @@ class DepolarizingWithDampedReadoutNoiseModel(devices.NoiseModel):
|
|
|
178
178
|
self.readout_noise_gate = ops.BitFlipChannel(bitflip_prob)
|
|
179
179
|
self.readout_decay_gate = ops.AmplitudeDampingChannel(decay_prob)
|
|
180
180
|
|
|
181
|
-
def noisy_moment(self, moment: cirq.Moment, system_qubits: Sequence[cirq.Qid]):
|
|
181
|
+
def noisy_moment(self, moment: cirq.Moment, system_qubits: Sequence[cirq.Qid]) -> cirq.OP_TREE:
|
|
182
182
|
if validate_all_measurements(moment):
|
|
183
183
|
return [
|
|
184
184
|
circuits.Moment(self.readout_decay_gate(q) for q in system_qubits),
|
|
@@ -25,6 +25,7 @@ def test_depol_noise() -> None:
|
|
|
25
25
|
qubits = cirq.LineQubit.range(2)
|
|
26
26
|
moment = cirq.Moment([cirq.X(qubits[0]), cirq.Y(qubits[1])])
|
|
27
27
|
noisy_mom = noise_model.noisy_moment(moment, system_qubits=qubits)
|
|
28
|
+
assert isinstance(noisy_mom, list)
|
|
28
29
|
assert len(noisy_mom) == 2
|
|
29
30
|
assert noisy_mom[0] == moment
|
|
30
31
|
for g in noisy_mom[1]:
|
|
@@ -36,6 +37,7 @@ def test_depol_noise_prepend() -> None:
|
|
|
36
37
|
qubits = cirq.LineQubit.range(2)
|
|
37
38
|
moment = cirq.Moment([cirq.X(qubits[0]), cirq.Y(qubits[1])])
|
|
38
39
|
noisy_mom = noise_model.noisy_moment(moment, system_qubits=qubits)
|
|
40
|
+
assert isinstance(noisy_mom, list)
|
|
39
41
|
assert len(noisy_mom) == 2
|
|
40
42
|
assert noisy_mom[1] == moment
|
|
41
43
|
for g in noisy_mom[0]:
|
|
@@ -99,6 +101,7 @@ def test_readout_noise_no_prepend() -> None:
|
|
|
99
101
|
qubits = cirq.LineQubit.range(2)
|
|
100
102
|
moment = cirq.Moment([cirq.measure(*qubits, key="meas")])
|
|
101
103
|
noisy_mom = noise_model.noisy_moment(moment, system_qubits=qubits)
|
|
104
|
+
assert isinstance(noisy_mom, list)
|
|
102
105
|
assert len(noisy_mom) == 2
|
|
103
106
|
assert noisy_mom[0] == moment
|
|
104
107
|
for g in noisy_mom[1]:
|
|
@@ -167,6 +170,7 @@ def test_damped_readout_noise_no_prepend() -> None:
|
|
|
167
170
|
qubits = cirq.LineQubit.range(2)
|
|
168
171
|
moment = cirq.Moment([cirq.measure(*qubits, key="meas")])
|
|
169
172
|
noisy_mom = noise_model.noisy_moment(moment, system_qubits=qubits)
|
|
173
|
+
assert isinstance(noisy_mom, list)
|
|
170
174
|
assert len(noisy_mom) == 2
|
|
171
175
|
assert noisy_mom[0] == moment
|
|
172
176
|
for g in noisy_mom[1]:
|
|
@@ -286,7 +286,7 @@ def _build_many_one_qubits_empty_confusion_matrix(qubits_length: int) -> list[np
|
|
|
286
286
|
|
|
287
287
|
|
|
288
288
|
def _process_pauli_measurement_results(
|
|
289
|
-
qubits:
|
|
289
|
+
qubits: Sequence[ops.Qid],
|
|
290
290
|
pauli_string_groups: list[list[ops.PauliString]],
|
|
291
291
|
circuit_results: list[ResultDict],
|
|
292
292
|
calibration_results: dict[tuple[ops.Qid, ...], SingleQubitReadoutCalibrationResult],
|
|
@@ -304,10 +304,11 @@ def _process_pauli_measurement_results(
|
|
|
304
304
|
|
|
305
305
|
Args:
|
|
306
306
|
qubits: Qubits to build confusion matrices for. In a sorted order.
|
|
307
|
-
|
|
307
|
+
pauli_string_groups: The lists of QWC Pauli string groups that are measured.
|
|
308
308
|
circuit_results: A list of ResultDict obtained
|
|
309
309
|
from running the Pauli measurement circuits.
|
|
310
|
-
|
|
310
|
+
calibration_results: A dictionary of SingleQubitReadoutCalibrationResult
|
|
311
|
+
for tuples of qubits present in `pauli_string_groups`.
|
|
311
312
|
pauli_repetitions: The number of repetitions used for Pauli string measurements.
|
|
312
313
|
timestamp: The timestamp of the calibration results.
|
|
313
314
|
disable_readout_mitigation: If set to True, returns no error-mitigated error
|
|
@@ -326,7 +327,7 @@ def _process_pauli_measurement_results(
|
|
|
326
327
|
|
|
327
328
|
calibration_result = (
|
|
328
329
|
calibration_results[tuple(pauli_readout_qubits)]
|
|
329
|
-
if disable_readout_mitigation
|
|
330
|
+
if not disable_readout_mitigation
|
|
330
331
|
else None
|
|
331
332
|
)
|
|
332
333
|
|
|
@@ -458,9 +459,9 @@ def measure_pauli_strings(
|
|
|
458
459
|
qubits_list = sorted(unique_qubit_tuples)
|
|
459
460
|
|
|
460
461
|
# Build the basis-change circuits for each Pauli string group
|
|
461
|
-
pauli_measurement_circuits
|
|
462
|
+
pauli_measurement_circuits: list[circuits.Circuit] = []
|
|
462
463
|
for input_circuit, pauli_string_groups in normalized_circuits_to_pauli.items():
|
|
463
|
-
qid_list =
|
|
464
|
+
qid_list = sorted(input_circuit.all_qubits())
|
|
464
465
|
basis_change_circuits = []
|
|
465
466
|
input_circuit_unfrozen = input_circuit.unfreeze()
|
|
466
467
|
for pauli_strings in pauli_string_groups:
|
|
@@ -874,23 +874,20 @@ def test_group_paulis_type_mismatch() -> None:
|
|
|
874
874
|
|
|
875
875
|
def test_process_pauli_measurement_results_raises_error_on_missing_calibration() -> None:
|
|
876
876
|
"""Test that the function raises an error if the calibration result is missing."""
|
|
877
|
-
qubits:
|
|
877
|
+
qubits: Sequence[cirq.Qid] = cirq.LineQubit.range(5)
|
|
878
878
|
|
|
879
879
|
measurement_op = cirq.measure(*qubits, key='m')
|
|
880
|
-
test_circuits
|
|
881
|
-
for _ in range(3):
|
|
882
|
-
circuit_list = []
|
|
883
|
-
|
|
884
|
-
circuit = _create_ghz(5, qubits) + measurement_op
|
|
885
|
-
circuit_list.append(circuit)
|
|
886
|
-
test_circuits.extend(circuit_list)
|
|
880
|
+
test_circuits: list[cirq.Circuit] = [_create_ghz(5, qubits) + measurement_op for _ in range(3)]
|
|
887
881
|
|
|
888
882
|
pauli_strings = [_generate_random_pauli_string(qubits, True) for _ in range(3)]
|
|
889
883
|
sampler = cirq.Simulator()
|
|
890
884
|
|
|
891
885
|
circuit_results = sampler.run_batch(test_circuits, repetitions=1000)
|
|
892
886
|
|
|
893
|
-
|
|
887
|
+
pauli_strings_qubits = sorted(
|
|
888
|
+
set(itertools.chain.from_iterable(ps.qubits for ps in pauli_strings))
|
|
889
|
+
)
|
|
890
|
+
empty_calibration_result_dict = {tuple(pauli_strings_qubits): None}
|
|
894
891
|
|
|
895
892
|
with pytest.raises(
|
|
896
893
|
ValueError,
|
|
@@ -18,7 +18,8 @@ import cirq
|
|
|
18
18
|
import cirq.contrib.qcircuit as ccq
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
def test_get_qcircuit_diagram_info():
|
|
21
|
+
def test_get_qcircuit_diagram_info() -> None:
|
|
22
|
+
qubit_map: dict[cirq.LabelEntity, int]
|
|
22
23
|
qubits = cirq.NamedQubit('x'), cirq.NamedQubit('y')
|
|
23
24
|
|
|
24
25
|
gate = cirq.SwapPowGate(exponent=0.5)
|