graphix-qasm-parser 0.1.0__py3-none-any.whl → 0.1.1__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.
- graphix_qasm_parser/_version.py +34 -0
- graphix_qasm_parser/parser.py +40 -5
- {graphix_qasm_parser-0.1.0.dist-info → graphix_qasm_parser-0.1.1.dist-info}/METADATA +2 -2
- graphix_qasm_parser-0.1.1.dist-info/RECORD +9 -0
- {graphix_qasm_parser-0.1.0.dist-info → graphix_qasm_parser-0.1.1.dist-info}/WHEEL +1 -1
- graphix_qasm_parser-0.1.0.dist-info/RECORD +0 -9
- {graphix_qasm_parser-0.1.0.dist-info → graphix_qasm_parser-0.1.1.dist-info}/licenses/LICENSE +0 -0
- {graphix_qasm_parser-0.1.0.dist-info → graphix_qasm_parser-0.1.1.dist-info}/top_level.txt +0 -0
graphix_qasm_parser/_version.py
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
"__version__",
|
|
6
|
+
"__version_tuple__",
|
|
7
|
+
"version",
|
|
8
|
+
"version_tuple",
|
|
9
|
+
"__commit_id__",
|
|
10
|
+
"commit_id",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
TYPE_CHECKING = False
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from typing import Tuple
|
|
16
|
+
from typing import Union
|
|
17
|
+
|
|
18
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
19
|
+
COMMIT_ID = Union[str, None]
|
|
20
|
+
else:
|
|
21
|
+
VERSION_TUPLE = object
|
|
22
|
+
COMMIT_ID = object
|
|
23
|
+
|
|
24
|
+
version: str
|
|
25
|
+
__version__: str
|
|
26
|
+
__version_tuple__: VERSION_TUPLE
|
|
27
|
+
version_tuple: VERSION_TUPLE
|
|
28
|
+
commit_id: COMMIT_ID
|
|
29
|
+
__commit_id__: COMMIT_ID
|
|
30
|
+
|
|
31
|
+
__version__ = version = '0.1.1'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 1, 1)
|
|
33
|
+
|
|
34
|
+
__commit_id__ = commit_id = 'gd19a6333f'
|
graphix_qasm_parser/parser.py
CHANGED
|
@@ -24,6 +24,37 @@ if TYPE_CHECKING:
|
|
|
24
24
|
|
|
25
25
|
from graphix.instruction import Instruction
|
|
26
26
|
|
|
27
|
+
# Compatibility with graphix <= 0.3.3
|
|
28
|
+
# See https://github.com/TeamGraphix/graphix/pull/379
|
|
29
|
+
|
|
30
|
+
ANGLE_PI: float
|
|
31
|
+
|
|
32
|
+
def rad_to_angle(angle: float) -> float:
|
|
33
|
+
"""Prototype for rad_to_angle."""
|
|
34
|
+
...
|
|
35
|
+
|
|
36
|
+
CZ = SWAP
|
|
37
|
+
else:
|
|
38
|
+
try:
|
|
39
|
+
from graphix.instruction import CZ
|
|
40
|
+
except ImportError:
|
|
41
|
+
|
|
42
|
+
def CZ(_q0: int, _q1: int) -> None: # noqa: N802
|
|
43
|
+
"""In older versions of graphix (<= 0.3.3), CZ instructions were not supported."""
|
|
44
|
+
msg = "CZ instructions are not supported by graphix <= 0.3.3"
|
|
45
|
+
raise NotImplementedError(msg)
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
from graphix.fundamentals import ANGLE_PI, rad_to_angle
|
|
49
|
+
except ImportError:
|
|
50
|
+
# Compatibility with graphix <= 0.3.3
|
|
51
|
+
# See https://github.com/TeamGraphix/graphix/pull/399
|
|
52
|
+
ANGLE_PI = math.pi
|
|
53
|
+
|
|
54
|
+
def rad_to_angle(angle: float) -> float:
|
|
55
|
+
"""In older versions of graphix (<= 0.3.3), instruction angles were expressed in radians."""
|
|
56
|
+
return angle
|
|
57
|
+
|
|
27
58
|
|
|
28
59
|
class OpenQASMParser:
|
|
29
60
|
"""Graphix OpenQASM parser."""
|
|
@@ -295,13 +326,16 @@ class _CircuitVisitor(qasm3ParserVisitor):
|
|
|
295
326
|
instruction = CCX(target=operands[2], controls=(operands[0], operands[1]))
|
|
296
327
|
elif gate == "crz":
|
|
297
328
|
# https://openqasm.com/language/standard_library.html#crz
|
|
298
|
-
instruction = RZZ(target=operands[1], control=operands[0], angle=exprs[0])
|
|
329
|
+
instruction = RZZ(target=operands[1], control=operands[0], angle=rad_to_angle(exprs[0]))
|
|
299
330
|
elif gate == "cx":
|
|
300
331
|
# https://openqasm.com/language/standard_library.html#cx
|
|
301
332
|
instruction = CNOT(target=operands[1], control=operands[0])
|
|
302
333
|
elif gate == "swap":
|
|
303
334
|
# https://openqasm.com/language/standard_library.html#swap
|
|
304
335
|
instruction = SWAP(targets=(operands[0], operands[1]))
|
|
336
|
+
elif gate == "cz":
|
|
337
|
+
# https://openqasm.com/language/standard_library.html#cz
|
|
338
|
+
instruction = CZ(targets=(operands[0], operands[1]))
|
|
305
339
|
elif gate == "h":
|
|
306
340
|
# https://openqasm.com/language/standard_library.html#h
|
|
307
341
|
instruction = H(target=operands[0])
|
|
@@ -322,13 +356,13 @@ class _CircuitVisitor(qasm3ParserVisitor):
|
|
|
322
356
|
instruction = I(target=operands[0])
|
|
323
357
|
elif gate == "rx":
|
|
324
358
|
# https://openqasm.com/language/standard_library.html#rx
|
|
325
|
-
instruction = RX(target=operands[0], angle=exprs[0])
|
|
359
|
+
instruction = RX(target=operands[0], angle=rad_to_angle(exprs[0]))
|
|
326
360
|
elif gate == "ry":
|
|
327
361
|
# https://openqasm.com/language/standard_library.html#ry
|
|
328
|
-
instruction = RY(target=operands[0], angle=exprs[0])
|
|
362
|
+
instruction = RY(target=operands[0], angle=rad_to_angle(exprs[0]))
|
|
329
363
|
elif gate == "rz":
|
|
330
364
|
# https://openqasm.com/language/standard_library.html#rz
|
|
331
|
-
instruction = RZ(target=operands[0], angle=exprs[0])
|
|
365
|
+
instruction = RZ(target=operands[0], angle=rad_to_angle(exprs[0]))
|
|
332
366
|
else:
|
|
333
367
|
msg = f"Unknown gate: {gate}"
|
|
334
368
|
raise NotImplementedError(msg)
|
|
@@ -440,7 +474,8 @@ class _ExpressionVisitor(qasm3ParserVisitor):
|
|
|
440
474
|
raise NotImplementedError(msg)
|
|
441
475
|
|
|
442
476
|
def parse_binary_operator(
|
|
443
|
-
self,
|
|
477
|
+
self,
|
|
478
|
+
ctx: qasm3Parser.AdditiveExpressionContext | qasm3Parser.MultiplicativeExpressionContext,
|
|
444
479
|
) -> _Value:
|
|
445
480
|
lhs_expr: qasm3Parser.ExpressionContext = ctx.getChild(0)
|
|
446
481
|
rhs_expr: qasm3Parser.ExpressionContext = ctx.getChild(2)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: graphix-qasm-parser
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Author-email: Thierry Martinez <Thierry.Martinez@inria.fr>
|
|
5
5
|
Maintainer-email: Thierry Martinez <Thierry.Martinez@inria.fr>
|
|
6
6
|
License-File: LICENSE
|
|
7
|
-
Requires-Dist: graphix>=0.3.
|
|
7
|
+
Requires-Dist: graphix>=0.3.3
|
|
8
8
|
Requires-Dist: openqasm-parser>=3.1.0
|
|
9
9
|
Provides-Extra: dev
|
|
10
10
|
Requires-Dist: mypy==1.17.0; extra == "dev"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
graphix_qasm_parser/__init__.py,sha256=aa1tbxV5srFCGRQxhYoMtsJhcsD2ZTmzj6qeK0lCrgI,112
|
|
2
|
+
graphix_qasm_parser/_version.py,sha256=2S8TB-CcygNrm4MElpID5xUS_Xf_v_nfiLayW3A1ILU,712
|
|
3
|
+
graphix_qasm_parser/parser.py,sha256=YZSSPBYo3jHkBlftE53ERa2Nh4FEcc-UTTVzVc1IxjI,17913
|
|
4
|
+
graphix_qasm_parser/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
graphix_qasm_parser-0.1.1.dist-info/licenses/LICENSE,sha256=zqDOTnYJUvwXI1pJ2ccCmJNFpCI1dmpPXbzNbHcq2xU,10761
|
|
6
|
+
graphix_qasm_parser-0.1.1.dist-info/METADATA,sha256=dPKaPyRLhlG9lBwyn0KUKWmSqf5oEix2tarJjkhkPR8,527
|
|
7
|
+
graphix_qasm_parser-0.1.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
8
|
+
graphix_qasm_parser-0.1.1.dist-info/top_level.txt,sha256=Cdfsi06mfpZXxFjQVaH61OAzRQFsL6aW-uthGW8LeDg,20
|
|
9
|
+
graphix_qasm_parser-0.1.1.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
graphix_qasm_parser/__init__.py,sha256=aa1tbxV5srFCGRQxhYoMtsJhcsD2ZTmzj6qeK0lCrgI,112
|
|
2
|
-
graphix_qasm_parser/_version.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
graphix_qasm_parser/parser.py,sha256=VyPoMht8zpics1pLVGR1yTP8-a_B-UfWMLHhi_CvmHw,16684
|
|
4
|
-
graphix_qasm_parser/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
graphix_qasm_parser-0.1.0.dist-info/licenses/LICENSE,sha256=zqDOTnYJUvwXI1pJ2ccCmJNFpCI1dmpPXbzNbHcq2xU,10761
|
|
6
|
-
graphix_qasm_parser-0.1.0.dist-info/METADATA,sha256=1X0rDiK1WW0XvglxLgri-eR998kOYzAWLTUtJVtPx_g,527
|
|
7
|
-
graphix_qasm_parser-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
-
graphix_qasm_parser-0.1.0.dist-info/top_level.txt,sha256=Cdfsi06mfpZXxFjQVaH61OAzRQFsL6aW-uthGW8LeDg,20
|
|
9
|
-
graphix_qasm_parser-0.1.0.dist-info/RECORD,,
|
{graphix_qasm_parser-0.1.0.dist-info → graphix_qasm_parser-0.1.1.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|