In [34]:
from IPython.display import Image
Image("images/F2.png",width=400)
Out[34]:
In [35]:
Image("images/dieti.png",width=150)
Out[35]:

Department of Electrical Engineering and Information Technology, Via Claudio 21, Naples, Italy

 www.nanophotonics.it

Introduction to Quantum Circuits

Deutsch - Jozsa algorithm

In [37]:
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
%config InlineBackend.figure_format = 'svg' # Makes the images look nice
In [38]:
n=2
qc = QuantumCircuit(n,n)  # Create a quantum circuit with one qubit
backend = Aer.get_backend('statevector_simulator') # Tell Qiskit how to simulate our circuit

Preprocessing

In [39]:
qc.x(0) #Apply X-gate
qc.x(1) #Apply X-gate
qc.h(0) #Apply Hadamard-gate
qc.h(1) #Apply Hadamard-gate
qc.draw(output='mpl')
Out[39]:

Function

In [40]:
def one(): #Constant function
    qc.id(0)
    qc.id(1)
    return

def two(): #NON constant function
    qc.cx(0,1)
    return 
 
def three(): #NON constant function
    qc.id(0)
    qc.x(1)
    qc.cx(0,1)
    return 
 
def four(): #Constant function
    qc.id(0)
    qc.x(1)
    return

fun = 3
if fun == 1:
    one()
elif fun == 2:
    two()
elif fun==3:
    three()
elif fun==4:
    four()
    
qc.draw(output='mpl')
Out[40]:

PostProcessing

In [41]:
qc.h(0) #Apply Hadamard-gate
qc.i(1) #Apply Hadamard-gate
qc.draw(output='mpl')
Out[41]:

Measurement

In [42]:
qc.measure(0,0)
qc.measure(1,1)
qc.draw(output='mpl')
Out[42]:
In [43]:
counts = execute(qc,Aer.get_backend('qasm_simulator'),shots=1000).result().get_counts()
In [44]:
plot_histogram(counts)
Out[44]:

Bibliography

  1. David Deutsch & Richard Jozsa (1992). "Rapid solutions of problems by quantum computation". Proceedings of the Royal Society of London A. 439 (1907): 553–558. doi:10.1098/rspa.1992.0167.

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

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