Khoa Ho [[email protected]], Jeung Rac Lee [[email protected]]
A compiler translating a mock-up quantum programming language into a quantum assembly language, QASM. Our mock-up language is very similar to QASM, but we introduce a functional approach to gate application.
Refer to this paper for more details about QASM: https://arxiv.org/pdf/1707.03429.pdf
OCaml (>= 4.02.3) [https://ocaml.org/docs/install.html]
Following are useful Makefile commands
make (make all)
: build the project
make clean
: clean the binaries
First, build the project
$ make
Then run the compiler,
$ ./compiler.native [source_file_path]
Statement | Description |
---|---|
OPENQASM 2.0; | Denotes a file in Open QASM format |
qreg name[size]; | Declare a named register of qubits |
creg name[size]; | Declare a named register of bits |
include "filename"; | Open and parse another source file |
gate name qargs { body } | Declare a unitary gate |
CX qubit|qreg,qubit|qreg; | Apply built-in CNOT gate(s) |
measure qubit|qreg -> bit|creg; | Make measurement(s) in Z basis |
if(creg==int) qop; | Conditionally apply quantum operation |
barrier qargs; | Prevent transformations across this source line |
OPENQASM 2.0;
include "qelib1.inc";
qreg q[5];
creg c[5];
x q[4];
h q[3];
h q[4];
cx q[3],q[4];
h q[3];
measure q[3] -> c[3];
In our language, the program can be written as
include "qelib1.inc";
qreg q[5];
creg c[5];
q[4] > x > h;
q[3] > h;
cx q[3],q[4];
q[3] > h;
measure q[3] -> c[3];
And it will be compiled as
OPENQASM 2.0;
include "qelib1.inc";
qreg q[5];
creg c[5];
x q[4];
h q[3];
h q[4];
cx q[3],q[4];
h q[3];
measure q[3] -> c[3];
OPENQASM 2.0;
include "qelib1.inc";
qreg q[5];
creg c[5];
h q[1];
h q[2];
s q[1];
s q[2];
h q[2];
cx q[1],q[2];
h q[2];
s q[1];
s q[2];
h q[1];
h q[2];
x q[1];
x q[2];
h q[2];
cx q[1],q[2];
h q[2];
x q[1];
x q[2];
h q[1];
h q[2];
measure q[1] -> c[1];
measure q[2] -> c[2];
In our language, the program can be written as
include "qelib1.inc";
qreg q[5];
creg c[5];
q[1] > h > s;
q[2] > h > s > h;
cx q[1],q[2];
q[2] > h > s > h > x > h;
q[1] > s > h > x;
cx q[1],q[2];
q[2] > h > x > h;
q[1] > x > h;
measure q[1] -> c[1];
measure q[2] -> c[2];
And it will be compiled as
OPENQASM 2.0;
include "qelib1.inc";
qreg q[5];
creg c[5];
h q[1];
h q[2];
s q[1];
s q[2];
h q[2];
cx q[1],q[2];
h q[2];
s q[1];
s q[2];
h q[1];
h q[2];
x q[1];
x q[2];
h q[2];
cx q[1],q[2];
h q[2];
x q[1];
x q[2];
h q[1];
h q[2];
measure q[1] -> c[1];
measure q[2] -> c[2];