cirq-core 1.5.0.dev20250131224919__py3-none-any.whl → 1.5.0.dev20250205194253__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/acquaintance/gates.py +4 -2
- cirq/contrib/qasm_import/_lexer.py +5 -41
- cirq/contrib/qasm_import/_lexer_test.py +21 -6
- cirq/contrib/qasm_import/_parser.py +5 -2
- cirq/contrib/qasm_import/_parser_test.py +19 -0
- cirq/ops/common_gates.py +11 -10
- cirq/ops/common_gates_test.py +10 -0
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +1 -0
- cirq/value/linear_dict.py +80 -22
- cirq/value/linear_dict_test.py +94 -3
- cirq/value/type_alias.py +2 -2
- cirq_core-1.5.0.dev20250205194253.dist-info/METADATA +119 -0
- {cirq_core-1.5.0.dev20250131224919.dist-info → cirq_core-1.5.0.dev20250205194253.dist-info}/RECORD +18 -18
- cirq_core-1.5.0.dev20250131224919.dist-info/METADATA +0 -69
- {cirq_core-1.5.0.dev20250131224919.dist-info → cirq_core-1.5.0.dev20250205194253.dist-info}/LICENSE +0 -0
- {cirq_core-1.5.0.dev20250131224919.dist-info → cirq_core-1.5.0.dev20250205194253.dist-info}/WHEEL +0 -0
- {cirq_core-1.5.0.dev20250131224919.dist-info → cirq_core-1.5.0.dev20250205194253.dist-info}/top_level.txt +0 -0
cirq/_version.py
CHANGED
cirq/_version_test.py
CHANGED
|
@@ -316,10 +316,12 @@ class SwapNetworkGate(PermutationGate):
|
|
|
316
316
|
parts_qubits = list(left_part + right_part)
|
|
317
317
|
parts[i] = parts_qubits[: len(right_part)]
|
|
318
318
|
parts[i + 1] = parts_qubits[len(right_part) :]
|
|
319
|
-
|
|
319
|
+
if op_sort_key is not None:
|
|
320
|
+
layers.prior_interstitial.sort(key=op_sort_key)
|
|
320
321
|
for l in ('prior_interstitial', 'pre', 'intra', 'post'):
|
|
321
322
|
yield getattr(layers, l)
|
|
322
|
-
|
|
323
|
+
if op_sort_key is not None:
|
|
324
|
+
layers.posterior_interstitial.sort(key=op_sort_key)
|
|
323
325
|
yield layers.posterior_interstitial
|
|
324
326
|
|
|
325
327
|
assert list(
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
|
|
15
15
|
import re
|
|
16
16
|
from typing import Optional
|
|
17
|
-
import numpy as np
|
|
18
17
|
import ply.lex as lex
|
|
19
18
|
|
|
20
19
|
from cirq.contrib.qasm_import.exception import QasmException
|
|
@@ -35,8 +34,7 @@ class QasmLexer:
|
|
|
35
34
|
'reset': 'RESET',
|
|
36
35
|
'gate': 'GATE',
|
|
37
36
|
'if': 'IF',
|
|
38
|
-
'
|
|
39
|
-
'==': 'EQ',
|
|
37
|
+
'pi': 'PI',
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
tokens = [
|
|
@@ -46,7 +44,8 @@ class QasmLexer:
|
|
|
46
44
|
'STDGATESINC',
|
|
47
45
|
'QELIBINC',
|
|
48
46
|
'ID',
|
|
49
|
-
'
|
|
47
|
+
'ARROW',
|
|
48
|
+
'EQ',
|
|
50
49
|
] + list(reserved.values())
|
|
51
50
|
|
|
52
51
|
def t_newline(self, t):
|
|
@@ -55,11 +54,6 @@ class QasmLexer:
|
|
|
55
54
|
|
|
56
55
|
t_ignore = ' \t'
|
|
57
56
|
|
|
58
|
-
def t_PI(self, t):
|
|
59
|
-
r"""pi"""
|
|
60
|
-
t.value = np.pi
|
|
61
|
-
return t
|
|
62
|
-
|
|
63
57
|
# all numbers except NATURAL_NUMBERs:
|
|
64
58
|
# it's useful to have this separation to be able to handle indices
|
|
65
59
|
# separately. In case of the parameter expressions, we are "OR"-ing
|
|
@@ -97,38 +91,6 @@ class QasmLexer:
|
|
|
97
91
|
r"""include(\s+)"stdgates.inc";"""
|
|
98
92
|
return t
|
|
99
93
|
|
|
100
|
-
def t_QREG(self, t):
|
|
101
|
-
r"""qreg"""
|
|
102
|
-
return t
|
|
103
|
-
|
|
104
|
-
def t_QUBIT(self, t):
|
|
105
|
-
r"""qubit"""
|
|
106
|
-
return t
|
|
107
|
-
|
|
108
|
-
def t_CREG(self, t):
|
|
109
|
-
r"""creg"""
|
|
110
|
-
return t
|
|
111
|
-
|
|
112
|
-
def t_BIT(self, t):
|
|
113
|
-
r"""bit"""
|
|
114
|
-
return t
|
|
115
|
-
|
|
116
|
-
def t_MEASURE(self, t):
|
|
117
|
-
r"""measure"""
|
|
118
|
-
return t
|
|
119
|
-
|
|
120
|
-
def t_RESET(self, t):
|
|
121
|
-
r"""reset"""
|
|
122
|
-
return t
|
|
123
|
-
|
|
124
|
-
def t_GATE(self, t):
|
|
125
|
-
r"""gate"""
|
|
126
|
-
return t
|
|
127
|
-
|
|
128
|
-
def t_IF(self, t):
|
|
129
|
-
r"""if"""
|
|
130
|
-
return t
|
|
131
|
-
|
|
132
94
|
def t_ARROW(self, t):
|
|
133
95
|
"""->"""
|
|
134
96
|
return t
|
|
@@ -139,6 +101,8 @@ class QasmLexer:
|
|
|
139
101
|
|
|
140
102
|
def t_ID(self, t):
|
|
141
103
|
r"""[a-zA-Z][a-zA-Z\d_]*"""
|
|
104
|
+
if t.value in QasmLexer.reserved:
|
|
105
|
+
t.type = QasmLexer.reserved[t.value]
|
|
142
106
|
return t
|
|
143
107
|
|
|
144
108
|
def t_COMMENT(self, t):
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
import pytest
|
|
16
|
-
import numpy as np
|
|
17
16
|
from cirq.contrib.qasm_import import QasmException
|
|
18
17
|
from cirq.contrib.qasm_import._lexer import QasmLexer
|
|
19
18
|
|
|
@@ -103,12 +102,28 @@ def test_numbers(number: str):
|
|
|
103
102
|
assert token.value == float(number)
|
|
104
103
|
|
|
105
104
|
|
|
106
|
-
|
|
105
|
+
@pytest.mark.parametrize('token', QasmLexer.reserved.keys())
|
|
106
|
+
def test_keywords(token):
|
|
107
107
|
lexer = QasmLexer()
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
assert
|
|
108
|
+
identifier = f'{token} {token}'
|
|
109
|
+
lexer.input(identifier)
|
|
110
|
+
t = lexer.token()
|
|
111
|
+
assert t.type == QasmLexer.reserved[token]
|
|
112
|
+
assert t.value == token
|
|
113
|
+
t2 = lexer.token()
|
|
114
|
+
assert t2.type == QasmLexer.reserved[token]
|
|
115
|
+
assert t2.value == token
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@pytest.mark.parametrize('token', QasmLexer.reserved.keys())
|
|
119
|
+
@pytest.mark.parametrize('separator', ['', '_'])
|
|
120
|
+
def test_identifier_starts_or_ends_with_keyword(token, separator):
|
|
121
|
+
lexer = QasmLexer()
|
|
122
|
+
identifier = f'{token}{separator}{token}'
|
|
123
|
+
lexer.input(identifier)
|
|
124
|
+
t = lexer.token()
|
|
125
|
+
assert t.type == "ID"
|
|
126
|
+
assert t.value == identifier
|
|
112
127
|
|
|
113
128
|
|
|
114
129
|
def test_qreg():
|
|
@@ -510,10 +510,13 @@ class QasmParser:
|
|
|
510
510
|
|
|
511
511
|
def p_term(self, p):
|
|
512
512
|
"""term : NUMBER
|
|
513
|
-
| NATURAL_NUMBER
|
|
514
|
-
| PI"""
|
|
513
|
+
| NATURAL_NUMBER"""
|
|
515
514
|
p[0] = p[1]
|
|
516
515
|
|
|
516
|
+
def p_pi(self, p):
|
|
517
|
+
"""term : PI"""
|
|
518
|
+
p[0] = np.pi
|
|
519
|
+
|
|
517
520
|
# qargs : qarg ',' qargs
|
|
518
521
|
# | qarg ';'
|
|
519
522
|
|
|
@@ -1499,3 +1499,22 @@ def _test_parse_exception(qasm: str, cirq_err: str, qiskit_err: str | None):
|
|
|
1499
1499
|
"Skipped _test_qiskit_parse_exception because "
|
|
1500
1500
|
"qiskit isn't installed to verify against."
|
|
1501
1501
|
)
|
|
1502
|
+
|
|
1503
|
+
|
|
1504
|
+
def test_nested_custom_gate_has_keyword_in_name():
|
|
1505
|
+
qasm = """OPENQASM 2.0;
|
|
1506
|
+
include "qelib1.inc";
|
|
1507
|
+
qreg q[1];
|
|
1508
|
+
gate gateGate qb { x qb; }
|
|
1509
|
+
gate qregGate qa { gateGate qa; }
|
|
1510
|
+
qregGate q;
|
|
1511
|
+
"""
|
|
1512
|
+
qb = cirq.NamedQubit('qb')
|
|
1513
|
+
inner = cirq.FrozenCircuit(cirq.X(qb))
|
|
1514
|
+
qa = cirq.NamedQubit('qa')
|
|
1515
|
+
middle = cirq.FrozenCircuit(cirq.CircuitOperation(inner, qubit_map={qb: qa}))
|
|
1516
|
+
q_0 = cirq.NamedQubit('q_0')
|
|
1517
|
+
expected = cirq.Circuit(cirq.CircuitOperation(middle, qubit_map={qa: q_0}))
|
|
1518
|
+
parser = QasmParser()
|
|
1519
|
+
parsed_qasm = parser.parse(qasm)
|
|
1520
|
+
assert parsed_qasm.circuit == expected
|
cirq/ops/common_gates.py
CHANGED
|
@@ -258,11 +258,12 @@ class XPowGate(eigen_gate.EigenGate):
|
|
|
258
258
|
return result
|
|
259
259
|
|
|
260
260
|
def _pauli_expansion_(self) -> value.LinearDict[str]:
|
|
261
|
-
if
|
|
261
|
+
if self._dimension != 2:
|
|
262
262
|
return NotImplemented
|
|
263
263
|
phase = 1j ** (2 * self._exponent * (self._global_shift + 0.5))
|
|
264
|
-
angle =
|
|
265
|
-
|
|
264
|
+
angle = _pi(self._exponent) * self._exponent / 2
|
|
265
|
+
lib = sympy if protocols.is_parameterized(self) else np
|
|
266
|
+
return value.LinearDict({'I': phase * lib.cos(angle), 'X': -1j * phase * lib.sin(angle)})
|
|
266
267
|
|
|
267
268
|
def _circuit_diagram_info_(
|
|
268
269
|
self, args: 'cirq.CircuitDiagramInfoArgs'
|
|
@@ -464,11 +465,10 @@ class YPowGate(eigen_gate.EigenGate):
|
|
|
464
465
|
return abs(np.sin(self._exponent * 0.5 * np.pi))
|
|
465
466
|
|
|
466
467
|
def _pauli_expansion_(self) -> value.LinearDict[str]:
|
|
467
|
-
if protocols.is_parameterized(self):
|
|
468
|
-
return NotImplemented
|
|
469
468
|
phase = 1j ** (2 * self._exponent * (self._global_shift + 0.5))
|
|
470
|
-
angle =
|
|
471
|
-
|
|
469
|
+
angle = _pi(self._exponent) * self._exponent / 2
|
|
470
|
+
lib = sympy if protocols.is_parameterized(self) else np
|
|
471
|
+
return value.LinearDict({'I': phase * lib.cos(angle), 'Y': -1j * phase * lib.sin(angle)})
|
|
472
472
|
|
|
473
473
|
def _circuit_diagram_info_(
|
|
474
474
|
self, args: 'cirq.CircuitDiagramInfoArgs'
|
|
@@ -764,11 +764,12 @@ class ZPowGate(eigen_gate.EigenGate):
|
|
|
764
764
|
return abs(np.sin(self._exponent * 0.5 * np.pi))
|
|
765
765
|
|
|
766
766
|
def _pauli_expansion_(self) -> value.LinearDict[str]:
|
|
767
|
-
if
|
|
767
|
+
if self._dimension != 2:
|
|
768
768
|
return NotImplemented
|
|
769
769
|
phase = 1j ** (2 * self._exponent * (self._global_shift + 0.5))
|
|
770
|
-
angle =
|
|
771
|
-
|
|
770
|
+
angle = _pi(self._exponent) * self._exponent / 2
|
|
771
|
+
lib = sympy if protocols.is_parameterized(self) else np
|
|
772
|
+
return value.LinearDict({'I': phase * lib.cos(angle), 'Z': -1j * phase * lib.sin(angle)})
|
|
772
773
|
|
|
773
774
|
def _phase_by_(self, phase_turns: float, qubit_index: int):
|
|
774
775
|
return self
|
cirq/ops/common_gates_test.py
CHANGED
|
@@ -1300,3 +1300,13 @@ def test_wrong_dims():
|
|
|
1300
1300
|
|
|
1301
1301
|
with pytest.raises(ValueError, match='Wrong shape'):
|
|
1302
1302
|
_ = cirq.Z.on(cirq.LineQid(0, dimension=3))
|
|
1303
|
+
|
|
1304
|
+
|
|
1305
|
+
@pytest.mark.parametrize('gate_type', [cirq.XPowGate, cirq.YPowGate, cirq.ZPowGate])
|
|
1306
|
+
@pytest.mark.parametrize('exponent', [sympy.Symbol('s'), sympy.Symbol('s') * 2])
|
|
1307
|
+
def test_parameterized_pauli_expansion(gate_type, exponent):
|
|
1308
|
+
gate = gate_type(exponent=exponent)
|
|
1309
|
+
pauli = cirq.pauli_expansion(gate)
|
|
1310
|
+
gate_resolved = cirq.resolve_parameters(gate, {'s': 0.5})
|
|
1311
|
+
pauli_resolved = cirq.resolve_parameters(pauli, {'s': 0.5})
|
|
1312
|
+
assert cirq.approx_eq(pauli_resolved, cirq.pauli_expansion(gate_resolved))
|
cirq/value/linear_dict.py
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"""Linear combination represented as mapping of things to coefficients."""
|
|
16
16
|
|
|
17
17
|
from typing import (
|
|
18
|
+
AbstractSet,
|
|
18
19
|
Any,
|
|
19
20
|
Callable,
|
|
20
21
|
Dict,
|
|
@@ -28,6 +29,7 @@ from typing import (
|
|
|
28
29
|
Optional,
|
|
29
30
|
overload,
|
|
30
31
|
Tuple,
|
|
32
|
+
TYPE_CHECKING,
|
|
31
33
|
TypeVar,
|
|
32
34
|
Union,
|
|
33
35
|
ValuesView,
|
|
@@ -35,6 +37,11 @@ from typing import (
|
|
|
35
37
|
from typing_extensions import Self
|
|
36
38
|
|
|
37
39
|
import numpy as np
|
|
40
|
+
import sympy
|
|
41
|
+
from cirq import protocols
|
|
42
|
+
|
|
43
|
+
if TYPE_CHECKING:
|
|
44
|
+
import cirq
|
|
38
45
|
|
|
39
46
|
Scalar = Union[complex, np.number]
|
|
40
47
|
TVector = TypeVar('TVector')
|
|
@@ -42,7 +49,23 @@ TVector = TypeVar('TVector')
|
|
|
42
49
|
TDefault = TypeVar('TDefault')
|
|
43
50
|
|
|
44
51
|
|
|
45
|
-
|
|
52
|
+
class _SympyPrinter(sympy.printing.str.StrPrinter):
|
|
53
|
+
def __init__(self, format_spec: str):
|
|
54
|
+
super().__init__()
|
|
55
|
+
self._format_spec = format_spec
|
|
56
|
+
|
|
57
|
+
def _print(self, expr, **kwargs):
|
|
58
|
+
if expr.is_complex:
|
|
59
|
+
coefficient = complex(expr)
|
|
60
|
+
s = _format_coefficient(self._format_spec, coefficient)
|
|
61
|
+
return s[1:-1] if s.startswith('(') else s
|
|
62
|
+
return super()._print(expr, **kwargs)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _format_coefficient(format_spec: str, coefficient: 'cirq.TParamValComplex') -> str:
|
|
66
|
+
if isinstance(coefficient, sympy.Basic):
|
|
67
|
+
printer = _SympyPrinter(format_spec)
|
|
68
|
+
return printer.doprint(coefficient)
|
|
46
69
|
coefficient = complex(coefficient)
|
|
47
70
|
real_str = f'{coefficient.real:{format_spec}}'
|
|
48
71
|
imag_str = f'{coefficient.imag:{format_spec}}'
|
|
@@ -59,7 +82,7 @@ def _format_coefficient(format_spec: str, coefficient: Scalar) -> str:
|
|
|
59
82
|
return f'({real_str}+{imag_str}j)'
|
|
60
83
|
|
|
61
84
|
|
|
62
|
-
def _format_term(format_spec: str, vector: TVector, coefficient:
|
|
85
|
+
def _format_term(format_spec: str, vector: TVector, coefficient: 'cirq.TParamValComplex') -> str:
|
|
63
86
|
coefficient_str = _format_coefficient(format_spec, coefficient)
|
|
64
87
|
if not coefficient_str:
|
|
65
88
|
return coefficient_str
|
|
@@ -69,7 +92,7 @@ def _format_term(format_spec: str, vector: TVector, coefficient: Scalar) -> str:
|
|
|
69
92
|
return '+' + result
|
|
70
93
|
|
|
71
94
|
|
|
72
|
-
def _format_terms(terms: Iterable[Tuple[TVector,
|
|
95
|
+
def _format_terms(terms: Iterable[Tuple[TVector, 'cirq.TParamValComplex']], format_spec: str):
|
|
73
96
|
formatted_terms = [_format_term(format_spec, vector, coeff) for vector, coeff in terms]
|
|
74
97
|
s = ''.join(formatted_terms)
|
|
75
98
|
if not s:
|
|
@@ -79,7 +102,7 @@ def _format_terms(terms: Iterable[Tuple[TVector, Scalar]], format_spec: str):
|
|
|
79
102
|
return s
|
|
80
103
|
|
|
81
104
|
|
|
82
|
-
class LinearDict(Generic[TVector], MutableMapping[TVector,
|
|
105
|
+
class LinearDict(Generic[TVector], MutableMapping[TVector, 'cirq.TParamValComplex']):
|
|
83
106
|
"""Represents linear combination of things.
|
|
84
107
|
|
|
85
108
|
LinearDict implements the basic linear algebraic operations of vector
|
|
@@ -96,7 +119,7 @@ class LinearDict(Generic[TVector], MutableMapping[TVector, Scalar]):
|
|
|
96
119
|
|
|
97
120
|
def __init__(
|
|
98
121
|
self,
|
|
99
|
-
terms: Optional[Mapping[TVector,
|
|
122
|
+
terms: Optional[Mapping[TVector, 'cirq.TParamValComplex']] = None,
|
|
100
123
|
validator: Optional[Callable[[TVector], bool]] = None,
|
|
101
124
|
) -> None:
|
|
102
125
|
"""Initializes linear combination from a collection of terms.
|
|
@@ -112,13 +135,18 @@ class LinearDict(Generic[TVector], MutableMapping[TVector, Scalar]):
|
|
|
112
135
|
"""
|
|
113
136
|
self._has_validator = validator is not None
|
|
114
137
|
self._is_valid = validator or (lambda x: True)
|
|
115
|
-
self._terms: Dict[TVector,
|
|
138
|
+
self._terms: Dict[TVector, 'cirq.TParamValComplex'] = {}
|
|
116
139
|
if terms is not None:
|
|
117
140
|
self.update(terms)
|
|
118
141
|
|
|
119
142
|
@classmethod
|
|
120
143
|
def fromkeys(cls, vectors, coefficient=0):
|
|
121
|
-
return LinearDict(
|
|
144
|
+
return LinearDict(
|
|
145
|
+
dict.fromkeys(
|
|
146
|
+
vectors,
|
|
147
|
+
coefficient if isinstance(coefficient, sympy.Basic) else complex(coefficient),
|
|
148
|
+
)
|
|
149
|
+
)
|
|
122
150
|
|
|
123
151
|
def _check_vector_valid(self, vector: TVector) -> None:
|
|
124
152
|
if not self._is_valid(vector):
|
|
@@ -126,7 +154,11 @@ class LinearDict(Generic[TVector], MutableMapping[TVector, Scalar]):
|
|
|
126
154
|
|
|
127
155
|
def clean(self, *, atol: float = 1e-9) -> Self:
|
|
128
156
|
"""Remove terms with coefficients of absolute value atol or less."""
|
|
129
|
-
negligible = [
|
|
157
|
+
negligible = [
|
|
158
|
+
v
|
|
159
|
+
for v, c in self._terms.items()
|
|
160
|
+
if not isinstance(c, sympy.Basic) and abs(complex(c)) <= atol
|
|
161
|
+
]
|
|
130
162
|
for v in negligible:
|
|
131
163
|
del self._terms[v]
|
|
132
164
|
return self
|
|
@@ -139,40 +171,50 @@ class LinearDict(Generic[TVector], MutableMapping[TVector, Scalar]):
|
|
|
139
171
|
snapshot = self.copy().clean(atol=0)
|
|
140
172
|
return snapshot._terms.keys()
|
|
141
173
|
|
|
142
|
-
def values(self) -> ValuesView[
|
|
174
|
+
def values(self) -> ValuesView['cirq.TParamValComplex']:
|
|
143
175
|
snapshot = self.copy().clean(atol=0)
|
|
144
176
|
return snapshot._terms.values()
|
|
145
177
|
|
|
146
|
-
def items(self) -> ItemsView[TVector,
|
|
178
|
+
def items(self) -> ItemsView[TVector, 'cirq.TParamValComplex']:
|
|
147
179
|
snapshot = self.copy().clean(atol=0)
|
|
148
180
|
return snapshot._terms.items()
|
|
149
181
|
|
|
150
182
|
# pylint: disable=function-redefined
|
|
151
183
|
@overload
|
|
152
|
-
def update(
|
|
184
|
+
def update(
|
|
185
|
+
self, other: Mapping[TVector, 'cirq.TParamValComplex'], **kwargs: 'cirq.TParamValComplex'
|
|
186
|
+
) -> None:
|
|
153
187
|
pass
|
|
154
188
|
|
|
155
189
|
@overload
|
|
156
|
-
def update(
|
|
190
|
+
def update(
|
|
191
|
+
self,
|
|
192
|
+
other: Iterable[Tuple[TVector, 'cirq.TParamValComplex']],
|
|
193
|
+
**kwargs: 'cirq.TParamValComplex',
|
|
194
|
+
) -> None:
|
|
157
195
|
pass
|
|
158
196
|
|
|
159
197
|
@overload
|
|
160
|
-
def update(self, *args: Any, **kwargs:
|
|
198
|
+
def update(self, *args: Any, **kwargs: 'cirq.TParamValComplex') -> None:
|
|
161
199
|
pass
|
|
162
200
|
|
|
163
201
|
def update(self, *args, **kwargs):
|
|
164
202
|
terms = dict()
|
|
165
203
|
terms.update(*args, **kwargs)
|
|
166
204
|
for vector, coefficient in terms.items():
|
|
205
|
+
if isinstance(coefficient, sympy.Basic):
|
|
206
|
+
coefficient = sympy.simplify(coefficient)
|
|
207
|
+
if coefficient.is_complex:
|
|
208
|
+
coefficient = complex(coefficient)
|
|
167
209
|
self[vector] = coefficient
|
|
168
210
|
self.clean(atol=0)
|
|
169
211
|
|
|
170
212
|
@overload
|
|
171
|
-
def get(self, vector: TVector) ->
|
|
213
|
+
def get(self, vector: TVector) -> 'cirq.TParamValComplex':
|
|
172
214
|
pass
|
|
173
215
|
|
|
174
216
|
@overload
|
|
175
|
-
def get(self, vector: TVector, default: TDefault) -> Union[
|
|
217
|
+
def get(self, vector: TVector, default: TDefault) -> Union['cirq.TParamValComplex', TDefault]:
|
|
176
218
|
pass
|
|
177
219
|
|
|
178
220
|
def get(self, vector, default=0):
|
|
@@ -185,10 +227,10 @@ class LinearDict(Generic[TVector], MutableMapping[TVector, Scalar]):
|
|
|
185
227
|
def __contains__(self, vector: Any) -> bool:
|
|
186
228
|
return vector in self._terms and self._terms[vector] != 0
|
|
187
229
|
|
|
188
|
-
def __getitem__(self, vector: TVector) ->
|
|
230
|
+
def __getitem__(self, vector: TVector) -> 'cirq.TParamValComplex':
|
|
189
231
|
return self._terms.get(vector, 0)
|
|
190
232
|
|
|
191
|
-
def __setitem__(self, vector: TVector, coefficient:
|
|
233
|
+
def __setitem__(self, vector: TVector, coefficient: 'cirq.TParamValComplex') -> None:
|
|
192
234
|
self._check_vector_valid(vector)
|
|
193
235
|
if coefficient != 0:
|
|
194
236
|
self._terms[vector] = coefficient
|
|
@@ -236,21 +278,21 @@ class LinearDict(Generic[TVector], MutableMapping[TVector, Scalar]):
|
|
|
236
278
|
factory = type(self)
|
|
237
279
|
return factory({v: -c for v, c in self.items()})
|
|
238
280
|
|
|
239
|
-
def __imul__(self, a:
|
|
281
|
+
def __imul__(self, a: 'cirq.TParamValComplex') -> Self:
|
|
240
282
|
for vector in self:
|
|
241
283
|
self._terms[vector] *= a
|
|
242
284
|
self.clean(atol=0)
|
|
243
285
|
return self
|
|
244
286
|
|
|
245
|
-
def __mul__(self, a:
|
|
287
|
+
def __mul__(self, a: 'cirq.TParamValComplex') -> Self:
|
|
246
288
|
result = self.copy()
|
|
247
289
|
result *= a
|
|
248
|
-
return result
|
|
290
|
+
return result.copy()
|
|
249
291
|
|
|
250
|
-
def __rmul__(self, a:
|
|
292
|
+
def __rmul__(self, a: 'cirq.TParamValComplex') -> Self:
|
|
251
293
|
return self.__mul__(a)
|
|
252
294
|
|
|
253
|
-
def __truediv__(self, a:
|
|
295
|
+
def __truediv__(self, a: 'cirq.TParamValComplex') -> Self:
|
|
254
296
|
return self.__mul__(1 / a)
|
|
255
297
|
|
|
256
298
|
def __bool__(self) -> bool:
|
|
@@ -320,3 +362,19 @@ class LinearDict(Generic[TVector], MutableMapping[TVector, Scalar]):
|
|
|
320
362
|
@classmethod
|
|
321
363
|
def _from_json_dict_(cls, keys, values, **kwargs):
|
|
322
364
|
return cls(terms=dict(zip(keys, values)))
|
|
365
|
+
|
|
366
|
+
def _is_parameterized_(self) -> bool:
|
|
367
|
+
return any(protocols.is_parameterized(v) for v in self._terms.values())
|
|
368
|
+
|
|
369
|
+
def _parameter_names_(self) -> AbstractSet[str]:
|
|
370
|
+
return set(name for v in self._terms.values() for name in protocols.parameter_names(v))
|
|
371
|
+
|
|
372
|
+
def _resolve_parameters_(self, resolver: 'cirq.ParamResolver', recursive: bool) -> 'LinearDict':
|
|
373
|
+
result = self.copy()
|
|
374
|
+
result.update(
|
|
375
|
+
{
|
|
376
|
+
k: protocols.resolve_parameters(v, resolver, recursive)
|
|
377
|
+
for k, v in self._terms.items()
|
|
378
|
+
}
|
|
379
|
+
)
|
|
380
|
+
return result
|
cirq/value/linear_dict_test.py
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
import numpy as np
|
|
16
16
|
import pytest
|
|
17
|
+
import sympy
|
|
17
18
|
|
|
18
19
|
import cirq
|
|
19
20
|
|
|
@@ -24,6 +25,12 @@ def test_empty_init():
|
|
|
24
25
|
assert not v
|
|
25
26
|
|
|
26
27
|
|
|
28
|
+
sym = sympy.Symbol('sym')
|
|
29
|
+
expr = sym * -(2 + 3j)
|
|
30
|
+
symval = expr.subs({'sym': 5})
|
|
31
|
+
symvalresolved = -10 - 15j
|
|
32
|
+
|
|
33
|
+
|
|
27
34
|
@pytest.mark.parametrize(
|
|
28
35
|
'keys, coefficient, terms_expected',
|
|
29
36
|
(
|
|
@@ -31,6 +38,9 @@ def test_empty_init():
|
|
|
31
38
|
(('X',), 2, {'X': 2}),
|
|
32
39
|
(('a', 'b', 'c', 'd'), 0.5, {'a': 0.5, 'b': 0.5, 'c': 0.5, 'd': 0.5}),
|
|
33
40
|
(('b', 'c', 'd', 'e'), -2j, {'b': -2j, 'c': -2j, 'd': -2j, 'e': -2j}),
|
|
41
|
+
(('b', 'c'), sym, {'b': sym, 'c': sym}),
|
|
42
|
+
(('b', 'c'), expr, {'b': expr, 'c': expr}),
|
|
43
|
+
(('b', 'c'), symval, {'b': symvalresolved, 'c': symvalresolved}),
|
|
34
44
|
),
|
|
35
45
|
)
|
|
36
46
|
def test_fromkeys(keys, coefficient, terms_expected):
|
|
@@ -273,6 +283,9 @@ def test_len(terms, expected_length):
|
|
|
273
283
|
({'X': 1}, {'Y': 2}, {'X': 1, 'Y': 2}),
|
|
274
284
|
({'X': 1}, {'X': 1}, {'X': 2}),
|
|
275
285
|
({'X': 1, 'Y': 2}, {'Y': -2}, {'X': 1}),
|
|
286
|
+
({'X': 1}, {'X': sym}, {'X': sym + 1}),
|
|
287
|
+
({'X': 1}, {'X': expr}, {'X': expr + 1}),
|
|
288
|
+
({'X': 1}, {'X': symval}, {'X': symvalresolved + 1}),
|
|
276
289
|
),
|
|
277
290
|
)
|
|
278
291
|
def test_vector_addition(terms_1, terms_2, terms_expected):
|
|
@@ -297,6 +310,9 @@ def test_vector_addition(terms_1, terms_2, terms_expected):
|
|
|
297
310
|
({'X': 1}, {'X': 1}, {}),
|
|
298
311
|
({'X': 1, 'Y': 2}, {'Y': 2}, {'X': 1}),
|
|
299
312
|
({'X': 1, 'Y': 2}, {'Y': 3}, {'X': 1, 'Y': -1}),
|
|
313
|
+
({'X': 1}, {'X': sym}, {'X': 1 - sym}),
|
|
314
|
+
({'X': 1}, {'X': expr}, {'X': 1 - expr}),
|
|
315
|
+
({'X': 1}, {'X': symval}, {'X': 1 - symvalresolved}),
|
|
300
316
|
),
|
|
301
317
|
)
|
|
302
318
|
def test_vector_subtraction(terms_1, terms_2, terms_expected):
|
|
@@ -313,7 +329,14 @@ def test_vector_subtraction(terms_1, terms_2, terms_expected):
|
|
|
313
329
|
|
|
314
330
|
@pytest.mark.parametrize(
|
|
315
331
|
'terms, terms_expected',
|
|
316
|
-
(
|
|
332
|
+
(
|
|
333
|
+
({}, {}),
|
|
334
|
+
({'key': 1}, {'key': -1}),
|
|
335
|
+
({'1': 10, '2': -20}, {'1': -10, '2': 20}),
|
|
336
|
+
({'key': sym}, {'key': -sym}),
|
|
337
|
+
({'key': expr}, {'key': -expr}),
|
|
338
|
+
({'key': symval}, {'key': -symvalresolved}),
|
|
339
|
+
),
|
|
317
340
|
)
|
|
318
341
|
def test_vector_negation(terms, terms_expected):
|
|
319
342
|
linear_dict = cirq.LinearDict(terms)
|
|
@@ -331,6 +354,12 @@ def test_vector_negation(terms, terms_expected):
|
|
|
331
354
|
(0, {'abc': 10, 'def': 20}, {}),
|
|
332
355
|
(1j, {'X': 4j}, {'X': -4}),
|
|
333
356
|
(-1, {'a': 10, 'b': -20}, {'a': -10, 'b': 20}),
|
|
357
|
+
(2, {'X': sym}, {'X': 2 * sym}),
|
|
358
|
+
(2, {'X': expr}, {'X': 2 * expr}),
|
|
359
|
+
(2, {'X': symval}, {'X': 2 * symvalresolved}),
|
|
360
|
+
(sym, {'X': 2}, {'X': 2 * sym}),
|
|
361
|
+
(expr, {'X': 2}, {'X': 2 * expr}),
|
|
362
|
+
(symval, {'X': 2}, {'X': 2 * symvalresolved}),
|
|
334
363
|
),
|
|
335
364
|
)
|
|
336
365
|
def test_scalar_multiplication(scalar, terms, terms_expected):
|
|
@@ -350,6 +379,12 @@ def test_scalar_multiplication(scalar, terms, terms_expected):
|
|
|
350
379
|
(2, {'X': 6, 'Y': -2}, {'X': 3, 'Y': -1}),
|
|
351
380
|
(1j, {'X': 1, 'Y': 1j}, {'X': -1j, 'Y': 1}),
|
|
352
381
|
(-1, {'a': 10, 'b': -20}, {'a': -10, 'b': 20}),
|
|
382
|
+
(2, {'X': sym}, {'X': 0.5 * sym}),
|
|
383
|
+
(2, {'X': expr}, {'X': 0.5 * expr}),
|
|
384
|
+
(2, {'X': symval}, {'X': 0.5 * symvalresolved}),
|
|
385
|
+
(sym, {'X': 2}, {'X': 2 / sym}),
|
|
386
|
+
(expr, {'X': 2}, {'X': 2 / expr}),
|
|
387
|
+
(symval, {'X': 2}, {'X': 2 / symvalresolved}),
|
|
353
388
|
),
|
|
354
389
|
)
|
|
355
390
|
def test_scalar_division(scalar, terms, terms_expected):
|
|
@@ -387,7 +422,13 @@ def test_bool(terms, bool_value):
|
|
|
387
422
|
|
|
388
423
|
@pytest.mark.parametrize(
|
|
389
424
|
'terms_1, terms_2',
|
|
390
|
-
(
|
|
425
|
+
(
|
|
426
|
+
({}, {}),
|
|
427
|
+
({}, {'X': 0}),
|
|
428
|
+
({'X': 0.0}, {'Y': 0.0}),
|
|
429
|
+
({'a': 1}, {'a': 1, 'b': 0}),
|
|
430
|
+
({'X': sym}, {'X': sym}),
|
|
431
|
+
),
|
|
391
432
|
)
|
|
392
433
|
def test_equal(terms_1, terms_2):
|
|
393
434
|
linear_dict_1 = cirq.LinearDict(terms_1)
|
|
@@ -405,6 +446,7 @@ def test_equal(terms_1, terms_2):
|
|
|
405
446
|
({'X': 1e-12}, {'X': 0}),
|
|
406
447
|
({'X': 0.0}, {'Y': 0.1}),
|
|
407
448
|
({'X': 1}, {'X': 1, 'Z': 1e-12}),
|
|
449
|
+
({'X': sym + 0.1}, {'X': sym}),
|
|
408
450
|
),
|
|
409
451
|
)
|
|
410
452
|
def test_unequal(terms_1, terms_2):
|
|
@@ -423,6 +465,7 @@ def test_unequal(terms_1, terms_2):
|
|
|
423
465
|
({'X': 1e-12}, {'X': 0}),
|
|
424
466
|
({'X': 5e-10}, {'Y': 2e-11}),
|
|
425
467
|
({'X': 1.000000001}, {'X': 1, 'Z': 0}),
|
|
468
|
+
({'X': sym + 0.000000001}, {'X': sym}),
|
|
426
469
|
),
|
|
427
470
|
)
|
|
428
471
|
def test_approximately_equal(terms_1, terms_2):
|
|
@@ -476,7 +519,20 @@ def test_format(terms, fmt, expected_string):
|
|
|
476
519
|
assert actual_string.replace(' ', '') == expected_string.replace(' ', '')
|
|
477
520
|
|
|
478
521
|
|
|
479
|
-
@pytest.mark.parametrize(
|
|
522
|
+
@pytest.mark.parametrize(
|
|
523
|
+
'terms',
|
|
524
|
+
(
|
|
525
|
+
(
|
|
526
|
+
{},
|
|
527
|
+
{'X': 1},
|
|
528
|
+
{'X': 2, 'Y': 3},
|
|
529
|
+
{'X': 1.23456789e-12},
|
|
530
|
+
{'X': sym},
|
|
531
|
+
({'X': sym * 2}),
|
|
532
|
+
{'X': symval},
|
|
533
|
+
)
|
|
534
|
+
),
|
|
535
|
+
)
|
|
480
536
|
def test_repr(terms):
|
|
481
537
|
original = cirq.LinearDict(terms)
|
|
482
538
|
recovered = eval(repr(original))
|
|
@@ -502,6 +558,10 @@ def test_repr(terms):
|
|
|
502
558
|
({'X': -2, 'Y': -3}, '-2.000*X-3.000*Y'),
|
|
503
559
|
({'X': -2j, 'Y': -3}, '-2.000j*X-3.000*Y'),
|
|
504
560
|
({'X': -2j, 'Y': -3j}, '-2.000j*X-3.000j*Y'),
|
|
561
|
+
({'X': sym}, 'sym*X'),
|
|
562
|
+
({'X': sym * 2}, '2.000*sym*X'),
|
|
563
|
+
({'X': expr}, '-sym*(2.000+3.000j)*X'),
|
|
564
|
+
({'X': symval}, '-(10.000+15.000j)*X'),
|
|
505
565
|
),
|
|
506
566
|
)
|
|
507
567
|
def test_str(terms, string):
|
|
@@ -547,3 +607,34 @@ def test_repr_pretty(terms):
|
|
|
547
607
|
def test_json_fails_with_validator():
|
|
548
608
|
with pytest.raises(ValueError, match='not json serializable'):
|
|
549
609
|
_ = cirq.to_json(cirq.LinearDict({}, validator=lambda: True))
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
@pytest.mark.parametrize(
|
|
613
|
+
'terms, names',
|
|
614
|
+
(
|
|
615
|
+
({'X': sym}, {'sym'}),
|
|
616
|
+
({'X': sym * sympy.Symbol('a')}, {'sym', 'a'}),
|
|
617
|
+
({'X': expr}, {'sym'}),
|
|
618
|
+
({'X': sym, 'Y': sympy.Symbol('a')}, {'sym', 'a'}),
|
|
619
|
+
({'X': symval}, set()),
|
|
620
|
+
),
|
|
621
|
+
)
|
|
622
|
+
def test_parameter_names(terms, names):
|
|
623
|
+
linear_dict = cirq.LinearDict(terms)
|
|
624
|
+
assert cirq.parameter_names(linear_dict) == names
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
@pytest.mark.parametrize(
|
|
628
|
+
'terms, expected',
|
|
629
|
+
(
|
|
630
|
+
({'X': sym}, {'X': 2}),
|
|
631
|
+
({'X': sym * sympy.Symbol('a')}, {'X': 6}),
|
|
632
|
+
({'X': expr}, {'X': -4 - 6j}),
|
|
633
|
+
({'X': sym, 'Y': sympy.Symbol('a')}, {'X': 2, 'Y': 3}),
|
|
634
|
+
({'X': symval}, {'X': symvalresolved}),
|
|
635
|
+
),
|
|
636
|
+
)
|
|
637
|
+
def test_resolve_parameters(terms, expected):
|
|
638
|
+
linear_dict = cirq.LinearDict(terms)
|
|
639
|
+
expected_dict = cirq.LinearDict(expected)
|
|
640
|
+
assert cirq.resolve_parameters(linear_dict, {'sym': 2, 'a': 3}) == expected_dict
|
cirq/value/type_alias.py
CHANGED
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
|
|
15
15
|
from typing import Union
|
|
16
16
|
|
|
17
|
+
import numpy as np
|
|
17
18
|
import sympy
|
|
18
19
|
|
|
19
20
|
from cirq._doc import document
|
|
20
|
-
from cirq.value import linear_dict
|
|
21
21
|
|
|
22
22
|
"""Supply aliases for commonly used types.
|
|
23
23
|
"""
|
|
@@ -28,5 +28,5 @@ document(TParamKey, """A parameter that a parameter resolver may map to a value.
|
|
|
28
28
|
TParamVal = Union[float, sympy.Expr]
|
|
29
29
|
document(TParamVal, """A value that a parameter resolver may return for a parameter.""")
|
|
30
30
|
|
|
31
|
-
TParamValComplex = Union[
|
|
31
|
+
TParamValComplex = Union[complex, np.number, sympy.Expr]
|
|
32
32
|
document(TParamValComplex, """A complex value that parameter resolvers may use for parameters.""")
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: cirq-core
|
|
3
|
+
Version: 1.5.0.dev20250205194253
|
|
4
|
+
Summary: A framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
|
|
5
|
+
Home-page: http://github.com/quantumlib/cirq
|
|
6
|
+
Author: The Cirq Developers
|
|
7
|
+
Author-email: cirq-dev@googlegroups.com
|
|
8
|
+
Maintainer: The Quantum AI open-source software maintainers
|
|
9
|
+
Maintainer-email: quantum-oss-maintainers@google.com
|
|
10
|
+
License: Apache 2
|
|
11
|
+
Keywords: algorithms,api,cirq,google,google quantum,nisq,python,quantum,quantum algorithms,quantum circuit,quantum circuit simulator,quantum computer simulator,quantum computing,quantum development kit,quantum information,quantum programming,quantum programming language,quantum simulation,sdk,simulation
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Education
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
18
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
19
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Quantum Computing
|
|
26
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
+
Classifier: Typing :: Typed
|
|
28
|
+
Requires-Python: >=3.10.0
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: attrs>=21.3.0
|
|
32
|
+
Requires-Dist: duet>=0.2.8
|
|
33
|
+
Requires-Dist: matplotlib~=3.7
|
|
34
|
+
Requires-Dist: networkx~=3.1
|
|
35
|
+
Requires-Dist: numpy>=1.25
|
|
36
|
+
Requires-Dist: pandas~=2.0
|
|
37
|
+
Requires-Dist: sortedcontainers~=2.0
|
|
38
|
+
Requires-Dist: scipy~=1.11
|
|
39
|
+
Requires-Dist: sympy
|
|
40
|
+
Requires-Dist: typing-extensions>=4.2
|
|
41
|
+
Requires-Dist: tqdm
|
|
42
|
+
Provides-Extra: contrib
|
|
43
|
+
Requires-Dist: ply>=3.6; extra == "contrib"
|
|
44
|
+
Requires-Dist: pylatex~=1.4; extra == "contrib"
|
|
45
|
+
Requires-Dist: quimb>=1.8; extra == "contrib"
|
|
46
|
+
Requires-Dist: opt-einsum; extra == "contrib"
|
|
47
|
+
|
|
48
|
+
<div align='center' width='50%'>
|
|
49
|
+
|
|
50
|
+
| ⚠️ WARNING |
|
|
51
|
+
|:----------:|
|
|
52
|
+
| **This is a development version of `cirq-core` and may be<br>unstable. For the latest stable release of `cirq-core`,<br>please visit** <https://pypi.org/project/cirq-core>.|
|
|
53
|
+
|
|
54
|
+
</div>
|
|
55
|
+
|
|
56
|
+
<div align="center">
|
|
57
|
+
<img width="220px" alt="Cirq logo"
|
|
58
|
+
src="https://raw.githubusercontent.com/quantumlib/Cirq/refs/heads/main/docs/images/Cirq_logo_color.svg">
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
# cirq-core
|
|
62
|
+
|
|
63
|
+
[Cirq] is a Python package for writing, manipulating, and running [quantum
|
|
64
|
+
circuits](https://en.wikipedia.org/wiki/Quantum_circuit) on quantum computers
|
|
65
|
+
and simulators. Cirq provides useful abstractions for dealing with today’s
|
|
66
|
+
[noisy intermediate-scale quantum](https://arxiv.org/abs/1801.00862) (NISQ)
|
|
67
|
+
computers, where the details of quantum hardware are vital to achieving
|
|
68
|
+
state-of-the-art results. For more information about Cirq, please visit the
|
|
69
|
+
[Cirq documentation site].
|
|
70
|
+
|
|
71
|
+
This Python module is `cirq-core`, which contains all the code you need to
|
|
72
|
+
write quantum algorithms for NISQ devices and run them on the built-in Cirq
|
|
73
|
+
simulators.
|
|
74
|
+
|
|
75
|
+
To run algorithms on a given quantum computing platform, you will also need to
|
|
76
|
+
install an appropriate Cirq hardware interface module. Please visit the
|
|
77
|
+
[hardware section of the Cirq documentation
|
|
78
|
+
site](https://quantumai.google/cirq/hardware) for information about the
|
|
79
|
+
hardware interface modules currently available.
|
|
80
|
+
|
|
81
|
+
[Cirq]: https://github.com/quantumlib/cirq
|
|
82
|
+
[Cirq documentation site]: https://quantumai.google/cirq
|
|
83
|
+
|
|
84
|
+
## Installation
|
|
85
|
+
|
|
86
|
+
There are two installation options for the `cirq-core` module:
|
|
87
|
+
|
|
88
|
+
* To install the stable version of `cirq-core`, use
|
|
89
|
+
|
|
90
|
+
```shell
|
|
91
|
+
pip install cirq-core
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
* To install the latest pre-release version of `cirq-core`, use
|
|
95
|
+
|
|
96
|
+
```shell
|
|
97
|
+
pip install cirq-core~=1.0.dev
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
(The `~=` has a special meaning to `pip` of selecting the latest version
|
|
101
|
+
compatible with the `1.*` and `dev` in the name. Despite appearances,
|
|
102
|
+
this will not install an old version 1.0 release!)
|
|
103
|
+
|
|
104
|
+
If you would like to install Cirq with all the optional modules, not just
|
|
105
|
+
`cirq-core`, then instead of the above commands, use `pip install cirq` for the
|
|
106
|
+
stable release or `pip install cirq~=1.0.dev` for the latest pre-release
|
|
107
|
+
version.
|
|
108
|
+
|
|
109
|
+
## Documentation
|
|
110
|
+
|
|
111
|
+
To get started with using Cirq, please refer to the [Cirq documentation site].
|
|
112
|
+
|
|
113
|
+
For more information about getting help, reporting bugs, and other matters
|
|
114
|
+
related to Cirq and the Cirq-Core integration module, please visit the [Cirq
|
|
115
|
+
repository on GitHub](https://github.com/quantumlib/Cirq).
|
|
116
|
+
|
|
117
|
+
## Disclaimer
|
|
118
|
+
|
|
119
|
+
Cirq is not an official Google product. Copyright 2019 The Cirq Developers.
|
{cirq_core-1.5.0.dev20250131224919.dist-info → cirq_core-1.5.0.dev20250205194253.dist-info}/RECORD
RENAMED
|
@@ -4,8 +4,8 @@ cirq/_compat_test.py,sha256=Qq3ZcfgD-Nb81cEppQdJqhAyrVqXKtfXZYGXT0p-Wh0,34718
|
|
|
4
4
|
cirq/_doc.py,sha256=yDyWUD_2JDS0gShfGRb-rdqRt9-WeL7DhkqX7np0Nko,2879
|
|
5
5
|
cirq/_import.py,sha256=p9gMHJscbtDDkfHOaulvd3Aer0pwUF5AXpL89XR8dNw,8402
|
|
6
6
|
cirq/_import_test.py,sha256=6K_v0riZJXOXUphHNkGA8MY-JcmGlezFaGmvrNhm3OQ,1015
|
|
7
|
-
cirq/_version.py,sha256=
|
|
8
|
-
cirq/_version_test.py,sha256=
|
|
7
|
+
cirq/_version.py,sha256=gno6a2CDY4sCjlypTFIKWsy9N09lk98yTKvycQ5GjAg,1206
|
|
8
|
+
cirq/_version_test.py,sha256=GHzN2Nz4dKpH8LxDN-lorBJIsoXHMSZSd_HhfTIklnk,147
|
|
9
9
|
cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
|
|
10
10
|
cirq/json_resolver_cache.py,sha256=p-vEOa-8GQ2cFIAdze-kd6C1un1uRvtujVPljVKaHBg,13557
|
|
11
11
|
cirq/py.typed,sha256=VFSlmh_lNwnaXzwY-ZuW-C2Ws5PkuDoVgBdNCs0jXJE,63
|
|
@@ -42,7 +42,7 @@ cirq/contrib/acquaintance/devices.py,sha256=1hWW9_WF5TZQXFMu9-yXNTk3GfSETyjikNbo
|
|
|
42
42
|
cirq/contrib/acquaintance/devices_test.py,sha256=icl_9SOp8PuZu7msfW5H7zP7_-zfTwTjyPPkajDu-w4,1088
|
|
43
43
|
cirq/contrib/acquaintance/executor.py,sha256=ZGPWcEVYAdkqA9rvECsp7WFgxYC_wAvfE6HKNqzT7AM,8681
|
|
44
44
|
cirq/contrib/acquaintance/executor_test.py,sha256=ir-LKuQTfHm5WCcjmLriJ8qCT89YnltLpFx89Q3bF_I,7837
|
|
45
|
-
cirq/contrib/acquaintance/gates.py,sha256=
|
|
45
|
+
cirq/contrib/acquaintance/gates.py,sha256=ZYEVM8CxY_jAuI7iuf8Fbn-rKHh9M8GFlUmA6AscnZE,13577
|
|
46
46
|
cirq/contrib/acquaintance/gates_test.py,sha256=5FVX7zAtZSUqDPNsXk_Wm7LwDmHIApzgNhjAIX1IQBM,15010
|
|
47
47
|
cirq/contrib/acquaintance/inspection_utils.py,sha256=-olAKpSZPm4Q9xhaQwAjT2ovUqZQd5zXAJ0ImkffOWk,2607
|
|
48
48
|
cirq/contrib/acquaintance/inspection_utils_test.py,sha256=N5WyOkZaP7Vy0DRoiq6ZtQ1S99j5F7XyRPnyRLJqmtM,1250
|
|
@@ -103,10 +103,10 @@ cirq/contrib/paulistring/recombine_test.py,sha256=hJ083nR67JsIs38TfmCjmBLnhqyG0r
|
|
|
103
103
|
cirq/contrib/paulistring/separate.py,sha256=2g4l78mXYJDR6xkv51VExZDb-rm5JEvhYrpMPgWa0Us,3961
|
|
104
104
|
cirq/contrib/paulistring/separate_test.py,sha256=FzR78MSHDhNJxizbXreK6u3BeYhT7xn7W1QyHfEZ34E,1267
|
|
105
105
|
cirq/contrib/qasm_import/__init__.py,sha256=RKX0vGDC2Pe5rH5rM4ClXdvtrAU16ePFImQpiJtJVNo,744
|
|
106
|
-
cirq/contrib/qasm_import/_lexer.py,sha256
|
|
107
|
-
cirq/contrib/qasm_import/_lexer_test.py,sha256=
|
|
108
|
-
cirq/contrib/qasm_import/_parser.py,sha256=
|
|
109
|
-
cirq/contrib/qasm_import/_parser_test.py,sha256=
|
|
106
|
+
cirq/contrib/qasm_import/_lexer.py,sha256=-72amAxuZbkybMH-xBynqYqx1-TnRVpl51Dd2qtjjCY,2928
|
|
107
|
+
cirq/contrib/qasm_import/_lexer_test.py,sha256=mgzCMoXwngMOJ8JZYVqaSNRIiZEnnzpla_3jo9UMLjQ,6217
|
|
108
|
+
cirq/contrib/qasm_import/_parser.py,sha256=S9Yme100Yp3Ye8wGoCm0MkAeweOvPI1uOV7UbbDoEDc,26053
|
|
109
|
+
cirq/contrib/qasm_import/_parser_test.py,sha256=PL0Os1pZmvS8xg8kgXoeEng322lR9nlpBrlanKzmkyU,39925
|
|
110
110
|
cirq/contrib/qasm_import/exception.py,sha256=Wm6cwUPIkNMPjkv-ELpQ-zSoXaiLOddOQ4iYybwuS6I,695
|
|
111
111
|
cirq/contrib/qasm_import/qasm.py,sha256=CP444IWCw4zlDNA7HxsTJ2xIak4mZhQv62ZiLlUc2zo,914
|
|
112
112
|
cirq/contrib/qasm_import/qasm_test.py,sha256=e5b7LVn_6FIFZ6kINqMzJFIjzgtTgutVhgXgX_DcTc0,1861
|
|
@@ -277,8 +277,8 @@ cirq/ops/common_channels.py,sha256=go4yhaRw0XNAr3TUBJ59SOhn2SKxf6bHmmrOHPbBYCY,3
|
|
|
277
277
|
cirq/ops/common_channels_test.py,sha256=nQsSSxu7vtedb3ZUuw4hNKIX7MYI4x8lxvLyWMZNt10,30079
|
|
278
278
|
cirq/ops/common_gate_families.py,sha256=e5M8wlDYtdrpWBrhdns6iizIvSqzfxDyIsBdxt8hVMc,8611
|
|
279
279
|
cirq/ops/common_gate_families_test.py,sha256=Oo3C7BPO3gt3ePuqwsI_lx_lY38et8Ps4AuVydX2Aww,5275
|
|
280
|
-
cirq/ops/common_gates.py,sha256=
|
|
281
|
-
cirq/ops/common_gates_test.py,sha256=
|
|
280
|
+
cirq/ops/common_gates.py,sha256=0kQPjqB5vZmjKyUiQj-B_08cZ5wxTfa8e_5wfu4ce50,58209
|
|
281
|
+
cirq/ops/common_gates_test.py,sha256=tNymwCOXCgVe6JnrHSq7kwzCO-ucQZYHdBF9cvdZRMo,46731
|
|
282
282
|
cirq/ops/control_values.py,sha256=nNDN6pgz_aWkUfrpOZ9zHHD42AGFaplWhVQj9rmJwbQ,13410
|
|
283
283
|
cirq/ops/control_values_test.py,sha256=iDtdQjL39u80MaR16XLp00LRZqWgJqC54cIeADWf0IY,12906
|
|
284
284
|
cirq/ops/controlled_gate.py,sha256=8ELuov5mOUp_cNwwrwMEjB4NwDph4Cpi7ezABx86W8Y,14261
|
|
@@ -1081,7 +1081,7 @@ cirq/transformers/analytical_decompositions/__init__.py,sha256=hMsoQSQtSvEn5mNoh
|
|
|
1081
1081
|
cirq/transformers/analytical_decompositions/clifford_decomposition.py,sha256=DsuuP91pm2dX0CO4rWwmJAJyAfuXMcA1UJK0g8krp7k,6726
|
|
1082
1082
|
cirq/transformers/analytical_decompositions/clifford_decomposition_test.py,sha256=AAZh_9vEb5f2E_EItPZTlMRNdv0d47AwqTn4BytX0UI,7102
|
|
1083
1083
|
cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py,sha256=iFF2vb5tI4PVQVHBOP_tuy8EKUtGg8aMDZSdK-74YMI,8675
|
|
1084
|
-
cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py,sha256=
|
|
1084
|
+
cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py,sha256=sZ2eDF5foEyNhTDqSzTYKkug4CMY7QmF4NCN-FaA530,5050
|
|
1085
1085
|
cirq/transformers/analytical_decompositions/cphase_to_fsim.py,sha256=RDg0wzYa_YXBJepCgloD_OIwTOwNco98dqGoe0UsnhI,9108
|
|
1086
1086
|
cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py,sha256=bwZa0BDclAd1sX3bD-GdNF2MO5DtH7mw2YLppEK0LG0,5568
|
|
1087
1087
|
cirq/transformers/analytical_decompositions/pauli_string_decomposition.py,sha256=bU9IoY0igVZTmF_wsTdTxAfqPKWyqZ14Gt2AJoK5D_4,4524
|
|
@@ -1155,8 +1155,8 @@ cirq/value/digits.py,sha256=pUQi6PIA1FMbXUOWknefb6dBApCyLsTkpLFrhvNgE0Q,6024
|
|
|
1155
1155
|
cirq/value/digits_test.py,sha256=evx-y619LfjSN_gUO1B6K7O80X5HJmxxBPl61RrOovo,3812
|
|
1156
1156
|
cirq/value/duration.py,sha256=isNzA1TuKb5rSaAYy4JpgT91Zt9_5XLQBSmMkuWCtD4,10358
|
|
1157
1157
|
cirq/value/duration_test.py,sha256=C7nwg7IlHoQOUhWa_aX8vy7_qp654ZIDtmnKF35UiqE,8244
|
|
1158
|
-
cirq/value/linear_dict.py,sha256=
|
|
1159
|
-
cirq/value/linear_dict_test.py,sha256=
|
|
1158
|
+
cirq/value/linear_dict.py,sha256=KlyntK71PZOlozh35K6ZTIQoNxDnQ_i5z3wQSMhuCwU,12735
|
|
1159
|
+
cirq/value/linear_dict_test.py,sha256=H7-3yABo7J9T8HF8_orAE0DsIUrTjNIwArTkhgpQdsc,19872
|
|
1160
1160
|
cirq/value/measurement_key.py,sha256=glvyn36NylWMdtHYLFsD72jPZJsnKpFqQXKh8XpOX4Q,5200
|
|
1161
1161
|
cirq/value/measurement_key_test.py,sha256=GnEX5QdEVbmi0dR9URcgXQH23aqW7Y_PKmTb2eIdRCg,4466
|
|
1162
1162
|
cirq/value/periodic_value.py,sha256=U_tYBgWNVblZ6XDSwbXZin67KA0jUZiDAPpz-w7bnhw,3956
|
|
@@ -1169,7 +1169,7 @@ cirq/value/random_state.py,sha256=SA4owzMPof8P5FLPhGUPN7ODfciKAIY24PgxfmnJ5AY,20
|
|
|
1169
1169
|
cirq/value/random_state_test.py,sha256=0VyxtuBYgrbHsNCXFZtcgucd5KwI1obMjILH2ZTZ5BU,1348
|
|
1170
1170
|
cirq/value/timestamp.py,sha256=u0v5FmnSF_o3NE7aF-xIfQ5cDAVZzaUb-ZMdrxWYg2Y,3649
|
|
1171
1171
|
cirq/value/timestamp_test.py,sha256=eZt9LLVK6TQy-2Bo1djitUD4at7i7M4lN60bLCx9UPs,4029
|
|
1172
|
-
cirq/value/type_alias.py,sha256=
|
|
1172
|
+
cirq/value/type_alias.py,sha256=bmKOnIIiHbjU4x62QBxAPyvdzsyv9fGyMEBz_ivwBo8,1128
|
|
1173
1173
|
cirq/value/value_equality_attr.py,sha256=9tU54y5JUAGKsvNV9G1nCWJioP6gvTlYfGN7Pe3YebI,10545
|
|
1174
1174
|
cirq/value/value_equality_attr_test.py,sha256=k_nl5hWxo4yMO6WNu0wU68wyeb-RN9Ua_Ix7s9UTfOE,6412
|
|
1175
1175
|
cirq/vis/__init__.py,sha256=YzNrNjIyUiTxKHGzYw92qzOYzx8aXkm2y_1hkfVohtU,1171
|
|
@@ -1202,8 +1202,8 @@ cirq/work/sampler.py,sha256=bE5tmVkcR6cZZMLETxDfHehdsYUMbx2RvBeIBetehI4,19187
|
|
|
1202
1202
|
cirq/work/sampler_test.py,sha256=hL2UWx3dz2ukZVNxWftiKVvJcQoLplLZdQm-k1QcA40,13282
|
|
1203
1203
|
cirq/work/zeros_sampler.py,sha256=x1C7cup66a43n-3tm8QjhiqJa07qcJW10FxNp9jJ59Q,2356
|
|
1204
1204
|
cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
|
|
1205
|
-
cirq_core-1.5.0.
|
|
1206
|
-
cirq_core-1.5.0.
|
|
1207
|
-
cirq_core-1.5.0.
|
|
1208
|
-
cirq_core-1.5.0.
|
|
1209
|
-
cirq_core-1.5.0.
|
|
1205
|
+
cirq_core-1.5.0.dev20250205194253.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
|
|
1206
|
+
cirq_core-1.5.0.dev20250205194253.dist-info/METADATA,sha256=ZcjzsLqI_LBiMpwCu_YAiXnqdYey1CzEiYqFp1Ul7qo,4811
|
|
1207
|
+
cirq_core-1.5.0.dev20250205194253.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
1208
|
+
cirq_core-1.5.0.dev20250205194253.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
|
|
1209
|
+
cirq_core-1.5.0.dev20250205194253.dist-info/RECORD,,
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: cirq-core
|
|
3
|
-
Version: 1.5.0.dev20250131224919
|
|
4
|
-
Summary: A framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
|
|
5
|
-
Home-page: http://github.com/quantumlib/cirq
|
|
6
|
-
Author: The Cirq Developers
|
|
7
|
-
Author-email: cirq-dev@googlegroups.com
|
|
8
|
-
Maintainer: The Quantum AI open-source software maintainers
|
|
9
|
-
Maintainer-email: quantum-oss-maintainers@google.com
|
|
10
|
-
License: Apache 2
|
|
11
|
-
Keywords: algorithms,api,cirq,google,google quantum,nisq,python,quantum,quantum algorithms,quantum circuit,quantum circuit simulator,quantum computer simulator,quantum computing,quantum development kit,quantum information,quantum programming,quantum programming language,quantum simulation,sdk,simulation
|
|
12
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
-
Classifier: Intended Audience :: Developers
|
|
14
|
-
Classifier: Intended Audience :: Education
|
|
15
|
-
Classifier: Intended Audience :: Science/Research
|
|
16
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
-
Classifier: Operating System :: MacOS :: MacOS X
|
|
18
|
-
Classifier: Operating System :: Microsoft :: Windows
|
|
19
|
-
Classifier: Operating System :: POSIX :: Linux
|
|
20
|
-
Classifier: Programming Language :: Python :: 3
|
|
21
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
-
Classifier: Topic :: Scientific/Engineering :: Quantum Computing
|
|
26
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
-
Classifier: Typing :: Typed
|
|
28
|
-
Requires-Python: >=3.10.0
|
|
29
|
-
License-File: LICENSE
|
|
30
|
-
Requires-Dist: attrs>=21.3.0
|
|
31
|
-
Requires-Dist: duet>=0.2.8
|
|
32
|
-
Requires-Dist: matplotlib~=3.7
|
|
33
|
-
Requires-Dist: networkx~=3.1
|
|
34
|
-
Requires-Dist: numpy>=1.25
|
|
35
|
-
Requires-Dist: pandas~=2.0
|
|
36
|
-
Requires-Dist: sortedcontainers~=2.0
|
|
37
|
-
Requires-Dist: scipy~=1.11
|
|
38
|
-
Requires-Dist: sympy
|
|
39
|
-
Requires-Dist: typing-extensions>=4.2
|
|
40
|
-
Requires-Dist: tqdm
|
|
41
|
-
Provides-Extra: contrib
|
|
42
|
-
Requires-Dist: ply>=3.6; extra == "contrib"
|
|
43
|
-
Requires-Dist: pylatex~=1.4; extra == "contrib"
|
|
44
|
-
Requires-Dist: quimb>=1.8; extra == "contrib"
|
|
45
|
-
Requires-Dist: opt-einsum; extra == "contrib"
|
|
46
|
-
|
|
47
|
-
**This is a development version of Cirq-core and may be unstable.**
|
|
48
|
-
|
|
49
|
-
**For the latest stable release of Cirq-core see**
|
|
50
|
-
`here <https://pypi.org/project/cirq-core>`__.
|
|
51
|
-
|
|
52
|
-
.. image:: https://raw.githubusercontent.com/quantumlib/Cirq/main/docs/images/Cirq_logo_color.png
|
|
53
|
-
:target: https://github.com/quantumlib/cirq
|
|
54
|
-
:alt: Cirq
|
|
55
|
-
:width: 500px
|
|
56
|
-
|
|
57
|
-
Cirq is a Python library for writing, manipulating, and optimizing quantum
|
|
58
|
-
circuits and running them against quantum computers and simulators.
|
|
59
|
-
|
|
60
|
-
This module is **cirq-core**, which contains everything you'd need to write quantum algorithms for NISQ devices and run them on the built-in Cirq simulators.
|
|
61
|
-
In order to run algorithms on a given quantum hardware platform, you'll have to install the right cirq module as well.
|
|
62
|
-
|
|
63
|
-
Installation
|
|
64
|
-
------------
|
|
65
|
-
|
|
66
|
-
To install the stable version of only **cirq-core**, use `pip install cirq-core`.
|
|
67
|
-
To install the pre-release version of only **cirq-core**, use `pip install cirq-core~=1.0.dev`.
|
|
68
|
-
|
|
69
|
-
To get all the optional modules installed as well, you'll have to use `pip install cirq` or `pip install cirq~=1.0.dev` for the pre-release version.
|
{cirq_core-1.5.0.dev20250131224919.dist-info → cirq_core-1.5.0.dev20250205194253.dist-info}/LICENSE
RENAMED
|
File without changes
|
{cirq_core-1.5.0.dev20250131224919.dist-info → cirq_core-1.5.0.dev20250205194253.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|