In [1]:
from IPython.display import Image
Image("images/F2.png",width=300)

Out[1]:
In [2]:
Image("images/dieti.png",width=200)

Out[2]:

# Introduction to Quantum Circuits¶

The operator $U$ is defined as:

$$U|y\rangle = |7 \times y\bmod 15\rangle$$
In [3]:
from qiskit import *
from qiskit.visualization import plot_histogram, plot_bloch_vector, plot_bloch_multivector, circuit_drawer
from qiskit_textbook.widgets import plot_bloch_vector_spherical
from math import sqrt, pi
from IPython.display import display, Math, Latex

In [4]:
backend = Aer.get_backend('statevector_simulator') # Tell Qiskit how to simulate our circuit

In [5]:
qc = QuantumCircuit(4)

# Inizialization of the input value.
# Please change these four bits to test the function U|y>
# for different values of the input register
# For instance we choose |y> = |0111> = |7>

qc.x(0)
qc.x(1)
qc.x(2)
qc.i(3)

# DEFINITION OF THE FUNCTION U using NOT and CNOT gates

qc.x(0)
qc.x(1)
qc.x(2)
qc.x(3)

qc.cx(1,2)
qc.cx(2,1)
qc.cx(1,2)
qc.cx(2,3)
qc.cx(3,2)
qc.cx(2,3)
qc.cx(0,3)
qc.cx(3,0)
qc.cx(0,3)

# Draw the corresponding circuit using matplotlib
qc.draw(output='mpl')

Out[5]:
In [6]:
result = execute(qc,backend).result() # Do the simulation, returning the result
out_state = result.get_statevector() # Get the final statevector of an experiment.
print(out_state)

[0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j
0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]

In [7]:
plot_bloch_multivector(out_state)

Out[7]:
In [8]:
results = result.get_counts() # Get the histogram data of an experiment.
plot_histogram(results) # Display the output state vector

Out[8]:

In correspondence of the input $|y \rangle = |0111\rangle = |7\rangle_4$ we obtain $|y \rangle= |4\rangle_4=|0100\rangle_4$ in output as expected

# Bibliography¶

1. Qiskit: An Open-source Framework for Quantum Computing (2019), doi:10.5281/zenodo.2562110

2. N. David Mermin "Quantum Computer Science (An Introduction)" (2007)