Skip to content

Commit 62d4bdb

Browse files
authored
Initial commit (#1)
* Initial commit * Added submodule checkout to CI/CD * Fixed submodule directory * Make OpenPulse parser only parse the OpenQASM body * Improved the handling of return statement and added more tests * Updated comments * Formatting * Removed the code checked in accidentally
1 parent 367e577 commit 62d4bdb

20 files changed

Lines changed: 1388 additions & 0 deletions

.github/workflows/tests-ast.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Reference Python Package
2+
3+
on:
4+
[push, pull_request]
5+
6+
jobs:
7+
tests:
8+
name: OpenPulse AST tests
9+
runs-on: ubuntu-latest
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
python-version: ['3.7', '3.8', '3.9', '3.10']
14+
antlr-version: ['4.9.2']
15+
defaults:
16+
run:
17+
working-directory: source/openpulse
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
with:
22+
submodules: recursive
23+
24+
- uses: actions/setup-python@v2
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
28+
- uses: actions/setup-java@v2
29+
with:
30+
java-version: '15'
31+
distribution: 'adopt'
32+
33+
- name: Update pip
34+
run: python -mpip install --upgrade pip
35+
36+
- name: Install ANTLR4
37+
working-directory: .
38+
run: curl -O https://www.antlr.org/download/antlr-${{ matrix.antlr-version }}-complete.jar
39+
40+
- name: Install ANTLR4 Python runtime
41+
run: python -mpip install antlr4-python3-runtime==${{ matrix.antlr-version }}
42+
43+
- name: Generate openqasm3 grammar
44+
working-directory: openqasm/source/grammar
45+
run: java -Xmx500M -jar ../../../antlr-${{ matrix.antlr-version }}-complete.jar -o ../openqasm/openqasm3/antlr -Dlanguage=Python3 -visitor qasm3Lexer.g4 qasm3Parser.g4
46+
47+
- name: Install Python dependencies
48+
working-directory: openqasm/source/openqasm
49+
run: python -mpip install -r requirements.txt -r requirements-dev.txt
50+
51+
- name: Build openqasm3 package
52+
working-directory: openqasm/source/openqasm
53+
run: python -mpip install -e .[all]
54+
55+
- name: Generate openpulse grammar
56+
working-directory: source/grammar
57+
run: java -Xmx500M -jar ../../antlr-${{ matrix.antlr-version }}-complete.jar -lib ../../openqasm/source/grammar -o ../openpulse/openpulse/antlr -Dlanguage=Python3 -visitor openpulseLexer.g4 openpulseParser.g4
58+
59+
- name: Check openpulse format
60+
run: black --check --diff openpulse tests
61+
62+
- name: Check openpulse style
63+
working-directory: source/openpulse/openpulse
64+
run: pylint .
65+
66+
- name: Check openpulse tests style
67+
working-directory: source/openpulse/tests
68+
run: pylint .
69+
70+
- name: Run openpulse tests
71+
run: pytest -vv --color=yes tests

.gitignore

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
# Build output
2+
build
3+
4+
## Core latex/pdflatex auxiliary files:
5+
*.aux
6+
*.lof
7+
*.log
8+
*.lot
9+
*.fls
10+
*.out
11+
*.toc
12+
*.fmt
13+
*.fot
14+
*.cb
15+
*.cb2
16+
17+
## Intermediate documents:
18+
*.dvi
19+
*-converted-to.*
20+
# these rules might exclude image files for figures etc.
21+
# *.ps
22+
# *.eps
23+
# *.pdf
24+
25+
## Bibliography auxiliary files (bibtex/biblatex/biber):
26+
*.bbl
27+
*.bcf
28+
*.blg
29+
*-blx.aux
30+
*-blx.bib
31+
*.brf
32+
*.run.xml
33+
34+
## Build tool auxiliary files:
35+
*.fdb_latexmk
36+
*.synctex
37+
*.synctex.gz
38+
*.synctex.gz(busy)
39+
*.pdfsync
40+
41+
## Auxiliary and intermediate files from other packages:
42+
# algorithms
43+
*.alg
44+
*.loa
45+
46+
# achemso
47+
acs-*.bib
48+
49+
# amsthm
50+
*.thm
51+
52+
# beamer
53+
*.nav
54+
*.snm
55+
*.vrb
56+
57+
# cprotect
58+
*.cpt
59+
60+
# fixme
61+
*.lox
62+
63+
#(r)(e)ledmac/(r)(e)ledpar
64+
*.end
65+
*.?end
66+
*.[1-9]
67+
*.[1-9][0-9]
68+
*.[1-9][0-9][0-9]
69+
*.[1-9]R
70+
*.[1-9][0-9]R
71+
*.[1-9][0-9][0-9]R
72+
*.eledsec[1-9]
73+
*.eledsec[1-9]R
74+
*.eledsec[1-9][0-9]
75+
*.eledsec[1-9][0-9]R
76+
*.eledsec[1-9][0-9][0-9]
77+
*.eledsec[1-9][0-9][0-9]R
78+
79+
# glossaries
80+
*.acn
81+
*.acr
82+
*.glg
83+
*.glo
84+
*.gls
85+
*.glsdefs
86+
87+
# gnuplottex
88+
*-gnuplottex-*
89+
90+
# hyperref
91+
*.brf
92+
93+
# knitr
94+
*-concordance.tex
95+
# TODO Comment the next line if you want to keep your tikz graphics files
96+
*.tikz
97+
*-tikzDictionary
98+
99+
# listings
100+
*.lol
101+
102+
# makeidx
103+
*.idx
104+
*.ilg
105+
*.ind
106+
*.ist
107+
108+
# minitoc
109+
*.maf
110+
*.mlf
111+
*.mlt
112+
*.mtc
113+
*.mtc[0-9]
114+
*.mtc[1-9][0-9]
115+
116+
# minted
117+
_minted*
118+
*.pyg
119+
120+
# morewrites
121+
*.mw
122+
123+
# mylatexformat
124+
*.fmt
125+
126+
# nomencl
127+
*.nlo
128+
129+
# sagetex
130+
*.sagetex.sage
131+
*.sagetex.py
132+
*.sagetex.scmd
133+
134+
# sympy
135+
*.sout
136+
*.sympy
137+
sympy-plots-for-*.tex/
138+
139+
# pdfcomment
140+
*.upa
141+
*.upb
142+
143+
# pythontex
144+
*.pytxcode
145+
pythontex-files-*/
146+
147+
# thmtools
148+
*.loe
149+
150+
# TikZ & PGF
151+
*.dpth
152+
*.md5
153+
*.auxlock
154+
155+
# todonotes
156+
*.tdo
157+
158+
# xindy
159+
*.xdy
160+
161+
# xypic precompiled matrices
162+
*.xyc
163+
164+
# endfloat
165+
*.ttt
166+
*.fff
167+
168+
# Latexian
169+
TSWLatexianTemp*
170+
171+
## Editors:
172+
# WinEdt
173+
*.bak
174+
*.sav
175+
176+
# Texpad
177+
.texpadtmp
178+
179+
# Kile
180+
*.backup
181+
182+
# KBibTeX
183+
*~[0-9]*
184+
185+
# VSCode
186+
.vscode
187+
188+
# Pycharm
189+
.idea
190+
191+
# Python
192+
.venv
193+
__pycache__
194+
*.py[cod]
195+
*$py.class
196+
pip-log.txt
197+
pip-delete-this-directory.txt
198+
*.egg-info
199+
200+
# OS specific
201+
.DS_Store
202+
203+
source/_build
204+
205+
# Antlr
206+
*.java
207+
*.tokens
208+

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "openqasm"]
2+
path = openqasm
3+
url = https://github.com/openqasm/openqasm.git

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# OpenPulse Python Parser Reference Implementation
2+
3+
This project is a reference implementation of [OpenPulse](https://openqasm.com/language/openpulse.html).
4+
Specifically, the parser passes the body of `cal` and `defcal` written in `OpenPulse`.
5+
It reuses the classical types and statements from `openqasm3`.
6+
## Developing openpulse
7+
8+
### Working with submodule
9+
10+
The `openpulse` package depends on the `openqasm3` package. This repo references the
11+
[OpenQASM](https://github.com/openqasm/openqasm) repo as submodule.
12+
13+
To clone `openpulse`, run:
14+
15+
```
16+
git clone --recurse-submodules https://github.com/openqasm/openpulse-python.git
17+
```
18+
19+
If you forgot `--recurse-submodules` during initial cloning, you can run:
20+
21+
```
22+
git submodule update --init --recursive
23+
```
24+
25+
### Build and install openqasm3
26+
27+
We assume that you have already installed `Antlr4` tools following `openqasm/source/openqasm/README.md`
28+
and set up an Python virtual environment for this project.
29+
30+
You will need to build and install `openqasm3` first. Change to the `openqasm/source/grammar`
31+
directory and run:
32+
33+
```
34+
antlr4 -o ../openqasm/openqasm3/antlr -Dlanguage=Python3 -visitor qasm3Lexer.g4 qasm3Parser.g4
35+
```
36+
37+
Then change to the `openqasm/source/openqasm` directory and run:
38+
39+
```
40+
python -mpip install -r requirements.txt -r requirements-dev.txt
41+
python -mpip install -e ".[all]"
42+
```
43+
44+
### Working with openpulse
45+
46+
Now build the `openpulse` grammar. Change to the `source/grammar` directory and run:
47+
48+
```
49+
antlr4 -lib ../../openqasm/source/grammar -o ../openpulse/openpulse/antlr -Dlanguage=Python3 -visitor openpulseLexer.g4 openpulseParser.g4
50+
```
51+
52+
Finally, you can change to the `source/openpulse` directory and run:
53+
54+
```
55+
pytest .
56+
```

openqasm

Submodule openqasm added at fbcf587

source/grammar/openpulseLexer.g4

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
lexer grammar openpulseLexer;
2+
import qasm3Lexer;
3+
4+
WAVEFORM: 'waveform';
5+
PORT: 'port';
6+
FRAME: 'frame';
7+
8+
// Turn off mode switching for now and use statement* to match the body
9+
CAL: 'cal';
10+
DEFCAL: 'defcal';

0 commit comments

Comments
 (0)