Skip to content

Instantly share code, notes, and snippets.

@kareem1925
Last active February 15, 2020 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kareem1925/3908906a364b45273a621fcab40c51c8 to your computer and use it in GitHub Desktop.
Save kareem1925/3908906a364b45273a621fcab40c51c8 to your computer and use it in GitHub Desktop.
simple implementation of circuit-centeric quantum classifier using qiskit
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit import *
import numpy as np
qc = QuantumCircuit(3,1)
weights = np.random.rand(18)
# First layer
qc.u3(weights[0],weights[1],weights[2],0)
qc.u3(weights[3],weights[4],weights[5],1)
qc.u3(weights[6],weights[7],weights[8],2)
qc.cnot(0,1)
qc.cnot(1,2)
qc.cnot(2,0)
# Second Layer
qc.u3(weights[9],weights[10],weights[11],0)
qc.u3(weights[15],weights[16],weights[17],1)
qc.u3(weights[12],weights[13],weights[14],2)
qc.cnot(0,1)
qc.cnot(1,2)
qc.cnot(2,0)
# Z measurement
qc.measure(0,0)
# Drawing
qc.draw(output='mpl')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment