|
12 | 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | 13 | # See the License for the specific language governing permissions and
|
14 | 14 | # limitations under the License.
|
15 |
| -""" Backend to convert ProjectQ commands to OpenQASM. """ |
| 15 | +"""Backend to convert ProjectQ commands to OpenQASM.""" |
16 | 16 |
|
17 | 17 | from copy import deepcopy
|
18 | 18 |
|
19 | 19 | from projectq.cengines import BasicEngine
|
20 | 20 | from projectq.meta import get_control_count, has_negative_control
|
21 | 21 | from projectq.ops import (
|
22 |
| - X, |
23 | 22 | NOT,
|
24 |
| - Y, |
25 |
| - Z, |
26 |
| - T, |
27 |
| - Tdag, |
28 |
| - S, |
29 |
| - Sdag, |
| 23 | + Allocate, |
| 24 | + Barrier, |
| 25 | + Deallocate, |
| 26 | + FlushGate, |
30 | 27 | H,
|
| 28 | + Measure, |
31 | 29 | Ph,
|
32 | 30 | R,
|
33 | 31 | Rx,
|
34 | 32 | Ry,
|
35 | 33 | Rz,
|
| 34 | + S, |
| 35 | + Sdag, |
36 | 36 | Swap,
|
37 |
| - Measure, |
38 |
| - Allocate, |
39 |
| - Deallocate, |
40 |
| - Barrier, |
41 |
| - FlushGate, |
| 37 | + T, |
| 38 | + Tdag, |
| 39 | + X, |
| 40 | + Y, |
| 41 | + Z, |
42 | 42 | )
|
43 | 43 |
|
44 |
| - |
45 | 44 | # ==============================================================================
|
46 | 45 |
|
47 | 46 |
|
48 | 47 | class OpenQASMBackend(BasicEngine): # pylint: disable=too-many-instance-attributes
|
49 |
| - """ |
50 |
| - Engine to convert ProjectQ commands to OpenQASM format (either string or file) |
51 |
| - """ |
| 48 | + """Engine to convert ProjectQ commands to OpenQASM format (either string or file).""" |
52 | 49 |
|
53 | 50 | def __init__(
|
54 | 51 | self,
|
@@ -87,18 +84,16 @@ def __init__(
|
87 | 84 | self._qubit_id_mapping_redux = qubit_id_mapping_redux
|
88 | 85 |
|
89 | 86 | self._output = []
|
90 |
| - self._qreg_dict = dict() |
91 |
| - self._creg_dict = dict() |
| 87 | + self._qreg_dict = {} |
| 88 | + self._creg_dict = {} |
92 | 89 | self._reg_index = 0
|
93 | 90 | self._available_indices = []
|
94 | 91 |
|
95 | 92 | self._insert_openqasm_header()
|
96 | 93 |
|
97 | 94 | @property
|
98 | 95 | def qasm(self):
|
99 |
| - """ |
100 |
| - Access to the QASM representation of the circuit. |
101 |
| - """ |
| 96 | + """Access to the QASM representation of the circuit.""" |
102 | 97 | return self._output
|
103 | 98 |
|
104 | 99 | def is_available(self, cmd):
|
@@ -146,8 +141,7 @@ def is_available(self, cmd):
|
146 | 141 |
|
147 | 142 | def receive(self, command_list):
|
148 | 143 | """
|
149 |
| - Receives a command list and, for each command, stores it until |
150 |
| - completion. |
| 144 | + Receives a command list and, for each command, stores it until completion. |
151 | 145 |
|
152 | 146 | Args:
|
153 | 147 | command_list: List of commands to execute
|
@@ -309,9 +303,7 @@ def _insert_openqasm_header(self):
|
309 | 303 | self._output.append('include "stdgates.inc";')
|
310 | 304 |
|
311 | 305 | def _reset_after_flush(self):
|
312 |
| - """ |
313 |
| - Reset the internal quantum circuit after a FlushGate |
314 |
| - """ |
| 306 | + """Reset the internal quantum circuit after a FlushGate.""" |
315 | 307 | if not self._collate_callback:
|
316 | 308 | self._output.append('# ' + '=' * 80)
|
317 | 309 | else:
|
|
0 commit comments