🌱Aadam's Garden

Search

Search IconIcon to open search

IBM Quantum Experience

Last updated Jun 25, 2022

Source:: 2022 Introduction to Classical and Quantum Computing

Many companies are building NISQ device. In this chapter, we will lean to program IBM’s Quantum Computers because they are freely available to the public. Lessons learned from this toolkit can easily be used to learn other toolkits as well.

# IBM Quantum Experience

# Services

# Circuit Composer

# Quantum Processor

# Simulator

# Quantum Assembly Language

# OpenQASM

# A simple program:

1
2
3
4
5
6
7
8
9
OPENQASM 2.0;

qreg q[3];
creg c[3];

U(pi, 0, pi) q[0];
CX [q0], q[1];

measure q -> c;
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
OPENQASM 2.0;

// Define the Pauli X gate. 
gate x a 
{ 
	U(pi,0,pi) a; 
}


qreg q[3];
creg c[3];

x q[0];
CX [q0], q[1];

measure q -> c;

# Quantum Experience Standard Header

# OpenQASM in IBM Quantum Experience

# Quantum Adder

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
OPENQASM 2.0; 

// Include standard gates from IBM Quantum Experience. 
include "qelib1.inc"; 

// Define the quantum sum gate. 
gate sum cin, a, b 
{ 
    cx a, b; 
    cx cin, b; 
} 

// Define the quantum carry gate. 
gate carry cin, a, b, cout 
{ 
    ccx a, b, cout; 
    cx a, b; 
    ccx cin, b, cout; 
} 

// Define the inverse of the quantum carry gate. 
gate carrydg cin, a, b, cout 
{ 
    ccx cin, b, cout; 
    cx a, b; 
    ccx a, b, cout; 
} 

// Declare the quantum registers. 
qreg c[4]; 
qreg a[4]; 
qreg b[5]; 

// Declare the classical registers. 
creg bc[5]; 

// Set the input states by applying X gates. 
x a[1]; 
x a[2]; 
x a[3]; // a = 1110 
x b[0]; 
x b[1]; 
x b[3]; // b = 1011 

// Add the numbers so that |a>|b> becomes |a>|a+b>. 
carry c[0], a[0], b[0], c[1]; 
carry c[1], a[1], b[1], c[2]; 
carry c[2], a[2], b[2], c[3]; 
carry c[3], a[3], b[3], b[4]; 
cx a[3], b[3]; 
sum c[3], a[3], b[3];
carrydg c[2], a[2], b[2], c[3]; 
sum c[2], a[2], b[2]; 
carrydg c[1], a[1], b[1], c[2]; 
sum c[1], a[1], b[1]; 
carrydg c[0], a[0], b[0], c[1]; 
sum c[0], a[0], b[0]; 

// Measure the sum and put it in the classical register. 
measure b -> bc;

# Qiskit

# Circuit Composer

# Quantum Lab

# Simulator

# Quantum Processor

# Other Quantum Programming Languages

# Summary