Skip to content

Commit

Permalink
Basic parser testing
Browse files Browse the repository at this point in the history
  • Loading branch information
gribeill committed Dec 15, 2020
1 parent a1bba50 commit 9b193ae
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_QASM.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Test QASM parsing and (eventually) compilation
import os
import unittest

from QGL.qasm.parse import QASM3Parser

def get_qasm_test_file(filename):
path = os.path.dirname(os.path.abspath(__file__))
file = os.path.join(path, "test_data", "qasm", filename)
with open(file, "r") as f:
qasm = f.read()
return qasm

class ParseTestCase(unittest.TestCase):

def setUp(self):
pass

def test_parse_simple(self):
qasm = get_qasm_test_file("basic.qasm")
parser = QASM3Parser()
parser.build_tree(qasm)

if __name__ == "__main__":
unittest.main()
21 changes: 21 additions & 0 deletions tests/test_data/qasm/basic.qasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
OPENQASM 3.0;
#PRAGMA I <3 QGL

qubit q1;
length t;

//A very special gate
gate X(angle[32]: phi) q {
U(phi, -pi/2, -pi/2) q;
}

/* Let's do a ramsey experiment!
Fun! */

for t in 4ns:10us:20ns {
reset q1;
X(pi/2) q1;
delay[t] q1;
X(pi/2) q1;
measure q1;
}

0 comments on commit 9b193ae

Please sign in to comment.