Modeling a Quantum ComputerMostafa Elhoushi – MSc Student
Supervised by:
M. Watheq El-Kharashi
Hatem Elrefaei
Computer and Systems Engineering Department
Faculty of EngineeringAin Shams University
Cairo, December 2011
Contents● Introduction● Quantum Processing Module● Hybrid Quantum Computer● C/C++ Example● Conclusion and Future Work
Modeling a Quantum Computer of 43
INTRODUCTION
Modeling a Quantum Computer of 43
Quantum Computation● Quantum computation takes
advantage of quantum mechanics features:● Superposition● Entanglement
● More efficient than classical algorithms in solving some problems
● Examples: ● Grover’s search algorithm, Shor’s
factorization algorithm, Deutsch-Josza algorithm, ... Modeling a Quantum Computer of 43
Problem Definition● Need a single framework of:
● Quantum processor● Integrated with a classical processor
● Quantum assembly language and its assembler● Integrate with a classical high-level language
(C/C++)● General-purpose simulator of quantum
circuits and algorithms
Modeling a Quantum Computer of 43
Comparisons with Related Work
HDL Modeling
M. Udrescu et al.: VHDL simulation of specific circuits
A.U. Khalid et al.: FPGA synthesis of specific circuits
Programming
Languages
B. Ömer: QCLP. Selinger: QPLH. Mlnařík: LanQ
S. Bettelli et al.: Q Language
Our Work:● Hybrid quantum processor● VHDL simulation of general-
purpose circuit ● Define QASM instruction set
M. Oskin et al.: architecture of quantum computer
E.H. Knill: QRAM Model
Computer
Architecture
Modeling a Quantum Computer of 43
Contribution● Quantum processing module
● Modeled using VHDL● Executes Quantum Assembly (QASM)
language● MIPS-Q Processor
● Quantum processing module integrated into classical MIPS processor
● Executes classical MIPS assembly instructions + QASM instructions
● Execute C/C++ programs with quantum instructions
Modeling a Quantum Computer of 43
QRAM Model● Quantum Random Access Machine● Classical control and quantum data
● Instructions in the form:● “Apply operation X to qubit n”● “Measure qubit m”
Modeling a Quantum Computer of 43
MIPS-R2000: Classical CPU
Modeling a Quantum Computer of 43
MIPS-Q: Hybrid Quantum CPU
Modeling a Quantum Computer of 43
QUANTUM PROCESSING MODULE
Modeling a Quantum Computer of 43
Quantum Processing Module
● Quantum ALU (qALU)● to perform
operations● Q
● quantum register (holding N qubits)
● C● classical
measurement register (holding N bits)
● Instruction register Modeling a Quantum Computer of 43
QASM Instruction FormatType 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
Q qopcode parameter qaddress1 qaddress2 not used not used
R opcode Rs Rt Rd shamt funct
I opcode Rs Rt Immediate
J opcode address
● qopcode: quantum operation (quantum gate, quantum measurement or qubit initialization)
● parameter: used by some quantum operations
● qaddress1: number of first qubit to apply on
● qaddress2: number of second qubit to apply on
Modeling a Quantum Computer of 43
Quantum ALU
Modeling a Quantum Computer of 43
qALU Gate Set
Modeling a Quantum Computer of 43
QASM Instruction SetInstruction Measning
q param, num If param=0 then set all qubits to |0>. If param=1 set qubit num to |1>.
X num Apply X gate to qubit num.Z num Apply Z gate to qubit num.Y num Apply Y gate to qubit num.H num Apply H gate to qubit num.Rk param, num If param>=0 then apply Rk gate with k=param to qubit
num.If param<0 then apply Rk† gate with k=|param| to qubit num.
CNOT num1, num2 Apply CNOT gate to qubit num1 controlled by qubit num2.
Modeling a Quantum Computer of 43
Quantum Assembly (QASM) Instruction Set (cont.)
Instruction Measning
CRk param, num1, num2 If param>=0 then apply CRk gate with k=param to qubit num1 controlled by qubit num2.If param<0 then apply CRk† gate with k=|param| to qubit num1 controlled by qubit num2.
MEASURE num Measure qubit num and set numth bit of the classical register, C, to the measured value.
Modeling a Quantum Computer of 43
Testing Quantum Processing Module
● Perl script to translate QASM program to HEX file● VHDL testbench to load HEX file into instruction memory
and execute it.● Some algorithms consist of just quantum operations
without any classical operations● Examples: EPR Creation Circuit - Toffoli Gate Circuit -
Quantum Fourier Transform Circuit Modeling a Quantum Computer of 43
Example: EPR Creation Circuit● used to set qubits into an entangled
state
q 0,0
H 0
CNOT 1,0
MEASURE 0
MEASURE 1
Output 00 01 10 11
Quantum Register, Q 0.707 0 0 0.707
Probability of Measurement 50% 0% 0% 50%
Result after 100 trials 48 0 0 52
Modeling a Quantum Computer of 43
Example: Toffoli Gate Circuit● controlled-NAND gate
● Quantum computation has a universal gate set: Rk, CRk, CNOT, h
● Toffoli gate implemented using our gate set
Modeling a Quantum Computer of 43
Example: Toffoli Gate Circuit (cont.)
q 1,0
q 1,1
CRk 1,2,1
H 2
Rk-3,2
CNOT 2,0
Rk3,2
CNOT 2,1
Rk-3,2
CNOT 2,0
Rk3,2
H 2
CRk 2,1,0
Modeling a Quantum Computer of 43
Example: 4-bit Quantum Fourier Transform
q 0,0
H 0
Rk2,0,1
Rk3,0,2
Rk4,0,3
H 1
Rk2,1,2
Rk3,1,3
H 2
Rk2,2,3
H 3
Modeling a Quantum Computer of 43
Example: 4-bit Quantum Fourier Transform (cont.)Input Output
|0000> 0.25 (|0000> + … + |1111>)
[1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 0.25*[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
Input Output
0.25 (|0000> + … + |1111>) |0000>
0.25*[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1] [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
Modeling a Quantum Computer of 43
HYBRID QUANTUM COMPUTER
Modeling a Quantum Computer of 43
Compilation Flow
Modeling a Quantum Computer of 43
Execution Flow
Modeling a Quantum Computer of 43
Additional Instructions to MIPS Instruction Set● Add QASM instructions:
● Immediate form (already mentioned before)
● Register form● Used when qubit number is a variable or
parameter
● Load quantum measurement register● Only data can be read from quantum
processing module is the measurement values
Modeling a Quantum Computer of 43
Additional Instructions to MIPS Instruction Set (cont.)
QASM Immediate Form QASM Register Form
q param, num qr $a, $b
X num Xr $a
Z num Zr $a
Y num Yr $a
H num Hr $a
Rk param, num Rkr $a, $b
CNOT num1, num2 CNOTr $a, $b
CRk param, num1, num2 CRkr $a, $b, $c
MEASURE num MEASUREr $a
Load Quantum Measurement Register
lqmeas $t
Modeling a Quantum Computer of 43
C/C++ MacrosMacro
#define QUBIT(param, num) asm("q " #param", " #num);
#define X(q) asm("X " #q);
#define Z(q) asm("Z " #q);
#define Y(q) asm("Y " #q);
#define H(q) asm("H " #q);
#define Rk(param,q) asm("Rk " #param ", " #q);
#define CNOT(q1,q2) asm("CNOT " #q1 ", " #q2);
#define CRk(param,q1,q2) asm("CRk " #param ", " #q1 ", " #q2);
#define MEASURE(q) asm("MEASURE " #q);
#define GETQMEASURE(a) asm("lqmeas %0" : "=r" (a) :);
Modeling a Quantum Computer of 43
C/C++ FunctionsFunctions
void qubit(int param, int num){ asm(“qr %0, %1” :: “r” (param), “r” (num);}
void X(int q){ asm(“Xr %0” :: “r” (q);}
void Z(int q){ asm(“Zr %0” :: “r” (q);}
void Y(int q){ asm(“Yr %0” :: “r” (q);}
void H(int q){ asm(“Hr %0” :: “r” (q);}
void Rk(int param, int q){ asm(“Rkr %0, %1” :: “r” (param), “r” (q);}
void CNOT(int q1, int q2){ asm(“CNOTr %0, %1” :: “r” (q1), “r” (q2);}
Modeling a Quantum Computer of 43
C/C++ Functions (cont.)Functions
void CRk(int param, int q1, int q2){ asm(“CRkr %0, %1, %2” :: “r” (param), “r” (q1), “r” (q2);}
int Measure(int q){asm(“MEASUREr %0” :: “r” (q); int reg;asm("lqmeas %0" : "=r" (reg) :);return (reg & (1 << q)); }
Modeling a Quantum Computer of 43
C/C++ Classclass Qubit{public:Qubit(int p_intValue = 0) { number = count++; asm(“qr %0, %1” :: “r” (p_intValue ), “r” (number);}
void X() { asm(“Xr %0” :: “r” (number);}
void Z() { asm(“Zr %0” :: “r” (number);}
void Y() { asm(“Yr %0” :: “r” (number);}
void H() { asm(“Hr %0” :: “r” (number);}
...
Modeling a Quantum Computer of 43
C/C++ Class (cont.)void Rk(int param){ asm(“Rkr %0, %1” :: “r” (param), “r” (number);}
void CNOT(Qubit q2) { asm(“CNOTr %0, %1” :: “r” (number), “r” (q2.GetNumber());}
void CRk(int param, Qubit q2) { asm(“CRkr %0, %1, %2” :: “r” (param), “r” (number), “r” (q2.GetNumber());}
int GetNumber() {return number;}
int Measure() {asm(“MEASUREr %0” :: “r” (number); int reg; asm("lqmeas %0" : "=r" (reg) :);return (reg & (1 << number)); }
protected: int number; static int count;}; Modeling a Quantum Computer of 43
C/C++ EXAMPLE
Modeling a Quantum Computer of 43
Example: Quantum Teleportation Circuit
● Using Macrosint main(){int a;QUBIT(1,0);H(1); CNOT(2,1); CNOT(1,0); H(0);MEASURE(0); MEASURE(1);GETQMEASURE(a);if(a & (1 << 1)) X(2);if(a & (1 << 0)) Z(2);} Modeling a Quantum Computer of 43
Example: Quantum Teleportation Circuit (cont.)
● Using Functionsint QTeleportation(int q0, int q1, int q2)
{
H(q1); CNOT(q2,q1); CNOT(q1,q0); H(q0);
Measure(q0); Measure(q1);
if(Measure(q0)) X(q2);
if(Measure(q1)) Z(q2);
}
Modeling a Quantum Computer of 43
Example: Quantum Teleportation Circuit (cont.)
● Using Classesint main()
{
Qubit q0(1), q1(0), q2(0);
q1.H(); q2.CNOT(q1); q1.CNOT(q0); q0.H();
if(q1.Measure()) q2.X();
if(q0.Measure()) q2.Z();
}
Modeling a Quantum Computer of 43
CONCLUSION AND FUTURE WORK
Modeling a Quantum Computer of 43
Conclusion● We have provided a single framework
for:● Describing quantum algorithms in a low-
level language● Integrating quantum operations within a
classical high-level language (C++)● Single processor model to simulate
algorithm execution● Framework independent of physical
implementation Modeling a Quantum Computer of 43
Future Work● Provide compilers to translate different
imperative and functional languages into QASM programs
● Provide libraries to translate arbitrary gates into primitive quantum gates
● FPGA Synthesis for faster simulation● Use more efficient simulation
techniques, ● e.g. probabilistic methods
Modeling a Quantum Computer of 43
Publications1. Elhoushi, Mostafa; El-Kharashi, M. Watheq;
Elrefaei, Hatem, “Modeling a quantum processor using the QRAM model,” Communications, Computers and Signal Processing (PacRim), 2011 IEEE Pacific Rim Conference on , vol., no., pp.409-415, 23-26 Aug. 2011
Modeling a Quantum Computer of 43
QUESTIONS?
Modeling a Quantum Computer of 43
THANK YOU!
Modeling a Quantum Computer of 43