Skip to content

khoa-ho/qcompiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QCompiler

Author

Khoa Ho [[email protected]], Jeung Rac Lee [[email protected]]

Overview

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

Usage

Requirements:

OCaml (>= 4.02.3) [https://ocaml.org/docs/install.html]

Build

Following are useful Makefile commands

make (make all): build the project make clean: clean the binaries

Execute

First, build the project

$ make

Then run the compiler,

$ ./compiler.native [source_file_path]

Supporting Open QASM statements

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

Examples

Sample quantunm algorithms

Deutsch–Jozsa algorithm in QASM,

from https://github.com/QISKit/openqasm/blob/master/examples/ibmqx2/Deutsch_Algorithm.qasm

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];
Grover's Algorithm in QASM,

from https://github.com/sampaio96/Quantum-Computing/blob/master/Grover's%20Algorithm/Grover_N_2_A_00.qasm

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];

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published