-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
experimental.py
70 lines (55 loc) · 1.95 KB
/
experimental.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# This code is part of Qiskit.
#
# (C) Copyright IBM 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
"""Experimental feature flags."""
import enum
# This enumeration is shared between a bunch of parts of the exporter, so it gets its own file to
# avoid cyclic dependencies.
class ExperimentalFeatures(enum.Flag):
"""Flags for experimental features that the OpenQASM 3 exporter supports.
These are experimental and are more liable to change, because the OpenQASM 3
specification has not formally accepted them yet, so the syntax may not be finalized."""
SWITCH_CASE_V1 = enum.auto()
"""Support exporting switch-case statements as proposed by
https://github.com/openqasm/openqasm/pull/463 at `commit bfa787aa3078
<https://github.com/openqasm/openqasm/pull/463/commits/bfa787aa3078>`__.
These have the output format:
.. code-block::
switch (i) {
case 0:
case 1:
x $0;
break;
case 2: {
z $0;
}
break;
default: {
cx $0, $1;
}
break;
}
This differs from the syntax of the ``switch`` statement as stabilized. If this flag is not
passed, then the parser will instead output using the stabilized syntax, which would render the
same example above as:
.. code-block::
switch (i) {
case 0, 1 {
x $0;
}
case 2 {
z $0;
}
default {
cx $0, $1;
}
}
"""