cirq-core 1.6.0.dev20250505215959__py3-none-any.whl → 1.6.0.dev20250507223949__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/_compat_test.py +4 -1
- cirq/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/circuits/insert_strategy.py +7 -5
- cirq/contrib/acquaintance/gates_test.py +3 -1
- cirq/contrib/graph_device/hypergraph.py +3 -1
- cirq/contrib/paulistring/clifford_optimize.py +2 -2
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +9 -3
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +2 -0
- cirq/contrib/paulistring/pauli_string_optimize.py +2 -0
- cirq/contrib/paulistring/recombine.py +1 -1
- cirq/contrib/paulistring/separate.py +5 -4
- cirq/contrib/qasm_import/qasm.py +2 -0
- cirq/contrib/quimb/density_matrix.py +4 -1
- cirq/contrib/quimb/state_vector.py +4 -1
- cirq/contrib/quirk/quirk_gate.py +3 -1
- cirq/contrib/routing/router.py +2 -0
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +4 -0
- cirq/experiments/fidelity_estimation.py +11 -5
- cirq/linalg/combinators.py +4 -2
- cirq/linalg/predicates.py +6 -1
- cirq/linalg/tolerance.py +4 -1
- cirq/neutral_atoms/convert_to_neutral_atom_gates.py +9 -3
- cirq/ops/clifford_gate_test.py +3 -1
- cirq/ops/pauli_string.py +3 -4
- cirq/ops/pauli_string_phasor.py +20 -3
- cirq/ops/pauli_string_phasor_test.py +2 -5
- cirq/ops/pauli_string_test.py +0 -147
- cirq/ops/projector.py +13 -8
- cirq/transformers/gauge_compiling/cphase_gauge.py +2 -0
- cirq/vis/heatmap.py +1 -1
- cirq/work/sampler.py +33 -34
- cirq/work/sampler_test.py +6 -2
- cirq/work/zeros_sampler.py +3 -1
- cirq/work/zeros_sampler_test.py +3 -1
- {cirq_core-1.6.0.dev20250505215959.dist-info → cirq_core-1.6.0.dev20250507223949.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250505215959.dist-info → cirq_core-1.6.0.dev20250507223949.dist-info}/RECORD +40 -40
- {cirq_core-1.6.0.dev20250505215959.dist-info → cirq_core-1.6.0.dev20250507223949.dist-info}/WHEEL +0 -0
- {cirq_core-1.6.0.dev20250505215959.dist-info → cirq_core-1.6.0.dev20250507223949.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250505215959.dist-info → cirq_core-1.6.0.dev20250507223949.dist-info}/top_level.txt +0 -0
cirq/ops/pauli_string_test.py
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
|
|
15
15
|
import itertools
|
|
16
16
|
import math
|
|
17
|
-
from typing import List
|
|
18
17
|
|
|
19
18
|
import numpy as np
|
|
20
19
|
import pytest
|
|
@@ -723,118 +722,6 @@ def test_to_z_basis_ops_product_state():
|
|
|
723
722
|
)
|
|
724
723
|
|
|
725
724
|
|
|
726
|
-
def _assert_pass_over(ops: List[cirq.Operation], before: cirq.PauliString, after: cirq.PauliString):
|
|
727
|
-
assert before.pass_operations_over(ops[::-1]) == after
|
|
728
|
-
assert after.pass_operations_over(ops, after_to_before=True) == before
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
@pytest.mark.parametrize('shift,sign', itertools.product(range(3), (-1, +1)))
|
|
732
|
-
def test_pass_operations_over_single(shift: int, sign: int):
|
|
733
|
-
q0, q1 = _make_qubits(2)
|
|
734
|
-
X, Y, Z = (cirq.Pauli.by_relative_index(pauli, shift) for pauli in (cirq.X, cirq.Y, cirq.Z))
|
|
735
|
-
|
|
736
|
-
op0 = cirq.SingleQubitCliffordGate.from_pauli(Y)(q1)
|
|
737
|
-
ps_before: cirq.PauliString[cirq.Qid] = cirq.PauliString({q0: X}, sign)
|
|
738
|
-
ps_after = ps_before
|
|
739
|
-
_assert_pass_over([op0], ps_before, ps_after)
|
|
740
|
-
|
|
741
|
-
op0 = cirq.SingleQubitCliffordGate.from_pauli(X)(q0)
|
|
742
|
-
op1 = cirq.SingleQubitCliffordGate.from_pauli(Y)(q1)
|
|
743
|
-
ps_before = cirq.PauliString({q0: X, q1: Y}, sign)
|
|
744
|
-
ps_after = ps_before
|
|
745
|
-
_assert_pass_over([op0, op1], ps_before, ps_after)
|
|
746
|
-
|
|
747
|
-
op0 = cirq.SingleQubitCliffordGate.from_double_map({Z: (X, False), X: (Z, False)})(q0)
|
|
748
|
-
ps_before = cirq.PauliString({q0: X, q1: Y}, sign)
|
|
749
|
-
ps_after = cirq.PauliString({q0: Z, q1: Y}, sign)
|
|
750
|
-
_assert_pass_over([op0], ps_before, ps_after)
|
|
751
|
-
|
|
752
|
-
op1 = cirq.SingleQubitCliffordGate.from_pauli(X)(q1)
|
|
753
|
-
ps_before = cirq.PauliString({q0: X, q1: Y}, sign)
|
|
754
|
-
ps_after = -ps_before
|
|
755
|
-
_assert_pass_over([op1], ps_before, ps_after)
|
|
756
|
-
|
|
757
|
-
ps_after = cirq.PauliString({q0: Z, q1: Y}, -sign)
|
|
758
|
-
_assert_pass_over([op0, op1], ps_before, ps_after)
|
|
759
|
-
|
|
760
|
-
op0 = cirq.SingleQubitCliffordGate.from_pauli(Z, True)(q0)
|
|
761
|
-
op1 = cirq.SingleQubitCliffordGate.from_pauli(X, True)(q0)
|
|
762
|
-
ps_before = cirq.PauliString({q0: X}, sign)
|
|
763
|
-
ps_after = cirq.PauliString({q0: Y}, -sign)
|
|
764
|
-
_assert_pass_over([op0, op1], ps_before, ps_after)
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
@pytest.mark.parametrize(
|
|
768
|
-
'shift,t_or_f1, t_or_f2,neg', itertools.product(range(3), *((True, False),) * 3)
|
|
769
|
-
)
|
|
770
|
-
def test_pass_operations_over_double(shift: int, t_or_f1: bool, t_or_f2: bool, neg: bool):
|
|
771
|
-
sign = -1 if neg else +1
|
|
772
|
-
q0, q1, q2 = _make_qubits(3)
|
|
773
|
-
X, Y, Z = (cirq.Pauli.by_relative_index(pauli, shift) for pauli in (cirq.X, cirq.Y, cirq.Z))
|
|
774
|
-
|
|
775
|
-
op0 = cirq.PauliInteractionGate(Z, t_or_f1, X, t_or_f2)(q0, q1)
|
|
776
|
-
ps_before = cirq.PauliString(qubit_pauli_map={q0: Z, q2: Y}, coefficient=sign)
|
|
777
|
-
ps_after = cirq.PauliString(qubit_pauli_map={q0: Z, q2: Y}, coefficient=sign)
|
|
778
|
-
assert_conjugation(ps_before, op0, ps_after, True)
|
|
779
|
-
_assert_pass_over([op0], ps_before, ps_after)
|
|
780
|
-
|
|
781
|
-
op0 = cirq.PauliInteractionGate(Y, t_or_f1, X, t_or_f2)(q0, q1)
|
|
782
|
-
ps_before = cirq.PauliString({q0: Z, q2: Y}, sign)
|
|
783
|
-
ps_after = cirq.PauliString({q0: Z, q2: Y, q1: X}, -sign if t_or_f2 else sign)
|
|
784
|
-
assert_conjugation(ps_before, op0, ps_after, True)
|
|
785
|
-
_assert_pass_over([op0], ps_before, ps_after)
|
|
786
|
-
|
|
787
|
-
op0 = cirq.PauliInteractionGate(Z, t_or_f1, X, t_or_f2)(q0, q1)
|
|
788
|
-
ps_before = cirq.PauliString({q0: Z, q1: Y}, sign)
|
|
789
|
-
ps_after = cirq.PauliString({q1: Y}, -sign if t_or_f1 else sign)
|
|
790
|
-
assert_conjugation(ps_before, op0, ps_after, True)
|
|
791
|
-
_assert_pass_over([op0], ps_before, ps_after)
|
|
792
|
-
|
|
793
|
-
op0 = cirq.PauliInteractionGate(Y, t_or_f1, X, t_or_f2)(q0, q1)
|
|
794
|
-
ps_before = cirq.PauliString({q0: Z, q1: Y}, sign)
|
|
795
|
-
ps_after = cirq.PauliString({q0: X, q1: Z}, -1 if neg ^ t_or_f1 ^ t_or_f2 else +1)
|
|
796
|
-
assert_conjugation(ps_before, op0, ps_after, True)
|
|
797
|
-
_assert_pass_over([op0], ps_before, ps_after)
|
|
798
|
-
|
|
799
|
-
op0 = cirq.PauliInteractionGate(X, t_or_f1, X, t_or_f2)(q0, q1)
|
|
800
|
-
ps_before = cirq.PauliString({q0: Z, q1: Y}, sign)
|
|
801
|
-
ps_after = cirq.PauliString({q0: Y, q1: Z}, +1 if neg ^ t_or_f1 ^ t_or_f2 else -1)
|
|
802
|
-
assert_conjugation(ps_before, op0, ps_after, True)
|
|
803
|
-
_assert_pass_over([op0], ps_before, ps_after)
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
def test_pass_operations_over_cz():
|
|
807
|
-
q0, q1 = _make_qubits(2)
|
|
808
|
-
op0 = cirq.CZ(q0, q1)
|
|
809
|
-
ps_before = cirq.PauliString({q0: cirq.Z, q1: cirq.Y})
|
|
810
|
-
ps_after = cirq.PauliString({q1: cirq.Y})
|
|
811
|
-
_assert_pass_over([op0], ps_before, ps_after)
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
def test_pass_operations_over_no_common_qubits():
|
|
815
|
-
class ExampleGate(cirq.testing.SingleQubitGate):
|
|
816
|
-
|
|
817
|
-
def _decompose_(self, qubits):
|
|
818
|
-
return cirq.X(qubits[0])
|
|
819
|
-
|
|
820
|
-
q0, q1 = _make_qubits(2)
|
|
821
|
-
op0 = ExampleGate()(q1)
|
|
822
|
-
ps_before = cirq.PauliString({q0: cirq.Z})
|
|
823
|
-
ps_after = cirq.PauliString({q0: cirq.Z})
|
|
824
|
-
_assert_pass_over([op0], ps_before, ps_after)
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
def test_pass_unsupported_operations_over():
|
|
828
|
-
(q0,) = _make_qubits(1)
|
|
829
|
-
pauli_string = cirq.PauliString({q0: cirq.X})
|
|
830
|
-
with pytest.raises(
|
|
831
|
-
ValueError,
|
|
832
|
-
match='Clifford Gate can only be constructed from the operations'
|
|
833
|
-
' that has stabilizer effect.',
|
|
834
|
-
):
|
|
835
|
-
pauli_string.pass_operations_over([cirq.T(q0)])
|
|
836
|
-
|
|
837
|
-
|
|
838
725
|
def test_with_qubits():
|
|
839
726
|
old_qubits = cirq.LineQubit.range(9)
|
|
840
727
|
new_qubits = cirq.LineQubit.range(9, 18)
|
|
@@ -1637,40 +1524,6 @@ def test_conjugated_by_ordering():
|
|
|
1637
1524
|
assert out1 == out2 == cirq.X(a) * cirq.Z(b)
|
|
1638
1525
|
|
|
1639
1526
|
|
|
1640
|
-
def test_pass_operations_over_ordering():
|
|
1641
|
-
class OrderSensitiveGate(cirq.Gate):
|
|
1642
|
-
def num_qubits(self):
|
|
1643
|
-
return 2
|
|
1644
|
-
|
|
1645
|
-
def _decompose_(self, qubits):
|
|
1646
|
-
return [cirq.Y(qubits[0]) ** -0.5, cirq.CNOT(*qubits)]
|
|
1647
|
-
|
|
1648
|
-
a, b = cirq.LineQubit.range(2)
|
|
1649
|
-
inp = cirq.Z(b)
|
|
1650
|
-
out1 = inp.pass_operations_over(OrderSensitiveGate().on(a, b))
|
|
1651
|
-
out2 = inp.pass_operations_over([cirq.CNOT(a, b), cirq.Y(a) ** -0.5])
|
|
1652
|
-
out3 = inp.pass_operations_over([cirq.CNOT(a, b)]).pass_operations_over([cirq.Y(a) ** -0.5])
|
|
1653
|
-
assert out1 == out2 == out3 == cirq.X(a) * cirq.Z(b)
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
def test_pass_operations_over_ordering_reversed():
|
|
1657
|
-
class OrderSensitiveGate(cirq.Gate):
|
|
1658
|
-
def num_qubits(self):
|
|
1659
|
-
return 2
|
|
1660
|
-
|
|
1661
|
-
def _decompose_(self, qubits):
|
|
1662
|
-
return [cirq.Y(qubits[0]) ** -0.5, cirq.CNOT(*qubits)]
|
|
1663
|
-
|
|
1664
|
-
a, b = cirq.LineQubit.range(2)
|
|
1665
|
-
inp = cirq.X(a) * cirq.Z(b)
|
|
1666
|
-
out1 = inp.pass_operations_over(OrderSensitiveGate().on(a, b), after_to_before=True)
|
|
1667
|
-
out2 = inp.pass_operations_over([cirq.Y(a) ** -0.5, cirq.CNOT(a, b)], after_to_before=True)
|
|
1668
|
-
out3 = inp.pass_operations_over([cirq.Y(a) ** -0.5], after_to_before=True).pass_operations_over(
|
|
1669
|
-
[cirq.CNOT(a, b)], after_to_before=True
|
|
1670
|
-
)
|
|
1671
|
-
assert out1 == out2 == out3 == cirq.Z(b)
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
1527
|
def test_pretty_print():
|
|
1675
1528
|
a, b, c = cirq.LineQubit.range(3)
|
|
1676
1529
|
result = cirq.PauliString({a: 'x', b: 'y', c: 'z'})
|
cirq/ops/projector.py
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
# pylint: disable=wrong-or-nonexistent-copyright-notice
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
2
5
|
import itertools
|
|
3
6
|
import math
|
|
4
|
-
from typing import Any, Dict, Iterable, List, Mapping, Optional
|
|
7
|
+
from typing import Any, Dict, Iterable, List, Mapping, Optional, TYPE_CHECKING
|
|
5
8
|
|
|
6
9
|
import numpy as np
|
|
7
10
|
from scipy.sparse import csr_matrix
|
|
8
11
|
|
|
9
12
|
from cirq import value
|
|
10
|
-
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
import cirq
|
|
11
16
|
|
|
12
17
|
|
|
13
18
|
def _check_qids_dimension(qids):
|
|
@@ -21,7 +26,7 @@ def _check_qids_dimension(qids):
|
|
|
21
26
|
class ProjectorString:
|
|
22
27
|
"""Mapping of `cirq.Qid` to measurement values (with a coefficient) representing a projector."""
|
|
23
28
|
|
|
24
|
-
def __init__(self, projector_dict: Dict[
|
|
29
|
+
def __init__(self, projector_dict: Dict[cirq.Qid, int], coefficient: complex = 1):
|
|
25
30
|
"""Constructor for ProjectorString
|
|
26
31
|
|
|
27
32
|
Args:
|
|
@@ -34,14 +39,14 @@ class ProjectorString:
|
|
|
34
39
|
self._coefficient = complex(coefficient)
|
|
35
40
|
|
|
36
41
|
@property
|
|
37
|
-
def projector_dict(self) -> Dict[
|
|
42
|
+
def projector_dict(self) -> Dict[cirq.Qid, int]:
|
|
38
43
|
return self._projector_dict
|
|
39
44
|
|
|
40
45
|
@property
|
|
41
46
|
def coefficient(self) -> complex:
|
|
42
47
|
return self._coefficient
|
|
43
48
|
|
|
44
|
-
def matrix(self, projector_qids: Optional[Iterable[
|
|
49
|
+
def matrix(self, projector_qids: Optional[Iterable[cirq.Qid]] = None) -> csr_matrix:
|
|
45
50
|
"""Returns the matrix of self in computational basis of qubits.
|
|
46
51
|
|
|
47
52
|
Args:
|
|
@@ -75,7 +80,7 @@ class ProjectorString:
|
|
|
75
80
|
([self._coefficient] * len(ones_idx), (ones_idx, ones_idx)), shape=(total_d, total_d)
|
|
76
81
|
)
|
|
77
82
|
|
|
78
|
-
def _get_idx_to_keep(self, qid_map: Mapping[
|
|
83
|
+
def _get_idx_to_keep(self, qid_map: Mapping[cirq.Qid, int]):
|
|
79
84
|
num_qubits = len(qid_map)
|
|
80
85
|
idx_to_keep: List[Any] = [slice(0, 2)] * num_qubits
|
|
81
86
|
for q in self.projector_dict.keys():
|
|
@@ -83,7 +88,7 @@ class ProjectorString:
|
|
|
83
88
|
return tuple(idx_to_keep)
|
|
84
89
|
|
|
85
90
|
def expectation_from_state_vector(
|
|
86
|
-
self, state_vector: np.ndarray, qid_map: Mapping[
|
|
91
|
+
self, state_vector: np.ndarray, qid_map: Mapping[cirq.Qid, int]
|
|
87
92
|
) -> complex:
|
|
88
93
|
"""Expectation of the projection from a state vector.
|
|
89
94
|
|
|
@@ -105,7 +110,7 @@ class ProjectorString:
|
|
|
105
110
|
)
|
|
106
111
|
|
|
107
112
|
def expectation_from_density_matrix(
|
|
108
|
-
self, state: np.ndarray, qid_map: Mapping[
|
|
113
|
+
self, state: np.ndarray, qid_map: Mapping[cirq.Qid, int]
|
|
109
114
|
) -> complex:
|
|
110
115
|
"""Expectation of the projection from a density matrix.
|
|
111
116
|
|
cirq/vis/heatmap.py
CHANGED
|
@@ -173,7 +173,7 @@ class Heatmap:
|
|
|
173
173
|
invalid_args = ", ".join([k for k in kwargs if k not in valid_kwargs])
|
|
174
174
|
raise ValueError(f"Received invalid argument(s): {invalid_args}")
|
|
175
175
|
|
|
176
|
-
def update_config(self, **kwargs) ->
|
|
176
|
+
def update_config(self, **kwargs) -> Heatmap:
|
|
177
177
|
"""Add/Modify **kwargs args passed during initialisation."""
|
|
178
178
|
self._validate_kwargs(kwargs)
|
|
179
179
|
self._config.update(kwargs)
|
cirq/work/sampler.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
|
"""Abstract base class for things sampling quantum circuits."""
|
|
15
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
16
19
|
import collections
|
|
17
20
|
from typing import Dict, FrozenSet, List, Optional, Sequence, Tuple, TYPE_CHECKING, TypeVar, Union
|
|
18
21
|
|
|
@@ -38,10 +41,10 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
38
41
|
|
|
39
42
|
def run(
|
|
40
43
|
self,
|
|
41
|
-
program:
|
|
42
|
-
param_resolver:
|
|
44
|
+
program: cirq.AbstractCircuit,
|
|
45
|
+
param_resolver: cirq.ParamResolverOrSimilarType = None,
|
|
43
46
|
repetitions: int = 1,
|
|
44
|
-
) ->
|
|
47
|
+
) -> cirq.Result:
|
|
45
48
|
"""Samples from the given `Circuit`.
|
|
46
49
|
|
|
47
50
|
This mode of operation for a sampler will provide results
|
|
@@ -66,10 +69,10 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
66
69
|
|
|
67
70
|
async def run_async(
|
|
68
71
|
self,
|
|
69
|
-
program:
|
|
70
|
-
param_resolver:
|
|
72
|
+
program: cirq.AbstractCircuit,
|
|
73
|
+
param_resolver: cirq.ParamResolverOrSimilarType = None,
|
|
71
74
|
repetitions: int = 1,
|
|
72
|
-
) ->
|
|
75
|
+
) -> cirq.Result:
|
|
73
76
|
"""Asynchronously samples from the given Circuit.
|
|
74
77
|
|
|
75
78
|
Provides measurement outcomes as a `cirq.Result` object. This
|
|
@@ -88,12 +91,8 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
88
91
|
return results[0]
|
|
89
92
|
|
|
90
93
|
def sample(
|
|
91
|
-
self,
|
|
92
|
-
|
|
93
|
-
*,
|
|
94
|
-
repetitions: int = 1,
|
|
95
|
-
params: 'cirq.Sweepable' = None,
|
|
96
|
-
) -> 'pd.DataFrame':
|
|
94
|
+
self, program: cirq.AbstractCircuit, *, repetitions: int = 1, params: cirq.Sweepable = None
|
|
95
|
+
) -> pd.DataFrame:
|
|
97
96
|
"""Samples the given Circuit, producing a pandas data frame.
|
|
98
97
|
|
|
99
98
|
This interface will operate in a similar way to the `run` method
|
|
@@ -180,21 +179,21 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
180
179
|
return pd.concat(results)
|
|
181
180
|
|
|
182
181
|
def _run_sweep_impl(
|
|
183
|
-
self, program:
|
|
184
|
-
) -> Sequence[
|
|
182
|
+
self, program: cirq.AbstractCircuit, params: cirq.Sweepable, repetitions: int = 1
|
|
183
|
+
) -> Sequence[cirq.Result]:
|
|
185
184
|
"""Implements run_sweep using run_sweep_async"""
|
|
186
185
|
return duet.run(self.run_sweep_async, program, params, repetitions)
|
|
187
186
|
|
|
188
187
|
async def _run_sweep_async_impl(
|
|
189
|
-
self, program:
|
|
190
|
-
) -> Sequence[
|
|
188
|
+
self, program: cirq.AbstractCircuit, params: cirq.Sweepable, repetitions: int = 1
|
|
189
|
+
) -> Sequence[cirq.Result]:
|
|
191
190
|
"""Implements run_sweep_async using run_sweep"""
|
|
192
191
|
return self.run_sweep(program, params=params, repetitions=repetitions)
|
|
193
192
|
|
|
194
193
|
@value.alternative(requires='run_sweep_async', implementation=_run_sweep_impl)
|
|
195
194
|
def run_sweep(
|
|
196
|
-
self, program:
|
|
197
|
-
) -> Sequence[
|
|
195
|
+
self, program: cirq.AbstractCircuit, params: cirq.Sweepable, repetitions: int = 1
|
|
196
|
+
) -> Sequence[cirq.Result]:
|
|
198
197
|
"""Samples from the given Circuit.
|
|
199
198
|
|
|
200
199
|
This allows for sweeping over different parameter values,
|
|
@@ -217,8 +216,8 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
217
216
|
|
|
218
217
|
@value.alternative(requires='run_sweep', implementation=_run_sweep_async_impl)
|
|
219
218
|
async def run_sweep_async(
|
|
220
|
-
self, program:
|
|
221
|
-
) -> Sequence[
|
|
219
|
+
self, program: cirq.AbstractCircuit, params: cirq.Sweepable, repetitions: int = 1
|
|
220
|
+
) -> Sequence[cirq.Result]:
|
|
222
221
|
"""Asynchronously samples from the given Circuit.
|
|
223
222
|
|
|
224
223
|
By default, this method invokes `run_sweep` synchronously and simply
|
|
@@ -237,10 +236,10 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
237
236
|
|
|
238
237
|
async def run_batch_async(
|
|
239
238
|
self,
|
|
240
|
-
programs: Sequence[
|
|
241
|
-
params_list: Optional[Sequence[
|
|
239
|
+
programs: Sequence[cirq.AbstractCircuit],
|
|
240
|
+
params_list: Optional[Sequence[cirq.Sweepable]] = None,
|
|
242
241
|
repetitions: Union[int, Sequence[int]] = 1,
|
|
243
|
-
) -> Sequence[Sequence[
|
|
242
|
+
) -> Sequence[Sequence[cirq.Result]]:
|
|
244
243
|
"""Runs the supplied circuits asynchronously.
|
|
245
244
|
|
|
246
245
|
Each circuit provided in `programs` will pair with the optional
|
|
@@ -288,10 +287,10 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
288
287
|
|
|
289
288
|
def _normalize_batch_args(
|
|
290
289
|
self,
|
|
291
|
-
programs: Sequence[
|
|
292
|
-
params_list: Optional[Sequence[
|
|
290
|
+
programs: Sequence[cirq.AbstractCircuit],
|
|
291
|
+
params_list: Optional[Sequence[cirq.Sweepable]] = None,
|
|
293
292
|
repetitions: Union[int, Sequence[int]] = 1,
|
|
294
|
-
) -> Tuple[Sequence[
|
|
293
|
+
) -> Tuple[Sequence[cirq.Sweepable], Sequence[int]]:
|
|
295
294
|
if params_list is None:
|
|
296
295
|
params_list = [None] * len(programs)
|
|
297
296
|
if len(programs) != len(params_list):
|
|
@@ -310,11 +309,11 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
310
309
|
|
|
311
310
|
def sample_expectation_values(
|
|
312
311
|
self,
|
|
313
|
-
program:
|
|
314
|
-
observables: Union[
|
|
312
|
+
program: cirq.AbstractCircuit,
|
|
313
|
+
observables: Union[cirq.PauliSumLike, List[cirq.PauliSumLike]],
|
|
315
314
|
*,
|
|
316
315
|
num_samples: int,
|
|
317
|
-
params:
|
|
316
|
+
params: cirq.Sweepable = None,
|
|
318
317
|
permit_terminal_measurements: bool = False,
|
|
319
318
|
) -> Sequence[Sequence[float]]:
|
|
320
319
|
"""Calculates estimated expectation values from samples of a circuit.
|
|
@@ -360,7 +359,7 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
360
359
|
)
|
|
361
360
|
|
|
362
361
|
# Wrap input into a list of pauli sum
|
|
363
|
-
pauli_sums: List[
|
|
362
|
+
pauli_sums: List[cirq.PauliSum] = (
|
|
364
363
|
[ops.PauliSum.wrap(o) for o in observables]
|
|
365
364
|
if isinstance(observables, List)
|
|
366
365
|
else [ops.PauliSum.wrap(observables)]
|
|
@@ -369,8 +368,8 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
369
368
|
|
|
370
369
|
# Flatten Pauli Sum into one big list of Pauli String
|
|
371
370
|
# Keep track of which Pauli Sum each one was from.
|
|
372
|
-
flat_pstrings: List[
|
|
373
|
-
pstring_to_psum_i: Dict[
|
|
371
|
+
flat_pstrings: List[cirq.PauliString] = []
|
|
372
|
+
pstring_to_psum_i: Dict[cirq.PauliString, int] = {}
|
|
374
373
|
for psum_i, pauli_sum in enumerate(pauli_sums):
|
|
375
374
|
for pstring in pauli_sum:
|
|
376
375
|
flat_pstrings.append(pstring)
|
|
@@ -378,7 +377,7 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
378
377
|
|
|
379
378
|
# Flatten Circuit Sweep into one big list of Params.
|
|
380
379
|
# Keep track of their indices so we can map back.
|
|
381
|
-
flat_params: List[
|
|
380
|
+
flat_params: List[cirq.ParamMappingType] = [
|
|
382
381
|
pr.param_dict for pr in study.to_resolvers(params)
|
|
383
382
|
]
|
|
384
383
|
circuit_param_to_sweep_i: Dict[FrozenSet[Tuple[str, Union[int, Tuple[int, int]]]], int] = {
|
|
@@ -409,7 +408,7 @@ class Sampler(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
409
408
|
|
|
410
409
|
@staticmethod
|
|
411
410
|
def _get_measurement_shapes(
|
|
412
|
-
circuit:
|
|
411
|
+
circuit: cirq.AbstractCircuit,
|
|
413
412
|
) -> Dict[str, Tuple[int, Tuple[int, ...]]]:
|
|
414
413
|
"""Gets the shapes of measurements in the given circuit.
|
|
415
414
|
|
cirq/work/sampler_test.py
CHANGED
|
@@ -11,7 +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
|
"""Tests for cirq.Sampler."""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
15
19
|
from typing import Sequence
|
|
16
20
|
|
|
17
21
|
import duet
|
|
@@ -285,8 +289,8 @@ def test_sampler_sample_expectation_values_calculation():
|
|
|
285
289
|
"""
|
|
286
290
|
|
|
287
291
|
def run_sweep(
|
|
288
|
-
self, program:
|
|
289
|
-
) -> Sequence[
|
|
292
|
+
self, program: cirq.AbstractCircuit, params: cirq.Sweepable, repetitions: int = 1
|
|
293
|
+
) -> Sequence[cirq.Result]:
|
|
290
294
|
results = np.zeros((repetitions, 1), dtype=bool)
|
|
291
295
|
for idx in range(repetitions // 4):
|
|
292
296
|
results[idx][0] = 1
|
cirq/work/zeros_sampler.py
CHANGED
|
@@ -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
|
import abc
|
|
16
18
|
from typing import List, Optional, TYPE_CHECKING
|
|
17
19
|
|
|
@@ -36,7 +38,7 @@ class ZerosSampler(work.Sampler, metaclass=abc.ABCMeta):
|
|
|
36
38
|
self.device = device
|
|
37
39
|
|
|
38
40
|
def run_sweep(
|
|
39
|
-
self, program:
|
|
41
|
+
self, program: cirq.AbstractCircuit, params: study.Sweepable, repetitions: int = 1
|
|
40
42
|
) -> List[study.Result]:
|
|
41
43
|
"""Samples circuit as if every measurement resulted in zero.
|
|
42
44
|
|
cirq/work/zeros_sampler_test.py
CHANGED
|
@@ -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
|
import numpy as np
|
|
16
18
|
import pytest
|
|
17
19
|
import sympy
|
|
@@ -72,7 +74,7 @@ def test_repeated_keys():
|
|
|
72
74
|
|
|
73
75
|
|
|
74
76
|
class OnlyMeasurementsDevice(cirq.Device):
|
|
75
|
-
def validate_operation(self, operation:
|
|
77
|
+
def validate_operation(self, operation: cirq.Operation) -> None:
|
|
76
78
|
if not cirq.is_measurement(operation):
|
|
77
79
|
raise ValueError(f'{operation} is not a measurement and this device only measures!')
|
|
78
80
|
|
{cirq_core-1.6.0.dev20250505215959.dist-info → cirq_core-1.6.0.dev20250507223949.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.dev20250507223949
|
|
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
|