cirq-core 1.7.0.dev20250807224154__py3-none-any.whl → 1.7.0.dev20250812021254__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/contrib/noise_models/noise_models.py +8 -8
- cirq/contrib/quimb/grid_circuits.py +1 -1
- cirq/contrib/quimb/grid_circuits_test.py +10 -5
- cirq/contrib/quimb/mps_simulator.py +3 -3
- cirq/contrib/quimb/mps_simulator_test.py +41 -42
- cirq/contrib/quimb/state_vector_test.py +14 -13
- cirq/contrib/quirk/export_to_quirk_test.py +2 -2
- cirq/contrib/quirk/linearize_circuit.py +1 -1
- cirq/contrib/routing/device.py +1 -1
- cirq/contrib/routing/device_test.py +7 -5
- cirq/contrib/routing/greedy_test.py +7 -2
- cirq/contrib/routing/initialization_test.py +1 -1
- cirq/contrib/routing/router_test.py +9 -10
- cirq/contrib/routing/swap_network_test.py +10 -4
- cirq/contrib/routing/utils_test.py +4 -4
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +9 -9
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +18 -16
- cirq/contrib/svg/svg.py +1 -1
- cirq/devices/grid_device_metadata_test.py +12 -12
- cirq/devices/grid_qubit_test.py +52 -52
- cirq/devices/line_qubit_test.py +37 -37
- cirq/devices/named_topologies.py +7 -5
- cirq/devices/named_topologies_test.py +3 -2
- cirq/devices/noise_model.py +1 -1
- cirq/devices/noise_properties_test.py +1 -1
- cirq/devices/noise_utils.py +1 -1
- cirq/devices/noise_utils_test.py +6 -6
- cirq/devices/superconducting_qubits_noise_properties_test.py +31 -24
- cirq/devices/thermal_noise_model_test.py +48 -44
- cirq/devices/unconstrained_device.py +1 -1
- cirq/devices/unconstrained_device_test.py +3 -3
- cirq/experiments/benchmarking/parallel_xeb.py +24 -17
- cirq/experiments/benchmarking/parallel_xeb_test.py +42 -28
- cirq/experiments/fidelity_estimation.py +5 -5
- cirq/experiments/fidelity_estimation_test.py +7 -7
- cirq/experiments/purity_estimation.py +1 -1
- cirq/experiments/purity_estimation_test.py +1 -1
- cirq/experiments/qubit_characterizations_test.py +10 -10
- cirq/experiments/random_quantum_circuit_generation.py +1 -1
- cirq/experiments/random_quantum_circuit_generation_test.py +18 -13
- cirq/experiments/readout_confusion_matrix_test.py +12 -8
- cirq/experiments/single_qubit_readout_calibration_test.py +13 -13
- cirq/experiments/t2_decay_experiment.py +1 -1
- cirq/experiments/t2_decay_experiment_test.py +13 -13
- cirq/experiments/two_qubit_xeb_test.py +20 -22
- cirq/experiments/xeb_fitting.py +3 -3
- cirq/experiments/xeb_fitting_test.py +21 -19
- cirq/experiments/xeb_sampling.py +2 -2
- cirq/experiments/xeb_sampling_test.py +9 -9
- cirq/experiments/xeb_simulation.py +1 -1
- cirq/experiments/xeb_simulation_test.py +6 -6
- cirq/ops/measure_util.py +2 -0
- {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812021254.dist-info}/METADATA +1 -1
- {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812021254.dist-info}/RECORD +59 -59
- {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812021254.dist-info}/WHEEL +0 -0
- {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812021254.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.7.0.dev20250807224154.dist-info → cirq_core-1.7.0.dev20250812021254.dist-info}/top_level.txt +0 -0
|
@@ -22,33 +22,35 @@ import cirq.contrib.routing as ccr
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
@pytest.mark.parametrize('n_qubits', (2, 5, 11))
|
|
25
|
-
def test_get_linear_device_graph(n_qubits):
|
|
25
|
+
def test_get_linear_device_graph(n_qubits) -> None:
|
|
26
26
|
graph = ccr.get_linear_device_graph(n_qubits)
|
|
27
27
|
assert sorted(graph) == cirq.LineQubit.range(n_qubits)
|
|
28
28
|
assert len(graph.edges()) == n_qubits - 1
|
|
29
29
|
assert all(abs(a.x - b.x) == 1 for a, b in graph.edges())
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
def test_nx_qubit_layout():
|
|
32
|
+
def test_nx_qubit_layout() -> None:
|
|
33
33
|
grid_qubit_graph = ccr.gridqubits_to_graph_device(cirq.GridQubit.rect(5, 5))
|
|
34
34
|
pos = ccr.nx_qubit_layout(grid_qubit_graph)
|
|
35
35
|
assert len(pos) == len(grid_qubit_graph)
|
|
36
36
|
for k, (x, y) in pos.items():
|
|
37
|
+
assert isinstance(k, cirq.GridQubit)
|
|
37
38
|
assert x == k.col
|
|
38
39
|
assert y == -k.row
|
|
39
40
|
|
|
40
41
|
|
|
41
|
-
def test_nx_qubit_layout_2():
|
|
42
|
+
def test_nx_qubit_layout_2() -> None:
|
|
42
43
|
g = nx.from_edgelist(
|
|
43
44
|
[(cirq.LineQubit(0), cirq.LineQubit(1)), (cirq.LineQubit(1), cirq.LineQubit(2))]
|
|
44
45
|
)
|
|
45
46
|
pos = ccr.nx_qubit_layout(g)
|
|
46
47
|
for k, (x, y) in pos.items():
|
|
48
|
+
assert isinstance(k, cirq.LineQubit)
|
|
47
49
|
assert x == k.x
|
|
48
50
|
assert y == 0.5
|
|
49
51
|
|
|
50
52
|
|
|
51
|
-
def test_nx_qubit_layout_3():
|
|
53
|
+
def test_nx_qubit_layout_3() -> None:
|
|
52
54
|
g = nx.from_edgelist(
|
|
53
55
|
[(cirq.NamedQubit('a'), cirq.NamedQubit('b')), (cirq.NamedQubit('b'), cirq.NamedQubit('c'))]
|
|
54
56
|
)
|
|
@@ -57,4 +59,4 @@ def test_nx_qubit_layout_3():
|
|
|
57
59
|
pos = ccr.nx_qubit_layout(g)
|
|
58
60
|
for k, (x, y) in pos.items():
|
|
59
61
|
assert x == 0.5
|
|
60
|
-
assert y == node_to_i[k] + 1
|
|
62
|
+
assert y == node_to_i[k] + 1 # type: ignore[index]
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
from multiprocessing import Process
|
|
18
|
+
from typing import TYPE_CHECKING
|
|
18
19
|
|
|
19
20
|
import pytest
|
|
20
21
|
|
|
@@ -22,6 +23,9 @@ import cirq
|
|
|
22
23
|
import cirq.contrib.routing as ccr
|
|
23
24
|
from cirq.contrib.routing.greedy import route_circuit_greedily
|
|
24
25
|
|
|
26
|
+
if TYPE_CHECKING:
|
|
27
|
+
import networkx as nx
|
|
28
|
+
|
|
25
29
|
|
|
26
30
|
def test_bad_args() -> None:
|
|
27
31
|
"""Test zero valued arguments in greedy router."""
|
|
@@ -34,18 +38,19 @@ def test_bad_args() -> None:
|
|
|
34
38
|
route_circuit_greedily(circuit, device_graph, max_num_empty_steps=0)
|
|
35
39
|
|
|
36
40
|
|
|
37
|
-
def create_circuit_and_device():
|
|
41
|
+
def create_circuit_and_device() -> tuple[cirq.Circuit, nx.Graph]:
|
|
38
42
|
"""Construct a small circuit and a device with line connectivity
|
|
39
43
|
to test the greedy router. This instance hangs router in Cirq 8.2.
|
|
40
44
|
"""
|
|
41
45
|
num_qubits = 6
|
|
46
|
+
gate_domain: dict[cirq.Gate, int]
|
|
42
47
|
gate_domain = {cirq.ops.CNOT: 2}
|
|
43
48
|
circuit = cirq.testing.random_circuit(num_qubits, 15, 0.5, gate_domain, random_state=37)
|
|
44
49
|
device_graph = ccr.get_linear_device_graph(num_qubits)
|
|
45
50
|
return circuit, device_graph
|
|
46
51
|
|
|
47
52
|
|
|
48
|
-
def create_hanging_routing_instance(circuit, device_graph):
|
|
53
|
+
def create_hanging_routing_instance(circuit, device_graph) -> None:
|
|
49
54
|
"""Create a test problem instance."""
|
|
50
55
|
route_circuit_greedily( # pragma: no cover
|
|
51
56
|
circuit, device_graph, max_search_radius=2, random_state=1
|
|
@@ -24,7 +24,7 @@ import cirq
|
|
|
24
24
|
import cirq.contrib.routing as ccr
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
def get_seeded_initial_mapping(graph_seed, init_seed):
|
|
27
|
+
def get_seeded_initial_mapping(graph_seed, init_seed) -> dict[cirq.Qid, cirq.Qid]:
|
|
28
28
|
logical_graph = nx.erdos_renyi_graph(10, 0.5, seed=graph_seed)
|
|
29
29
|
logical_graph = nx.relabel_nodes(logical_graph, cirq.LineQubit)
|
|
30
30
|
device_graph = ccr.get_grid_device_graph(4, 4)
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
import itertools
|
|
18
17
|
import random
|
|
19
18
|
|
|
20
19
|
import numpy as np
|
|
@@ -25,7 +24,7 @@ import cirq.contrib.acquaintance as cca
|
|
|
25
24
|
import cirq.contrib.routing as ccr
|
|
26
25
|
|
|
27
26
|
|
|
28
|
-
def random_seed():
|
|
27
|
+
def random_seed() -> int:
|
|
29
28
|
return random.randint(0, 2**32)
|
|
30
29
|
|
|
31
30
|
|
|
@@ -35,7 +34,7 @@ def random_seed():
|
|
|
35
34
|
+ [(0, 'greedy', random_seed(), random_seed())]
|
|
36
35
|
+ [(10, 'greedy', random_seed(), None)],
|
|
37
36
|
)
|
|
38
|
-
def test_route_circuit(n_moments, algo, circuit_seed, routing_seed):
|
|
37
|
+
def test_route_circuit(n_moments, algo, circuit_seed, routing_seed) -> None:
|
|
39
38
|
circuit = cirq.testing.random_circuit(10, n_moments, 0.5, random_state=circuit_seed)
|
|
40
39
|
device_graph = ccr.get_grid_device_graph(4, 3)
|
|
41
40
|
swap_network = ccr.route_circuit(
|
|
@@ -52,15 +51,15 @@ def test_route_circuit(n_moments, algo, circuit_seed, routing_seed):
|
|
|
52
51
|
@pytest.mark.parametrize(
|
|
53
52
|
'algo,seed', [(algo, random_seed()) for algo in ccr.ROUTERS for _ in range(3)]
|
|
54
53
|
)
|
|
55
|
-
def test_route_circuit_reproducible_with_seed(algo, seed):
|
|
54
|
+
def test_route_circuit_reproducible_with_seed(algo, seed) -> None:
|
|
56
55
|
circuit = cirq.testing.random_circuit(8, 20, 0.5, random_state=seed)
|
|
57
56
|
device_graph = ccr.get_grid_device_graph(4, 3)
|
|
58
|
-
|
|
57
|
+
random_states = [seed, seed, seed] + [np.random.RandomState(seed) for _ in range(3)]
|
|
59
58
|
|
|
60
59
|
swap_networks = []
|
|
61
|
-
for
|
|
60
|
+
for random_state in random_states:
|
|
62
61
|
swap_network = ccr.route_circuit(
|
|
63
|
-
circuit, device_graph, algo_name=algo, random_state=
|
|
62
|
+
circuit, device_graph, algo_name=algo, random_state=random_state
|
|
64
63
|
)
|
|
65
64
|
swap_networks.append(swap_network)
|
|
66
65
|
|
|
@@ -69,7 +68,7 @@ def test_route_circuit_reproducible_with_seed(algo, seed):
|
|
|
69
68
|
|
|
70
69
|
|
|
71
70
|
@pytest.mark.parametrize('algo', ccr.ROUTERS.keys())
|
|
72
|
-
def test_route_circuit_reproducible_between_runs(algo):
|
|
71
|
+
def test_route_circuit_reproducible_between_runs(algo) -> None:
|
|
73
72
|
seed = 23
|
|
74
73
|
circuit = cirq.testing.random_circuit(6, 5, 0.5, random_state=seed)
|
|
75
74
|
device_graph = ccr.get_grid_device_graph(2, 3)
|
|
@@ -106,7 +105,7 @@ def test_route_circuit_reproducible_between_runs(algo):
|
|
|
106
105
|
]
|
|
107
106
|
+ [(0, 'greedy', random_seed(), False)],
|
|
108
107
|
)
|
|
109
|
-
def test_route_circuit_via_unitaries(n_moments, algo, seed, make_bad):
|
|
108
|
+
def test_route_circuit_via_unitaries(n_moments, algo, seed, make_bad) -> None:
|
|
110
109
|
circuit = cirq.testing.random_circuit(4, n_moments, 0.5, random_state=seed)
|
|
111
110
|
device_graph = ccr.get_grid_device_graph(3, 2)
|
|
112
111
|
|
|
@@ -132,7 +131,7 @@ def test_route_circuit_via_unitaries(n_moments, algo, seed, make_bad):
|
|
|
132
131
|
assert np.allclose(physical_unitary, logical_unitary) == (not make_bad)
|
|
133
132
|
|
|
134
133
|
|
|
135
|
-
def test_router_bad_args():
|
|
134
|
+
def test_router_bad_args() -> None:
|
|
136
135
|
circuit = cirq.Circuit()
|
|
137
136
|
device_graph = ccr.get_linear_device_graph(5)
|
|
138
137
|
with pytest.raises(ValueError):
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import itertools
|
|
18
|
+
from typing import Any
|
|
18
19
|
|
|
19
20
|
import pytest
|
|
20
21
|
|
|
@@ -23,9 +24,10 @@ import cirq.contrib.acquaintance as cca
|
|
|
23
24
|
import cirq.contrib.routing as ccr
|
|
24
25
|
|
|
25
26
|
|
|
26
|
-
def test_final_mapping():
|
|
27
|
+
def test_final_mapping() -> None:
|
|
27
28
|
n_qubits = 10
|
|
28
29
|
qubits = cirq.LineQubit.range(n_qubits)
|
|
30
|
+
initial_mapping: dict[cirq.Qid, cirq.Qid]
|
|
29
31
|
initial_mapping = dict(zip(qubits, qubits))
|
|
30
32
|
expected_final_mapping = dict(zip(qubits, reversed(qubits)))
|
|
31
33
|
SWAP = cca.SwapPermutationGate()
|
|
@@ -37,10 +39,11 @@ def test_final_mapping():
|
|
|
37
39
|
assert swap_network.final_mapping() == expected_final_mapping
|
|
38
40
|
|
|
39
41
|
|
|
40
|
-
def test_swap_network_bad_args():
|
|
42
|
+
def test_swap_network_bad_args() -> None:
|
|
41
43
|
n_qubits = 10
|
|
42
44
|
qubits = cirq.LineQubit.range(n_qubits)
|
|
43
45
|
circuit = cirq.Circuit()
|
|
46
|
+
initial_mapping: dict[Any, Any]
|
|
44
47
|
with pytest.raises(ValueError):
|
|
45
48
|
initial_mapping = dict(zip(qubits, range(n_qubits)))
|
|
46
49
|
ccr.SwapNetwork(circuit, initial_mapping)
|
|
@@ -50,7 +53,8 @@ def test_swap_network_bad_args():
|
|
|
50
53
|
|
|
51
54
|
|
|
52
55
|
@pytest.mark.parametrize('circuits', [[cirq.testing.random_circuit(10, 10, 0.5) for _ in range(3)]])
|
|
53
|
-
def test_swap_network_equality(circuits):
|
|
56
|
+
def test_swap_network_equality(circuits) -> None:
|
|
57
|
+
mapping: dict[cirq.Qid, cirq.Qid]
|
|
54
58
|
et = cirq.testing.EqualsTester()
|
|
55
59
|
for circuit in circuits: # NB: tiny prob. that circuits aren't unique
|
|
56
60
|
qubits = sorted(circuit.all_qubits())
|
|
@@ -59,11 +63,13 @@ def test_swap_network_equality(circuits):
|
|
|
59
63
|
et.add_equality_group(ccr.SwapNetwork(circuit, mapping))
|
|
60
64
|
|
|
61
65
|
|
|
62
|
-
def test_swap_network_str():
|
|
66
|
+
def test_swap_network_str() -> None:
|
|
63
67
|
n_qubits = 5
|
|
64
68
|
phys_qubits = cirq.GridQubit.rect(n_qubits, 1)
|
|
65
69
|
log_qubits = cirq.LineQubit.range(n_qubits)
|
|
66
70
|
|
|
71
|
+
gates: dict[tuple[cirq.Qid, cirq.Qid], cirq.Gate]
|
|
72
|
+
initial_mapping: dict[cirq.Qid, cirq.Qid]
|
|
67
73
|
gates = {(l, ll): cirq.ZZ for l, ll in itertools.combinations(log_qubits, 2)}
|
|
68
74
|
initial_mapping = {p: l for p, l in zip(phys_qubits, log_qubits)}
|
|
69
75
|
execution_strategy = cca.GreedyExecutionStrategy(gates, initial_mapping)
|
|
@@ -21,7 +21,7 @@ import cirq
|
|
|
21
21
|
import cirq.contrib.routing as ccr
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
def test_ops_are_consistent_with_device_graph():
|
|
24
|
+
def test_ops_are_consistent_with_device_graph() -> None:
|
|
25
25
|
device_graph = ccr.get_linear_device_graph(3)
|
|
26
26
|
qubits = cirq.LineQubit.range(3)
|
|
27
27
|
circuit = cirq.Circuit(cirq.ZZ(qubits[0], qubits[2]))
|
|
@@ -31,7 +31,7 @@ def test_ops_are_consistent_with_device_graph():
|
|
|
31
31
|
)
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
def test_get_circuit_connectivity():
|
|
34
|
+
def test_get_circuit_connectivity() -> None:
|
|
35
35
|
a, b, c, d = cirq.LineQubit.range(4)
|
|
36
36
|
circuit = cirq.Circuit(cirq.CZ(a, b), cirq.CZ(b, c), cirq.CZ(c, d), cirq.CZ(d, a))
|
|
37
37
|
graph = ccr.get_circuit_connectivity(circuit)
|
|
@@ -41,12 +41,12 @@ def test_get_circuit_connectivity():
|
|
|
41
41
|
assert is_planar
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
def test_is_valid_routing_with_bad_args():
|
|
44
|
+
def test_is_valid_routing_with_bad_args() -> None:
|
|
45
45
|
p, q, r = cirq.LineQubit.range(3)
|
|
46
46
|
x, y = cirq.NamedQubit('x'), cirq.NamedQubit('y')
|
|
47
47
|
circuit = cirq.Circuit([cirq.CNOT(x, y), cirq.CZ(x, y)])
|
|
48
48
|
routed_circuit = cirq.Circuit([cirq.CNOT(p, q), cirq.CZ(q, r)])
|
|
49
|
-
initial_mapping = {p: x, q: y}
|
|
49
|
+
initial_mapping: dict[cirq.Qid, cirq.Qid] = {p: x, q: y}
|
|
50
50
|
swap_network = ccr.SwapNetwork(routed_circuit, initial_mapping)
|
|
51
51
|
assert not ccr.is_valid_routing(circuit, swap_network)
|
|
52
52
|
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
import time
|
|
20
|
-
from typing import
|
|
20
|
+
from typing import Sequence, TYPE_CHECKING
|
|
21
21
|
|
|
22
22
|
import attrs
|
|
23
23
|
import numpy as np
|
|
@@ -64,7 +64,7 @@ class ReadoutBenchmarkingParams:
|
|
|
64
64
|
def _validate_experiment_input(
|
|
65
65
|
input_circuits: Sequence[circuits.Circuit],
|
|
66
66
|
circuit_repetitions: int | list[int],
|
|
67
|
-
rng_or_seed:
|
|
67
|
+
rng_or_seed: np.random.Generator | int | None = None,
|
|
68
68
|
):
|
|
69
69
|
if not input_circuits:
|
|
70
70
|
raise ValueError("Input circuits must not be empty.")
|
|
@@ -84,7 +84,7 @@ def _validate_experiment_input_with_sweep(
|
|
|
84
84
|
input_circuits: Sequence[circuits.Circuit],
|
|
85
85
|
sweep_params: Sequence[study.Sweepable],
|
|
86
86
|
circuit_repetitions: int | list[int],
|
|
87
|
-
rng_or_seed:
|
|
87
|
+
rng_or_seed: np.random.Generator | int | None = None,
|
|
88
88
|
):
|
|
89
89
|
"""Validates the input for the run_sweep_with_readout_benchmarking function."""
|
|
90
90
|
if not sweep_params:
|
|
@@ -183,7 +183,7 @@ def _generate_all_readout_calibration_circuits(
|
|
|
183
183
|
|
|
184
184
|
def _determine_qubits_to_measure(
|
|
185
185
|
input_circuits: Sequence[circuits.Circuit],
|
|
186
|
-
qubits:
|
|
186
|
+
qubits: Sequence[ops.Qid] | Sequence[Sequence[ops.Qid]] | None,
|
|
187
187
|
) -> list[list[ops.Qid]]:
|
|
188
188
|
"""Determine the qubits to measure based on the input circuits and provided qubits."""
|
|
189
189
|
# If input qubits is None, extract qubits from input circuits
|
|
@@ -280,7 +280,7 @@ def run_shuffled_with_readout_benchmarking(
|
|
|
280
280
|
rng_or_seed: np.random.Generator | int,
|
|
281
281
|
num_random_bitstrings: int = 100,
|
|
282
282
|
readout_repetitions: int = 1000,
|
|
283
|
-
qubits:
|
|
283
|
+
qubits: Sequence[ops.Qid] | Sequence[Sequence[ops.Qid]] | None = None,
|
|
284
284
|
) -> tuple[Sequence[ResultDict], dict[tuple[ops.Qid, ...], SingleQubitReadoutCalibrationResult]]:
|
|
285
285
|
"""Run the circuits in a shuffled order with readout error benchmarking.
|
|
286
286
|
|
|
@@ -373,8 +373,8 @@ def run_shuffled_circuits_with_readout_benchmarking(
|
|
|
373
373
|
sampler: work.Sampler,
|
|
374
374
|
input_circuits: list[circuits.Circuit],
|
|
375
375
|
parameters: ReadoutBenchmarkingParams,
|
|
376
|
-
qubits:
|
|
377
|
-
rng_or_seed:
|
|
376
|
+
qubits: Sequence[ops.Qid] | Sequence[Sequence[ops.Qid]] | None = None,
|
|
377
|
+
rng_or_seed: np.random.Generator | int | None = None,
|
|
378
378
|
) -> tuple[Sequence[ResultDict], dict[tuple[ops.Qid, ...], SingleQubitReadoutCalibrationResult]]:
|
|
379
379
|
"""Run the circuits in a shuffled order with readout error benchmarking.
|
|
380
380
|
|
|
@@ -458,8 +458,8 @@ def run_sweep_with_readout_benchmarking(
|
|
|
458
458
|
input_circuits: list[circuits.Circuit],
|
|
459
459
|
sweep_params: Sequence[study.Sweepable],
|
|
460
460
|
parameters: ReadoutBenchmarkingParams,
|
|
461
|
-
qubits:
|
|
462
|
-
rng_or_seed:
|
|
461
|
+
qubits: Sequence[ops.Qid] | Sequence[Sequence[ops.Qid]] | None = None,
|
|
462
|
+
rng_or_seed: np.random.Generator | int | None = None,
|
|
463
463
|
) -> tuple[
|
|
464
464
|
Sequence[Sequence[study.Result]], dict[tuple[ops.Qid, ...], SingleQubitReadoutCalibrationResult]
|
|
465
465
|
]:
|
|
@@ -124,7 +124,7 @@ def _circuits_with_readout_benchmarking_errors_sweep(
|
|
|
124
124
|
|
|
125
125
|
|
|
126
126
|
@pytest.mark.parametrize("mode", ["shuffled", "sweep"])
|
|
127
|
-
def test_circuits_with_readout_benchmarking_errors_no_noise(mode: str):
|
|
127
|
+
def test_circuits_with_readout_benchmarking_errors_no_noise(mode: str) -> None:
|
|
128
128
|
"""Test shuffled/sweep circuits with readout benchmarking with no noise from sampler."""
|
|
129
129
|
qubits = cirq.LineQubit.range(5)
|
|
130
130
|
|
|
@@ -166,7 +166,7 @@ def test_circuits_with_readout_benchmarking_errors_no_noise(mode: str):
|
|
|
166
166
|
|
|
167
167
|
|
|
168
168
|
@pytest.mark.parametrize("mode", ["shuffled", "sweep"])
|
|
169
|
-
def test_circuits_with_readout_benchmarking_errors_with_noise(mode: str):
|
|
169
|
+
def test_circuits_with_readout_benchmarking_errors_with_noise(mode: str) -> None:
|
|
170
170
|
"""Test shuffled/sweep circuits with readout benchmarking with noise from sampler."""
|
|
171
171
|
qubits = cirq.LineQubit.range(6)
|
|
172
172
|
sampler = NoisySingleQubitReadoutSampler(p0=0.1, p1=0.2, seed=1234)
|
|
@@ -209,7 +209,7 @@ def test_circuits_with_readout_benchmarking_errors_with_noise(mode: str):
|
|
|
209
209
|
|
|
210
210
|
|
|
211
211
|
@pytest.mark.parametrize("mode", ["shuffled", "sweep"])
|
|
212
|
-
def test_circuits_with_readout_benchmarking_errors_with_noise_and_input_qubits(mode: str):
|
|
212
|
+
def test_circuits_with_readout_benchmarking_errors_with_noise_and_input_qubits(mode: str) -> None:
|
|
213
213
|
"""Test shuffled/sweep circuits with readout benchmarking with
|
|
214
214
|
noise from sampler and input qubits."""
|
|
215
215
|
qubits = cirq.LineQubit.range(6)
|
|
@@ -255,7 +255,9 @@ def test_circuits_with_readout_benchmarking_errors_with_noise_and_input_qubits(m
|
|
|
255
255
|
|
|
256
256
|
|
|
257
257
|
@pytest.mark.parametrize("mode", ["shuffled", "sweep"])
|
|
258
|
-
def test_circuits_with_readout_benchmarking_errors_with_noise_and_lists_input_qubits(
|
|
258
|
+
def test_circuits_with_readout_benchmarking_errors_with_noise_and_lists_input_qubits(
|
|
259
|
+
mode: str,
|
|
260
|
+
) -> None:
|
|
259
261
|
"""Test shuffled/sweep circuits with readout benchmarking with noise
|
|
260
262
|
from sampler and input qubits."""
|
|
261
263
|
qubits_1 = cirq.LineQubit.range(3)
|
|
@@ -305,7 +307,7 @@ def test_circuits_with_readout_benchmarking_errors_with_noise_and_lists_input_qu
|
|
|
305
307
|
|
|
306
308
|
|
|
307
309
|
@pytest.mark.parametrize("mode", ["shuffled", "sweep"])
|
|
308
|
-
def test_can_handle_zero_random_bitstring(mode: str):
|
|
310
|
+
def test_can_handle_zero_random_bitstring(mode: str) -> None:
|
|
309
311
|
"""Test shuffled/sweep circuits without readout benchmarking."""
|
|
310
312
|
qubits_1 = cirq.LineQubit.range(3)
|
|
311
313
|
qubits_2 = cirq.LineQubit.range(4)
|
|
@@ -345,7 +347,7 @@ def test_can_handle_zero_random_bitstring(mode: str):
|
|
|
345
347
|
|
|
346
348
|
|
|
347
349
|
@pytest.mark.parametrize("mode", ["shuffled", "sweep"])
|
|
348
|
-
def test_circuits_with_readout_benchmarking_no_qubits_arg_empty_rng(mode: str):
|
|
350
|
+
def test_circuits_with_readout_benchmarking_no_qubits_arg_empty_rng(mode: str) -> None:
|
|
349
351
|
"""Test benchmarking when the `qubits` argument is not provided."""
|
|
350
352
|
qubits = cirq.LineQubit.range(3)
|
|
351
353
|
sampler = NoisySingleQubitReadoutSampler(p0=0.1, p1=0.2, seed=1234)
|
|
@@ -389,7 +391,7 @@ def test_circuits_with_readout_benchmarking_no_qubits_arg_empty_rng(mode: str):
|
|
|
389
391
|
assert result.repetitions == readout_repetitions
|
|
390
392
|
|
|
391
393
|
|
|
392
|
-
def test_deprecated_run_shuffled_with_readout_benchmarking():
|
|
394
|
+
def test_deprecated_run_shuffled_with_readout_benchmarking() -> None:
|
|
393
395
|
"""Test that the deprecated function works correctly and is covered."""
|
|
394
396
|
qubits = cirq.LineQubit.range(3)
|
|
395
397
|
input_circuits = _create_test_circuits(qubits, 3)
|
|
@@ -470,7 +472,7 @@ def test_deprecated_run_shuffled_with_readout_benchmarking():
|
|
|
470
472
|
)
|
|
471
473
|
|
|
472
474
|
|
|
473
|
-
def test_empty_input_circuits():
|
|
475
|
+
def test_empty_input_circuits() -> None:
|
|
474
476
|
"""Test that the input circuits are empty."""
|
|
475
477
|
readout_benchmarking_params = sc_readout.ReadoutBenchmarkingParams(
|
|
476
478
|
circuit_repetitions=10, num_random_bitstrings=5, readout_repetitions=100
|
|
@@ -484,7 +486,7 @@ def test_empty_input_circuits():
|
|
|
484
486
|
)
|
|
485
487
|
|
|
486
488
|
|
|
487
|
-
def test_non_circuit_input():
|
|
489
|
+
def test_non_circuit_input() -> None:
|
|
488
490
|
"""Test that the input circuits are not of type cirq.Circuit."""
|
|
489
491
|
q = cirq.LineQubit(0)
|
|
490
492
|
readout_benchmarking_params = sc_readout.ReadoutBenchmarkingParams(
|
|
@@ -493,13 +495,13 @@ def test_non_circuit_input():
|
|
|
493
495
|
with pytest.raises(ValueError, match="Input circuits must be of type cirq.Circuit."):
|
|
494
496
|
sc_readout.run_shuffled_circuits_with_readout_benchmarking(
|
|
495
497
|
cirq.ZerosSampler(),
|
|
496
|
-
[q],
|
|
498
|
+
[q], # type: ignore[list-item]
|
|
497
499
|
readout_benchmarking_params,
|
|
498
500
|
rng_or_seed=np.random.default_rng(456),
|
|
499
501
|
)
|
|
500
502
|
|
|
501
503
|
|
|
502
|
-
def test_no_measurements():
|
|
504
|
+
def test_no_measurements() -> None:
|
|
503
505
|
"""Test that the input circuits don't have measurements."""
|
|
504
506
|
q = cirq.LineQubit(0)
|
|
505
507
|
circuit = cirq.Circuit(cirq.H(q))
|
|
@@ -515,7 +517,7 @@ def test_no_measurements():
|
|
|
515
517
|
)
|
|
516
518
|
|
|
517
519
|
|
|
518
|
-
def test_zero_circuit_repetitions():
|
|
520
|
+
def test_zero_circuit_repetitions() -> None:
|
|
519
521
|
"""Test that the circuit repetitions are zero."""
|
|
520
522
|
with pytest.raises(ValueError, match="Must provide non-zero circuit_repetitions."):
|
|
521
523
|
sc_readout.ReadoutBenchmarkingParams(
|
|
@@ -523,7 +525,7 @@ def test_zero_circuit_repetitions():
|
|
|
523
525
|
)
|
|
524
526
|
|
|
525
527
|
|
|
526
|
-
def test_mismatch_circuit_repetitions():
|
|
528
|
+
def test_mismatch_circuit_repetitions() -> None:
|
|
527
529
|
"""Test that the number of circuit repetitions don't match the number of input circuits."""
|
|
528
530
|
q = cirq.LineQubit(0)
|
|
529
531
|
circuit = cirq.Circuit(cirq.H(q), cirq.measure(q))
|
|
@@ -542,7 +544,7 @@ def test_mismatch_circuit_repetitions():
|
|
|
542
544
|
)
|
|
543
545
|
|
|
544
546
|
|
|
545
|
-
def test_zero_num_random_bitstrings():
|
|
547
|
+
def test_zero_num_random_bitstrings() -> None:
|
|
546
548
|
"""Test that the number of random bitstrings is smaller than zero."""
|
|
547
549
|
with pytest.raises(ValueError, match="Must provide zero or more num_random_bitstrings."):
|
|
548
550
|
sc_readout.ReadoutBenchmarkingParams(
|
|
@@ -550,7 +552,7 @@ def test_zero_num_random_bitstrings():
|
|
|
550
552
|
)
|
|
551
553
|
|
|
552
554
|
|
|
553
|
-
def test_zero_readout_repetitions():
|
|
555
|
+
def test_zero_readout_repetitions() -> None:
|
|
554
556
|
"""Test that the readout repetitions is zero."""
|
|
555
557
|
with pytest.raises(
|
|
556
558
|
ValueError, match="Must provide non-zero readout_repetitions for readout" + " calibration."
|
|
@@ -560,7 +562,7 @@ def test_zero_readout_repetitions():
|
|
|
560
562
|
)
|
|
561
563
|
|
|
562
564
|
|
|
563
|
-
def test_empty_sweep_params():
|
|
565
|
+
def test_empty_sweep_params() -> None:
|
|
564
566
|
"""Test that the sweep params are empty."""
|
|
565
567
|
q = cirq.LineQubit(5)
|
|
566
568
|
circuit = cirq.Circuit(cirq.H(q))
|
cirq/contrib/svg/svg.py
CHANGED
|
@@ -15,7 +15,7 @@ FONT = matplotlib.font_manager.FontProperties()
|
|
|
15
15
|
EMPTY_MOMENT_COLWIDTH = float(21) # assumed default column width
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
def fixup_text(text: str):
|
|
18
|
+
def fixup_text(text: str) -> str:
|
|
19
19
|
if '\n' in text:
|
|
20
20
|
# https://github.com/quantumlib/Cirq/issues/4499
|
|
21
21
|
# TODO: Visualize Custom MatrixGate
|
|
@@ -22,15 +22,15 @@ import pytest
|
|
|
22
22
|
import cirq
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
def test_griddevice_metadata():
|
|
25
|
+
def test_griddevice_metadata() -> None:
|
|
26
26
|
qubits = cirq.GridQubit.rect(2, 3)
|
|
27
27
|
qubit_pairs = [(a, b) for a in qubits for b in qubits if a != b and a.is_adjacent(b)]
|
|
28
28
|
isolated_qubits = [cirq.GridQubit(9, 9), cirq.GridQubit(10, 10)]
|
|
29
29
|
gateset = cirq.Gateset(cirq.XPowGate, cirq.YPowGate, cirq.ZPowGate, cirq.CZ)
|
|
30
30
|
gate_durations = {
|
|
31
|
-
cirq.GateFamily(cirq.XPowGate):
|
|
32
|
-
cirq.GateFamily(cirq.YPowGate):
|
|
33
|
-
cirq.GateFamily(cirq.ZPowGate):
|
|
31
|
+
cirq.GateFamily(cirq.XPowGate): cirq.Duration(nanos=10),
|
|
32
|
+
cirq.GateFamily(cirq.YPowGate): cirq.Duration(nanos=10),
|
|
33
|
+
cirq.GateFamily(cirq.ZPowGate): cirq.Duration(nanos=10),
|
|
34
34
|
# omitting cirq.CZ
|
|
35
35
|
}
|
|
36
36
|
target_gatesets = (cirq.CZTargetGateset(),)
|
|
@@ -65,8 +65,8 @@ def test_griddevice_metadata():
|
|
|
65
65
|
assert metadata.compilation_target_gatesets == target_gatesets
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
def test_griddevice_metadata_bad_durations():
|
|
69
|
-
qubits =
|
|
68
|
+
def test_griddevice_metadata_bad_durations() -> None:
|
|
69
|
+
qubits: tuple[cirq.GridQubit, cirq.GridQubit] = (cirq.GridQubit(0, 0), cirq.GridQubit(0, 1))
|
|
70
70
|
|
|
71
71
|
gateset = cirq.Gateset(cirq.XPowGate, cirq.YPowGate)
|
|
72
72
|
invalid_duration = {
|
|
@@ -77,7 +77,7 @@ def test_griddevice_metadata_bad_durations():
|
|
|
77
77
|
cirq.GridDeviceMetadata([qubits], gateset, gate_durations=invalid_duration)
|
|
78
78
|
|
|
79
79
|
|
|
80
|
-
def test_griddevice_metadata_bad_isolated():
|
|
80
|
+
def test_griddevice_metadata_bad_isolated() -> None:
|
|
81
81
|
qubits = cirq.GridQubit.rect(2, 3)
|
|
82
82
|
qubit_pairs = [(a, b) for a in qubits for b in qubits if a != b and a.is_adjacent(b)]
|
|
83
83
|
fewer_qubits = [cirq.GridQubit(0, 0)]
|
|
@@ -86,7 +86,7 @@ def test_griddevice_metadata_bad_isolated():
|
|
|
86
86
|
_ = cirq.GridDeviceMetadata(qubit_pairs, gateset, all_qubits=fewer_qubits)
|
|
87
87
|
|
|
88
88
|
|
|
89
|
-
def test_griddevice_self_loop():
|
|
89
|
+
def test_griddevice_self_loop() -> None:
|
|
90
90
|
bad_pairs = [
|
|
91
91
|
(cirq.GridQubit(0, 0), cirq.GridQubit(0, 0)),
|
|
92
92
|
(cirq.GridQubit(1, 0), cirq.GridQubit(1, 1)),
|
|
@@ -95,7 +95,7 @@ def test_griddevice_self_loop():
|
|
|
95
95
|
_ = cirq.GridDeviceMetadata(bad_pairs, cirq.Gateset(cirq.XPowGate))
|
|
96
96
|
|
|
97
97
|
|
|
98
|
-
def test_griddevice_json_load():
|
|
98
|
+
def test_griddevice_json_load() -> None:
|
|
99
99
|
qubits = cirq.GridQubit.rect(2, 3)
|
|
100
100
|
qubit_pairs = [(a, b) for a in qubits for b in qubits if a != b and a.is_adjacent(b)]
|
|
101
101
|
gateset = cirq.Gateset(cirq.XPowGate, cirq.YPowGate, cirq.ZPowGate, cirq.CZ)
|
|
@@ -118,7 +118,7 @@ def test_griddevice_json_load():
|
|
|
118
118
|
assert metadata == cirq.read_json(json_text=rep_str)
|
|
119
119
|
|
|
120
120
|
|
|
121
|
-
def test_griddevice_json_load_with_defaults():
|
|
121
|
+
def test_griddevice_json_load_with_defaults() -> None:
|
|
122
122
|
qubits = cirq.GridQubit.rect(2, 3)
|
|
123
123
|
qubit_pairs = [(a, b) for a in qubits for b in qubits if a != b and a.is_adjacent(b)]
|
|
124
124
|
gateset = cirq.Gateset(cirq.XPowGate, cirq.YPowGate, cirq.ZPowGate, cirq.CZ)
|
|
@@ -130,7 +130,7 @@ def test_griddevice_json_load_with_defaults():
|
|
|
130
130
|
assert metadata == cirq.read_json(json_text=rep_str)
|
|
131
131
|
|
|
132
132
|
|
|
133
|
-
def test_griddevice_metadata_equality():
|
|
133
|
+
def test_griddevice_metadata_equality() -> None:
|
|
134
134
|
qubits = cirq.GridQubit.rect(2, 3)
|
|
135
135
|
qubit_pairs = [(a, b) for a in qubits for b in qubits if a != b and a.is_adjacent(b)]
|
|
136
136
|
gateset = cirq.Gateset(cirq.XPowGate, cirq.YPowGate, cirq.ZPowGate, cirq.CZ, cirq.SQRT_ISWAP)
|
|
@@ -182,7 +182,7 @@ def test_griddevice_metadata_equality():
|
|
|
182
182
|
assert metadata == metadata5
|
|
183
183
|
|
|
184
184
|
|
|
185
|
-
def test_repr():
|
|
185
|
+
def test_repr() -> None:
|
|
186
186
|
qubits = cirq.GridQubit.rect(2, 3)
|
|
187
187
|
qubit_pairs = [(a, b) for a in qubits for b in qubits if a != b and a.is_adjacent(b)]
|
|
188
188
|
gateset = cirq.Gateset(cirq.XPowGate, cirq.YPowGate, cirq.ZPowGate, cirq.CZ)
|