0% found this document useful (0 votes)
131 views

An Introduction To The Quantum Simulator QCL: Rafael Trapani Possignolo

This document provides an introduction to the Quantum Simulator QCL. It discusses installing QCL, provides examples of basic usage including entanglement and measurement, and describes different programming structures in QCL like procedures, operators, and functions. The document contains information on running example programs, limitations of the simulator, and analyzing example code to understand the different program types in QCL. It aims to help users get started with QCL through hands-on examples and explanations of key concepts.

Uploaded by

ivi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views

An Introduction To The Quantum Simulator QCL: Rafael Trapani Possignolo

This document provides an introduction to the Quantum Simulator QCL. It discusses installing QCL, provides examples of basic usage including entanglement and measurement, and describes different programming structures in QCL like procedures, operators, and functions. The document contains information on running example programs, limitations of the simulator, and analyzing example code to understand the different program types in QCL. It aims to help users get started with QCL through hands-on examples and explanations of key concepts.

Uploaded by

ivi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

An introduction to the Quantum Simulator QCL

Rafael Trapani Possignolo


SEMBEI/LARC/PCS/POLI/USP

August 24, 2011

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

1 / 30

Installation

Getting Started
Simple examples
Simulation Limits
QCL Code

First examples: Entanglement


Measurement
Entanglement

The first Quantum Operator


A simple script
Toffoli Gate

More on syntax
Some helpful structures

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

2 / 30

Installation

Table of Contents
1

Installation

Getting Started
Simple examples
Simulation Limits
QCL Code

First examples: Entanglement


Measurement
Entanglement

The first Quantum Operator


A simple script
Toffoli Gate

More on syntax
Some helpful structures

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

3 / 30

Installation

Installation

Get the source code at


http://tph.tuwien.ac.at/~oemer/qcl.html
Untar the file (tar xzvf qcl-0.6.3.tgz)
make; make install
To run, just type qcl in your terminal
Note: qcl is only available in Linux operating systems. If youre using Windows
try a virtual machine or Cygwin.
Note2: You need flex and bison in order to use qcl. Some other packages may
also be needed for additional features, look into the documentation to more info.

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

4 / 30

Getting Started

Table of Contents
1

Installation

Getting Started
Simple examples
Simulation Limits
QCL Code

First examples: Entanglement


Measurement
Entanglement

The first Quantum Operator


A simple script
Toffoli Gate

More on syntax
Some helpful structures

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

5 / 30

Getting Started

Simple examples

Table of Contents
1

Installation

Getting Started
Simple examples
Simulation Limits
QCL Code

First examples: Entanglement


Measurement
Entanglement

The first Quantum Operator


A simple script
Toffoli Gate

More on syntax
Some helpful structures

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

6 / 30

Getting Started

Simple examples

Embedded Examples

The lib folder contain some examples


Type qcl to start the environment

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

7 / 30

Getting Started

Simple examples

Embedded Examples

The lib folder contain some examples


Type qcl to start the environment
Type include grover.qcl; to import the grover.qcl file
Use grover(10); to run the Grover Search for the number 10
Try other values

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

7 / 30

Getting Started

Simple examples

Embedded Examples

The lib folder contain some examples


Type qcl to start the environment
Type include grover.qcl; to import the grover.qcl file
Use grover(10); to run the Grover Search for the number 10
Try other values
Now import shor.qcl and run the Shors algorithm to some values

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

7 / 30

Getting Started

Simulation Limits

Table of Contents
1

Installation

Getting Started
Simple examples
Simulation Limits
QCL Code

First examples: Entanglement


Measurement
Entanglement

The first Quantum Operator


A simple script
Toffoli Gate

More on syntax
Some helpful structures

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

8 / 30

Getting Started

Simulation Limits

Questions

What happens when you use a prime value?


What happens when you enter a even number?
And a square?

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

9 / 30

Getting Started

Simulation Limits

Questions

What happens when you use a prime value?


What happens when you enter a even number?
And a square?
What is the highest factorable value? (Shor)
What is the highest searchable value? (Grover)

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

9 / 30

Getting Started

Simulation Limits

Questions

What happens when you use a prime value?


What happens when you enter a even number?
And a square?
What is the highest factorable value? (Shor)
What is the highest searchable value? (Grover)
What is the maximum number of Qubits allowed? Why?

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

9 / 30

Getting Started

QCL Code

Table of Contents
1

Installation

Getting Started
Simple examples
Simulation Limits
QCL Code

First examples: Entanglement


Measurement
Entanglement

The first Quantum Operator


A simple script
Toffoli Gate

More on syntax
Some helpful structures

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

10 / 30

Getting Started

QCL Code

Going through the code


Use gedit (or your favorite text editor) to open grover.qcl
Identify the types of sub-programs presented in the language

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

11 / 30

Getting Started

QCL Code

Going through the code


Use gedit (or your favorite text editor) to open grover.qcl
Identify the types of sub-programs presented in the language
What is the difference between them? (procedure, operator, qufunct)

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

11 / 30

Getting Started

QCL Code

Going through the code


Use gedit (or your favorite text editor) to open grover.qcl
Identify the types of sub-programs presented in the language
What is the difference between them? (procedure, operator, qufunct)
routine type program state machine state recursion
procedure
all
all
yes
operator
none
unitary
no
qufunct
none
pseudo-classic
no
functions
none
none
yes

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

11 / 30

Getting Started

QCL Code

Going through the code


Use gedit (or your favorite text editor) to open grover.qcl
Identify the types of sub-programs presented in the language
What is the difference between them? (procedure, operator, qufunct)
routine type program state machine state recursion
procedure
all
all
yes
operator
none
unitary
no
qufunct
none
pseudo-classic
no
functions
none
none
yes
Operator O : A Op A
qufunc: F : |xi|0i |xi|f (x)i
Can you identify basic quantum ports in the code?

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

11 / 30

First examples: Entanglement

Table of Contents
1

Installation

Getting Started
Simple examples
Simulation Limits
QCL Code

First examples: Entanglement


Measurement
Entanglement

The first Quantum Operator


A simple script
Toffoli Gate

More on syntax
Some helpful structures

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

12 / 30

First examples: Entanglement

First Examples

We will make a first example to better understand entanglement and


QCL
First, we will type commands direct on the shell
The idea is to understand how the simulator works before going to
batch mode

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

13 / 30

First examples: Entanglement

Measurement

Table of Contents
1

Installation

Getting Started
Simple examples
Simulation Limits
QCL Code

First examples: Entanglement


Measurement
Entanglement

The first Quantum Operator


A simple script
Toffoli Gate

More on syntax
Some helpful structures

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

14 / 30

First examples: Entanglement

Measurement

Measurement

Open the qcl environment, and type:


qureg a[1];

declare qubit a

reset;

force all qubits to pure zero state

measure a;

make a measure on a

What is the output? Is this deterministic?

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

15 / 30

First examples: Entanglement

Measurement

Without closing the environment, type:


reset;
H(a);

apply Hadamard transform over a

measure a;
What is the output? Is this deterministic? (try re-typing this three
commands some times).

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

16 / 30

First examples: Entanglement

Entanglement

Table of Contents
1

Installation

Getting Started
Simple examples
Simulation Limits
QCL Code

First examples: Entanglement


Measurement
Entanglement

The first Quantum Operator


A simple script
Toffoli Gate

More on syntax
Some helpful structures

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

17 / 30

First examples: Entanglement

Entanglement

Simple Entanglement

Re-Open the qcl environment, and type:


qureg a[1];
qureg b[1];
reset;
H(a);
CNot(b,a);

flip b if a is |1i

What happened? Can you name this state?


Make a final measure on a, what happen to b?
Repeat the commands H, CNot and measure.

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

18 / 30

First examples: Entanglement

Entanglement

Bell states

Without closing the environment, type:


reset;
Not(a);

CNot(b,a);
This is the
states?

| i

flip b if a is |1i

Bell-state. Can you produce the missing |+ i and | i

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

19 / 30

The first Quantum Operator

Table of Contents
1

Installation

Getting Started
Simple examples
Simulation Limits
QCL Code

First examples: Entanglement


Measurement
Entanglement

The first Quantum Operator


A simple script
Toffoli Gate

More on syntax
Some helpful structures

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

20 / 30

The first Quantum Operator

A simple script

Table of Contents
1

Installation

Getting Started
Simple examples
Simulation Limits
QCL Code

First examples: Entanglement


Measurement
Entanglement

The first Quantum Operator


A simple script
Toffoli Gate

More on syntax
Some helpful structures

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

21 / 30

The first Quantum Operator

A simple script

A simple script

We will start by creating a simple script an using it in the QCL


environment:
Create a script.qcl file (gedit script.qcl &), containing:
include shor.qcl;
shor(15);

Now save, open the qcl environment, and call include teste.qcl.

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

22 / 30

The first Quantum Operator

A simple script

A simple procedure
Now we will use the procedure feature:
Create a procedure.qcl file, containing:
include shor.qcl;
procedure callShor(int x){
shor(x);
}

Now save, open the qcl environment, and call include procedure.qcl.
You will have to call callShor(15) to run the script.

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

23 / 30

The first Quantum Operator

Toffoli Gate

Table of Contents
1

Installation

Getting Started
Simple examples
Simulation Limits
QCL Code

First examples: Entanglement


Measurement
Entanglement

The first Quantum Operator


A simple script
Toffoli Gate

More on syntax
Some helpful structures

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

24 / 30

The first Quantum Operator

Toffoli Gate

Our first operator


We will use the operator feature to create a Toffoli gate, which will flip a
qubit if the other two are 1:
Create a toffoli.qcl file, containing:
operator toffoli(qureg q) {
if q[0] and q[1] { Not(q[2]); };
}

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

25 / 30

The first Quantum Operator

Toffoli Gate

Our first operator


We will use the operator feature to create a Toffoli gate, which will flip a
qubit if the other two are 1:
Create a toffoli.qcl file, containing:
operator toffoli(qureg q) {
if q[0] and q[1] { Not(q[2]); };
}
To test, open qcl and type:
include toffoli.qcl;
qureg q[3];
reset;
toffoli(q);

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

25 / 30

The first Quantum Operator

Toffoli Gate

Result should be 0, as all the qubits are 0. Now, try


Not(q[0]);
toffoli(q);

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

26 / 30

The first Quantum Operator

Toffoli Gate

Result should be 0, as all the qubits are 0. Now, try


Not(q[0]);
toffoli(q);
Result should be 1. Finally, try
Not(q[1]);
toffoli(q);

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

26 / 30

The first Quantum Operator

Toffoli Gate

Result should be 0, as all the qubits are 0. Now, try


Not(q[0]);
toffoli(q);
Result should be 1. Finally, try
Not(q[1]);
toffoli(q);
Result should be 7.

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

26 / 30

More on syntax

Table of Contents
1

Installation

Getting Started
Simple examples
Simulation Limits
QCL Code

First examples: Entanglement


Measurement
Entanglement

The first Quantum Operator


A simple script
Toffoli Gate

More on syntax
Some helpful structures

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

27 / 30

More on syntax

Some helpful structures

Table of Contents
1

Installation

Getting Started
Simple examples
Simulation Limits
QCL Code

First examples: Entanglement


Measurement
Entanglement

The first Quantum Operator


A simple script
Toffoli Gate

More on syntax
Some helpful structures

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

28 / 30

More on syntax

Some helpful structures

Conditional:
if a and (b or c) { do something }
else { do something else };
For loop:
for i=1 to N { do something }
While loop:
{ do something } until (some condition);
Do and undo transform:
H(a); !H(a);
Length of qureg a:
#a
Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

29 / 30

More on syntax

Some helpful structures

More on: http://tph.tuwien.ac.at/~oemer/qcl.html

Rafael Trapani Possignolo (SEMBEI)

QCL intro

August 24, 2011

30 / 30

You might also like