cirq-core 1.5.0.dev20241120163208__py3-none-any.whl → 1.5.0.dev20241120233534__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/qasm_import/_lexer.py +24 -4
- cirq/contrib/qasm_import/_parser.py +35 -8
- cirq/contrib/qasm_import/_parser_test.py +48 -0
- cirq/protocols/qasm.py +10 -1
- cirq/protocols/qasm_test.py +12 -0
- {cirq_core-1.5.0.dev20241120163208.dist-info → cirq_core-1.5.0.dev20241120233534.dist-info}/METADATA +1 -1
- {cirq_core-1.5.0.dev20241120163208.dist-info → cirq_core-1.5.0.dev20241120233534.dist-info}/RECORD +12 -12
- {cirq_core-1.5.0.dev20241120163208.dist-info → cirq_core-1.5.0.dev20241120233534.dist-info}/LICENSE +0 -0
- {cirq_core-1.5.0.dev20241120163208.dist-info → cirq_core-1.5.0.dev20241120233534.dist-info}/WHEEL +0 -0
- {cirq_core-1.5.0.dev20241120163208.dist-info → cirq_core-1.5.0.dev20241120233534.dist-info}/top_level.txt +0 -0
cirq/_version.py
CHANGED
cirq/_version_test.py
CHANGED
|
@@ -24,10 +24,12 @@ class QasmLexer:
|
|
|
24
24
|
def __init__(self):
|
|
25
25
|
self.lex = lex.lex(object=self, debug=False)
|
|
26
26
|
|
|
27
|
-
literals = "{}[]()
|
|
27
|
+
literals = "{}[]();,+/*-^="
|
|
28
28
|
|
|
29
29
|
reserved = {
|
|
30
|
+
'qubit': 'QUBIT',
|
|
30
31
|
'qreg': 'QREG',
|
|
32
|
+
'bit': 'BIT',
|
|
31
33
|
'creg': 'CREG',
|
|
32
34
|
'measure': 'MEASURE',
|
|
33
35
|
'if': 'IF',
|
|
@@ -35,9 +37,15 @@ class QasmLexer:
|
|
|
35
37
|
'==': 'EQ',
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
tokens = [
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
tokens = [
|
|
41
|
+
'FORMAT_SPEC',
|
|
42
|
+
'NUMBER',
|
|
43
|
+
'NATURAL_NUMBER',
|
|
44
|
+
'STDGATESINC',
|
|
45
|
+
'QELIBINC',
|
|
46
|
+
'ID',
|
|
47
|
+
'PI',
|
|
48
|
+
] + list(reserved.values())
|
|
41
49
|
|
|
42
50
|
def t_newline(self, t):
|
|
43
51
|
r"""\n+"""
|
|
@@ -83,14 +91,26 @@ class QasmLexer:
|
|
|
83
91
|
r"""include(\s+)"qelib1.inc";"""
|
|
84
92
|
return t
|
|
85
93
|
|
|
94
|
+
def t_STDGATESINC(self, t):
|
|
95
|
+
r"""include(\s+)"stdgates.inc";"""
|
|
96
|
+
return t
|
|
97
|
+
|
|
86
98
|
def t_QREG(self, t):
|
|
87
99
|
r"""qreg"""
|
|
88
100
|
return t
|
|
89
101
|
|
|
102
|
+
def t_QUBIT(self, t):
|
|
103
|
+
r"""qubit"""
|
|
104
|
+
return t
|
|
105
|
+
|
|
90
106
|
def t_CREG(self, t):
|
|
91
107
|
r"""creg"""
|
|
92
108
|
return t
|
|
93
109
|
|
|
110
|
+
def t_BIT(self, t):
|
|
111
|
+
r"""bit"""
|
|
112
|
+
return t
|
|
113
|
+
|
|
94
114
|
def t_MEASURE(self, t):
|
|
95
115
|
r"""measure"""
|
|
96
116
|
return t
|
|
@@ -270,6 +270,7 @@ class QasmParser:
|
|
|
270
270
|
|
|
271
271
|
def p_qasm_no_format_specified_error(self, p):
|
|
272
272
|
"""qasm : QELIBINC
|
|
273
|
+
| STDGATESINC
|
|
273
274
|
| circuit"""
|
|
274
275
|
if self.supported_format is False:
|
|
275
276
|
raise QasmException("Missing 'OPENQASM 2.0;' statement")
|
|
@@ -279,15 +280,21 @@ class QasmParser:
|
|
|
279
280
|
self.qelibinc = True
|
|
280
281
|
p[0] = Qasm(self.supported_format, self.qelibinc, self.qregs, self.cregs, self.circuit)
|
|
281
282
|
|
|
283
|
+
def p_qasm_include_stdgates(self, p):
|
|
284
|
+
"""qasm : qasm STDGATESINC"""
|
|
285
|
+
self.qelibinc = True
|
|
286
|
+
p[0] = Qasm(self.supported_format, self.qelibinc, self.qregs, self.cregs, self.circuit)
|
|
287
|
+
|
|
282
288
|
def p_qasm_circuit(self, p):
|
|
283
289
|
"""qasm : qasm circuit"""
|
|
284
290
|
p[0] = Qasm(self.supported_format, self.qelibinc, self.qregs, self.cregs, p[2])
|
|
285
291
|
|
|
286
292
|
def p_format(self, p):
|
|
287
293
|
"""format : FORMAT_SPEC"""
|
|
288
|
-
if p[1]
|
|
294
|
+
if p[1] not in ["2.0", "3.0"]:
|
|
289
295
|
raise QasmException(
|
|
290
|
-
f"Unsupported OpenQASM version: {p[1]},
|
|
296
|
+
f"Unsupported OpenQASM version: {p[1]}, "
|
|
297
|
+
"only 2.0 and 3.0 are supported currently by Cirq"
|
|
291
298
|
)
|
|
292
299
|
|
|
293
300
|
# circuit : new_reg circuit
|
|
@@ -315,13 +322,28 @@ class QasmParser:
|
|
|
315
322
|
|
|
316
323
|
def p_new_reg(self, p):
|
|
317
324
|
"""new_reg : QREG ID '[' NATURAL_NUMBER ']' ';'
|
|
318
|
-
|
|
|
319
|
-
|
|
325
|
+
| QUBIT '[' NATURAL_NUMBER ']' ID ';'
|
|
326
|
+
| QUBIT ID ';'
|
|
327
|
+
| CREG ID '[' NATURAL_NUMBER ']' ';'
|
|
328
|
+
| BIT '[' NATURAL_NUMBER ']' ID ';'
|
|
329
|
+
| BIT ID ';'
|
|
330
|
+
"""
|
|
331
|
+
if p[1] == "qreg" or p[1] == "creg":
|
|
332
|
+
# QREG ID '[' NATURAL_NUMBER ']' ';'
|
|
333
|
+
name, length = p[2], p[4]
|
|
334
|
+
else:
|
|
335
|
+
if len(p) < 5:
|
|
336
|
+
# QUBIT ID ';' | BIT ID ';'
|
|
337
|
+
name = p[2]
|
|
338
|
+
length = 1
|
|
339
|
+
else:
|
|
340
|
+
# QUBIT '[' NATURAL_NUMBER ']' ID ';'
|
|
341
|
+
name, length = p[5], p[3]
|
|
320
342
|
if name in self.qregs.keys() or name in self.cregs.keys():
|
|
321
343
|
raise QasmException(f"{name} is already defined at line {p.lineno(2)}")
|
|
322
344
|
if length == 0:
|
|
323
345
|
raise QasmException(f"Illegal, zero-length register '{name}' at line {p.lineno(4)}")
|
|
324
|
-
if p[1] == "qreg":
|
|
346
|
+
if p[1] == "qreg" or p[1] == "qubit":
|
|
325
347
|
self.qregs[name] = length
|
|
326
348
|
else:
|
|
327
349
|
self.cregs[name] = length
|
|
@@ -485,9 +507,14 @@ class QasmParser:
|
|
|
485
507
|
# measurement : MEASURE qarg ARROW carg
|
|
486
508
|
|
|
487
509
|
def p_measurement(self, p):
|
|
488
|
-
"""measurement : MEASURE qarg ARROW carg ';'
|
|
489
|
-
|
|
490
|
-
|
|
510
|
+
"""measurement : MEASURE qarg ARROW carg ';'
|
|
511
|
+
| carg '=' MEASURE qarg ';'"""
|
|
512
|
+
if p[1] == 'measure':
|
|
513
|
+
qreg = p[2]
|
|
514
|
+
creg = p[4]
|
|
515
|
+
else:
|
|
516
|
+
qreg = p[4]
|
|
517
|
+
creg = p[1]
|
|
491
518
|
|
|
492
519
|
if len(qreg) != len(creg):
|
|
493
520
|
raise QasmException(
|
|
@@ -1057,3 +1057,51 @@ def test_single_qubit_gates(qasm_gate: str, cirq_gate: cirq.Gate):
|
|
|
1057
1057
|
|
|
1058
1058
|
ct.assert_same_circuits(parsed_qasm.circuit, expected_circuit)
|
|
1059
1059
|
assert parsed_qasm.qregs == {'q': 2}
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
def test_openqasm_3_0_qubits():
|
|
1063
|
+
qasm = """OPENQASM 3.0;
|
|
1064
|
+
include "stdgates.inc";
|
|
1065
|
+
qubit[2] q;
|
|
1066
|
+
bit[2] b;
|
|
1067
|
+
|
|
1068
|
+
x q[0];
|
|
1069
|
+
|
|
1070
|
+
b[0] = measure q[0];
|
|
1071
|
+
"""
|
|
1072
|
+
parser = QasmParser()
|
|
1073
|
+
|
|
1074
|
+
q0 = cirq.NamedQubit('q_0')
|
|
1075
|
+
|
|
1076
|
+
expected_circuit = Circuit([cirq.X.on(q0), cirq.measure(q0, key='b_0')])
|
|
1077
|
+
|
|
1078
|
+
parsed_qasm = parser.parse(qasm)
|
|
1079
|
+
|
|
1080
|
+
assert parsed_qasm.supportedFormat
|
|
1081
|
+
|
|
1082
|
+
ct.assert_same_circuits(parsed_qasm.circuit, expected_circuit)
|
|
1083
|
+
assert parsed_qasm.qregs == {'q': 2}
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
def test_openqasm_3_0_scalar_qubit():
|
|
1087
|
+
qasm = """OPENQASM 3.0;
|
|
1088
|
+
include "stdgates.inc";
|
|
1089
|
+
qubit q;
|
|
1090
|
+
bit b;
|
|
1091
|
+
|
|
1092
|
+
x q;
|
|
1093
|
+
|
|
1094
|
+
b = measure q;
|
|
1095
|
+
"""
|
|
1096
|
+
parser = QasmParser()
|
|
1097
|
+
|
|
1098
|
+
q0 = cirq.NamedQubit('q_0')
|
|
1099
|
+
|
|
1100
|
+
expected_circuit = Circuit([cirq.X.on(q0), cirq.measure(q0, key='b_0')])
|
|
1101
|
+
|
|
1102
|
+
parsed_qasm = parser.parse(qasm)
|
|
1103
|
+
|
|
1104
|
+
assert parsed_qasm.supportedFormat
|
|
1105
|
+
|
|
1106
|
+
ct.assert_same_circuits(parsed_qasm.circuit, expected_circuit)
|
|
1107
|
+
assert parsed_qasm.qregs == {'q': 1}
|
cirq/protocols/qasm.py
CHANGED
|
@@ -55,14 +55,23 @@ class QasmArgs(string.Formatter):
|
|
|
55
55
|
self.qubit_id_map = {} if qubit_id_map is None else qubit_id_map
|
|
56
56
|
self.meas_key_id_map = {} if meas_key_id_map is None else meas_key_id_map
|
|
57
57
|
|
|
58
|
+
def _format_number(self, value) -> str:
|
|
59
|
+
"""OpenQASM 2.0 does not support '1e-5' and wants '1.0e-5'"""
|
|
60
|
+
s = f'{value}'
|
|
61
|
+
if 'e' in s and not '.' in s:
|
|
62
|
+
return s.replace('e', '.0e')
|
|
63
|
+
return s
|
|
64
|
+
|
|
58
65
|
def format_field(self, value: Any, spec: str) -> str:
|
|
59
66
|
"""Method of string.Formatter that specifies the output of format()."""
|
|
60
67
|
if isinstance(value, (float, int)):
|
|
61
68
|
if isinstance(value, float):
|
|
62
69
|
value = round(value, self.precision)
|
|
63
70
|
if spec == 'half_turns':
|
|
64
|
-
value = f'pi*{value}' if value != 0 else '0'
|
|
71
|
+
value = f'pi*{self._format_number(value)}' if value != 0 else '0'
|
|
65
72
|
spec = ''
|
|
73
|
+
else:
|
|
74
|
+
value = self._format_number(value)
|
|
66
75
|
elif isinstance(value, ops.Qid):
|
|
67
76
|
value = self.qubit_id_map[value]
|
|
68
77
|
elif isinstance(value, str) and spec == 'meas':
|
cirq/protocols/qasm_test.py
CHANGED
|
@@ -52,3 +52,15 @@ def test_qasm():
|
|
|
52
52
|
|
|
53
53
|
assert cirq.qasm(ExpectsArgs(), args=cirq.QasmArgs()) == 'text'
|
|
54
54
|
assert cirq.qasm(ExpectsArgsQubits(), args=cirq.QasmArgs(), qubits=()) == 'text'
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_qasm_args_formatting():
|
|
58
|
+
args = cirq.QasmArgs()
|
|
59
|
+
assert args.format_field(0.01, '') == '0.01'
|
|
60
|
+
assert args.format_field(0.01, 'half_turns') == 'pi*0.01'
|
|
61
|
+
assert args.format_field(0.00001, '') == '1.0e-05'
|
|
62
|
+
assert args.format_field(0.00001, 'half_turns') == 'pi*1.0e-05'
|
|
63
|
+
assert args.format_field(1e-10, 'half_turns') == 'pi*1.0e-10'
|
|
64
|
+
args = cirq.QasmArgs(precision=6)
|
|
65
|
+
assert args.format_field(0.00001234, '') == '1.2e-05'
|
|
66
|
+
assert args.format_field(0.00001234, 'half_turns') == 'pi*1.2e-05'
|
{cirq_core-1.5.0.dev20241120163208.dist-info → cirq_core-1.5.0.dev20241120233534.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cirq-core
|
|
3
|
-
Version: 1.5.0.
|
|
3
|
+
Version: 1.5.0.dev20241120233534
|
|
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
|
{cirq_core-1.5.0.dev20241120163208.dist-info → cirq_core-1.5.0.dev20241120233534.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=Vpw7ogLDvHEtwUmt0PWS86YxwvfTBHzf2H5ozGsjGX4,1206
|
|
8
|
+
cirq/_version_test.py,sha256=98FHCYSWpiencHGZFgwAHsrlf12_WFY-XR69vsgHreI,147
|
|
9
9
|
cirq/conftest.py,sha256=X7yLFL8GLhg2CjPw0hp5e_dGASfvHx1-QT03aUbhKJw,1168
|
|
10
10
|
cirq/json_resolver_cache.py,sha256=ytePZtNZgKjOF2NiVpUTuotB-JKZmQNOFIFdvXqsxHw,13271
|
|
11
11
|
cirq/py.typed,sha256=VFSlmh_lNwnaXzwY-ZuW-C2Ws5PkuDoVgBdNCs0jXJE,63
|
|
@@ -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=
|
|
106
|
+
cirq/contrib/qasm_import/_lexer.py,sha256=1BGtCS2RetdiYPNOe_ZnMeoEl-AVBvvee_7y-h8tYcE,3275
|
|
107
107
|
cirq/contrib/qasm_import/_lexer_test.py,sha256=iiz-cmIt5hnhHBc4ub4btqHnbi4EPaO7BE7bsJKPet8,4142
|
|
108
|
-
cirq/contrib/qasm_import/_parser.py,sha256=
|
|
109
|
-
cirq/contrib/qasm_import/_parser_test.py,sha256=
|
|
108
|
+
cirq/contrib/qasm_import/_parser.py,sha256=e9ztG69dYm8dewM6efizbMT-Mf1n88hffg4ToBu0pig,20153
|
|
109
|
+
cirq/contrib/qasm_import/_parser_test.py,sha256=2XEfhoiHWDpnGh3yYrenekGTIYapDtf52AMzYulajRY,28374
|
|
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
|
|
@@ -419,8 +419,8 @@ cirq/protocols/phase_protocol.py,sha256=dXZRJb7aT8ZvtliItZOvoiaev-QvjBT4SknwZ5p-
|
|
|
419
419
|
cirq/protocols/phase_protocol_test.py,sha256=eU4g6VDqfWZCpklVlY1t5msc5kAZsP-UlPrROLll_ms,1939
|
|
420
420
|
cirq/protocols/pow_protocol.py,sha256=0wgb4LLAkOWjmP_u-_6IweXovDViocbdSgtsMOcXdkM,3290
|
|
421
421
|
cirq/protocols/pow_protocol_test.py,sha256=8eBcGUqRWSSYkEkvSHXL6tcv1o-ilnl6nzgNl9vfctg,1626
|
|
422
|
-
cirq/protocols/qasm.py,sha256=
|
|
423
|
-
cirq/protocols/qasm_test.py,sha256=
|
|
422
|
+
cirq/protocols/qasm.py,sha256=ekPlvfHIz9PUPdLeO7P_KMRuAh0rngM7r5grmW3kdWM,6869
|
|
423
|
+
cirq/protocols/qasm_test.py,sha256=MFkqSHByCbB46XOlAJgKQgEpANVwnmfO-tD-XofqrQ4,2013
|
|
424
424
|
cirq/protocols/qid_shape_protocol.py,sha256=jCAdpBBkEyK6JGmZwVBp__lHW3JhLmYt0Qzf8OgZtNU,7690
|
|
425
425
|
cirq/protocols/qid_shape_protocol_test.py,sha256=Qjo-wemjkP__1jQnVkkB91mUs8EpfXyKI9GzeZQVb1E,2303
|
|
426
426
|
cirq/protocols/resolve_parameters.py,sha256=NVFS5PSq18Hcvjv_P6vaZIa2D4OCgZY1u5j6QgPMlTA,7374
|
|
@@ -1187,8 +1187,8 @@ cirq/work/sampler.py,sha256=y6qtCpAwO8SqZ_JKU8PwlbMLHpJskNPqGWD_pNbyZew,19779
|
|
|
1187
1187
|
cirq/work/sampler_test.py,sha256=hL2UWx3dz2ukZVNxWftiKVvJcQoLplLZdQm-k1QcA40,13282
|
|
1188
1188
|
cirq/work/zeros_sampler.py,sha256=x1C7cup66a43n-3tm8QjhiqJa07qcJW10FxNp9jJ59Q,2356
|
|
1189
1189
|
cirq/work/zeros_sampler_test.py,sha256=JIkpBBFPJe5Ba4142vzogyWyboG1Q1ZAm0UVGgOoZn8,3279
|
|
1190
|
-
cirq_core-1.5.0.
|
|
1191
|
-
cirq_core-1.5.0.
|
|
1192
|
-
cirq_core-1.5.0.
|
|
1193
|
-
cirq_core-1.5.0.
|
|
1194
|
-
cirq_core-1.5.0.
|
|
1190
|
+
cirq_core-1.5.0.dev20241120233534.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
|
|
1191
|
+
cirq_core-1.5.0.dev20241120233534.dist-info/METADATA,sha256=1-jjDNKO-NFEVTOQY2DZbUf27V0_P5XX9JMubj1miv8,1992
|
|
1192
|
+
cirq_core-1.5.0.dev20241120233534.dist-info/WHEEL,sha256=bFJAMchF8aTQGUgMZzHJyDDMPTO3ToJ7x23SLJa1SVo,92
|
|
1193
|
+
cirq_core-1.5.0.dev20241120233534.dist-info/top_level.txt,sha256=Sz9iOxHU0IEMLSFGwiwOCaN2e9K-jFbBbtpPN1hB73g,5
|
|
1194
|
+
cirq_core-1.5.0.dev20241120233534.dist-info/RECORD,,
|
{cirq_core-1.5.0.dev20241120163208.dist-info → cirq_core-1.5.0.dev20241120233534.dist-info}/LICENSE
RENAMED
|
File without changes
|
{cirq_core-1.5.0.dev20241120163208.dist-info → cirq_core-1.5.0.dev20241120233534.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|