Skip to content

Commit 524714f

Browse files
committed
Full overhaul of OpenQASM3 handling.
1 parent f7036a2 commit 524714f

2 files changed

Lines changed: 313 additions & 500 deletions

File tree

docs/Developer/QASM_Parser.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# QASM Parsing
2+
3+
Before commit ID `6d4dbac`, the parsing was done by hand using `lex`/`yacc`. However, in order to easily update to newer grammar specifications to the exact letter prescribed by the OpenQASM3 standard, the ANTLR approach was adopted.
4+
5+
## Installing ANTLR toolkit on Ubuntu
6+
7+
Go to the [ANTLR4 website](https://www.antlr.org/download.html) and download the complete JAR (e.g. *antlr-4.13.2-complete.jar*) and move it to `/usr/local/lib` or alternatively run:
8+
9+
```bash
10+
cd /usr/local/lib
11+
sudo wget http://www.antlr.org/download/antlr-4.13.2-complete.jar
12+
```
13+
14+
Now run:
15+
16+
```bash
17+
cd /usr/local/bin
18+
sudo nano antlr4
19+
```
20+
21+
Fill it with:
22+
23+
```bash
24+
#! /bin/bash
25+
export CLASSPATH=".:/usr/local/lib/antlr-4.13.2-complete.jar:$CLASSPATH"
26+
java -jar /usr/local/lib/antlr-4.13.2-complete.jar "$@"
27+
```
28+
29+
and save the file. Finally, run:
30+
31+
```bash
32+
sudo chmod +x antlr4
33+
```
34+
35+
Running `antlr4` should work. ~~The installation script for SQDToolz additionally has `antlr4-python3-runtime`.~~ Okay given that openqasm3 is a package already in SQDToolz, this was adopted instead...
36+
37+
## Some notes on OpenQASM 3.0
38+
39+
Synchronisation is done via delay[0] on multiple qubits if required - i.e. [noting](https://openqasm.com/language/delays.html):
40+
41+
A multi-qubit delay instruction is not equivalent to multiple single-qubit delay instructions. Instead a multi-qubit delay acts as a synchronization point on the qubits, where the delay begins from the latest non-idle time across all qubits, and ends simultaneously across all qubits.
42+
43+
The `barrier` instruction is only there to prevent optimisation by commutation reordering and/or collapsing/simplification of gates across the barrier. Thus, the `barrier` instruction does not do anything in the current state of the compiler.

0 commit comments

Comments
 (0)