repo stringclasses 900
values | file stringclasses 754
values | content stringlengths 4 215k |
|---|---|---|
https://github.com/mett29/Shor-s-Algorithm | mett29 | from qiskit import QuantumCircuit, Aer, execute, IBMQ
from qiskit.utils import QuantumInstance
import numpy as np
from qiskit.algorithms import Shor
IBMQ.enable_account('ENTER API TOKEN HERE') # Enter your API token here
provider = IBMQ.get_provider(hub='ibm-q')
backend = Aer.get_backend('qasm_simulator')
qu... |
https://github.com/Cortexelus/qubit-audio-synthesis | Cortexelus | import numpy as np
pi = np.pi
import matplotlib.pyplot as plt
import librosa
%matplotlib inline
# Importing standard Qiskit libraries and configuring account
from qiskit import QuantumCircuit, execute, Aer, IBMQ, ClassicalRegister, QuantumRegister
from qiskit.compiler import transpile, assemble
from qiskit.tool... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | %matplotlib inline
from qiskit import *
from qiskit.visualization import *
from qiskit.tools.monitor import *
# Let's create a circuit to put a state in superposition and measure it
circ = QuantumCircuit(1,1) # We use one qubit and also one classical bit for the measure result
circ.h(0) #We apply the H g... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | %matplotlib inline
from qiskit import *
from qiskit.visualization import *
from qiskit.tools.monitor import *
circ_random = QuantumCircuit(1,1) # We need qubit and one classical bit
circ_random.h(0) #We apply the H gate
circ_random.measure(range(1),range(1)) # Measure
circ_random.draw(output='mpl')
... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | %matplotlib inline
from qiskit import *
from qiskit.visualization import *
from qiskit.tools.monitor import *
circ_bell = QuantumCircuit(2,2) # We need two qubits and two classical bits (for the measurements)
circ_bell.h(0) # We apply the H gate on the first qubit
circ_bell.cx(0,1) # We apply the CNOT gate ... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | #%matplotlib inline
from qiskit import *
from qiskit.tools.monitor import *
from qiskit.providers.ibmq import least_busy
import numpy as np
#Function to create the circuits for the CHSH game
def CHSH_circuit(x,y,a0=0,a1=np.pi/2,b0=np.pi/4,b1=-np.pi/4):
#x: bit received by Alice
#y: bit recei... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | %matplotlib inline
from qiskit import *
from qiskit.visualization import *
from qiskit.tools.monitor import *
import random, time
# We will create a random qubit by directly assigning random amplitudes
a1 = random.random()*2 -1 #Uniform number in [-1,1]
a2 = random.random()*2 -1
b1 = random.random()*2 -1
... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | %matplotlib inline
from qiskit import *
from qiskit.visualization import *
from qiskit.tools.monitor import *
n = 4 # Number of qubits that we are going to use in the oracle
q = QuantumRegister(n, 'q') # The oracle qubits
out = QuantumRegister(1, 'out') # Qubit for the oracle output
c = ClassicalRegist... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | %matplotlib inline
from qiskit import *
from qiskit.visualization import *
from qiskit.tools.monitor import *
import numpy as np
def init_grover(q):
circ = QuantumCircuit(q)
n = len(q)
circ.x(n-1) # The qubit that receives the oracle output must be set to |1>
for i in range(n):... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | %matplotlib inline
from qiskit import *
from qiskit.visualization import *
from qiskit.tools.monitor import *
from qiskit.aqua import *
from qiskit.aqua.components.oracles import *
from qiskit.aqua.algorithms import *
oracle = TruthTableOracle("0101")
oracle.construct_circuit().draw(output='mpl')
dj = De... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | %matplotlib inline
from qiskit import *
from qiskit.visualization import *
from qiskit.tools.monitor import *
from qiskit.aqua import *
from qiskit.aqua.algorithms import *
shor = Shor(N=15, a = 2)
backend = Aer.get_backend('qasm_simulator')
quantum_instance = QuantumInstance(backend)
result = shor.run(qua... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | import numpy as np
from qiskit import Aer, IBMQ
from qiskit.aqua import aqua_globals, QuantumInstance
from qiskit.aqua.algorithms import QAOA
from qiskit.aqua.components.optimizers import *
from qiskit.quantum_info import Pauli
from qiskit.aqua.operators import WeightedPauliOperator
from qiskit.providers.aer.n... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | from qiskit.chemistry.drivers import PySCFDriver, UnitsType, Molecule
from qiskit.chemistry.transformations import FermionicTransformation, FermionicQubitMappingType
molecule = Molecule(geometry=[['H', [0., 0., 0.]],
['H', [0., 0., 0.735]]],
charge=0, multiplicit... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | import matplotlib.pyplot as plt
import numpy as np
from qiskit import Aer
from qiskit.ml.datasets import breast_cancer
from qiskit.circuit.library import ZZFeatureMap
from qiskit.aqua import QuantumInstance
from qiskit.aqua.algorithms import QSVM
np.random.seed(2020)
n = 30
# Training examples for class 0
... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | import matplotlib.pyplot as plt
import numpy as np
from qiskit import Aer
from qiskit.ml.datasets import breast_cancer
from qiskit.circuit.library import ZZFeatureMap
from qiskit.circuit.library.n_local.two_local import TwoLocal
from qiskit.aqua import QuantumInstance
from qiskit.aqua.algorithms import VQC
from... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | %matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from qiskit import Aer
from qiskit.aqua import QuantumInstance
from qiskit.aqua.algorithms import QGAN
np.random.seed(2020)
N = 1000
real_data = np.random.binomial(3,0.5,N)
plt.hist(real_data, bins = 4);
n = 2
num_qubits = [n]
num_e... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | %matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from qiskit import Aer
from qiskit.aqua import QuantumInstance
from qiskit.aqua.algorithms import QGAN
np.random.seed(2020)
N = 1000
real_data = np.random.binomial(3,0.5,N)
plt.hist(real_data, bins = 4);
n = 2
num_qubits = [n]
num_e... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # Importing standard Qiskit libraries
from qiskit import QuantumCircuit, execute, Aer, IBMQ
# Loading your IBM Q account(s)
provider = IBMQ.load_account()
n = 1000
circ = QuantumCircuit(n,n)
circ.h(0)
for i in range(1,n):
circ.cx(0,i)
circ.measure(range(n),range(n))
backend = Aer.get_backend("qa... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | %matplotlib inline
import matplotlib.pyplot as plt
from qiskit import QuantumCircuit, execute, Aer
from qiskit.circuit.random import random_circuit
n_circs = 10000
n_qubits = 4
n_layers = 30
freq = []
backend_m = Aer.get_backend("qasm_simulator")
backend_s = Aer.get_backend("statevector_simulator")
for _ ... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | #Adding Two Numbers
x=2+5
print(x)
#Subtracting Two Numbers
y=8-5
print(y)
#Multiplying Two Numbers
a=3*5
print(a)
#Dividing Two Numbers
b=8/4
print(b)
#Calculate the Remainder
r=4%3
print(r)
#Exponent of a Number
e=5**3
print(e)
c1=1j*1j
print(c1)
#Initialize two complex numbers
z=4+... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | #Uncomment the below line
#!pip install qiskit
#!pip install qiskit[visualization]
import numpy as np
import qiskit
qiskit.__qiskit_version__
#Import everything from qiskit
from qiskit import *
from qiskit.visualization import plot_bloch_vector
plot_bloch_vector([0,0,1],title = 'spinup')
plot_bl... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | from qiskit import *
from qiskit.visualization import plot_bloch_multivector
# Let's do an X-gate on a |0> qubit
qc=QuantumCircuit(1)
qc.x(0)
qc.draw('mpl')#mpl stands for the matplotlib argument
# Let's see the result
backend = Aer.get_backend('statevector_simulator')
out = execute(qc, backend).result().ge... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | import numpy as np
from qiskit import *
qc = QuantumCircuit(3)
# Apply H-gate to each qubit:
for qubit in range(3):
qc.h(qubit)
# See the circuit:
qc.draw('mpl')
# Let's see the result
backend = Aer.get_backend('statevector_simulator')
out = execute(qc,backend).result().get_statevector()
print(out)
... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | import numpy as np
from qiskit import *
%matplotlib inline
from qiskit.tools.visualization import plot_histogram
s = 101011
from qiskit import *
qc = QuantumCircuit(6+1,6)
qc.h([0,1,2,3,4,5])
qc.draw('mpl')
qc.x(6)
qc.h(6)
qc.barrier()
qc.draw('mpl')
qc.cx(5, 6)
qc.cx(3, 6)
qc.cx(1, 6)
qc.cx(0... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
from qiskit import *
from qiskit.tools.visualization import plot_histogram
from IPython.display import display, Math, Latex
from qiskit.visualization import plot_state_qsphere
def BuildBell(x, y):
U = QuantumCircuit(2)
U.... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
from qiskit import *
from qiskit.tools.visualization import plot_histogram
from IPython.display import display, Math, Latex
def BuildGHZ(n):
U = QuantumCircuit(n)
U.h(0)
for i in range(1, n):
U.cx(0, i)
... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | import numpy as np
from numpy import linalg as LA
from scipy.linalg import expm, sinm, cosm
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import math
from scipy import stats
%matplotlib inline
from IPython.display import Image, display, Math, Latex
sns.set(color_codes=True)
#n... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
from qiskit import *
from qiskit.tools.visualization import plot_histogram
from IPython.display import display, Math, Latex
def Decrement(n):
U = QuantumCircuit(n)
control = [x for x in range(n-1)]
for k in range(n-1):
... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
from qiskit import IBMQ, BasicAer
from qiskit.providers.ibmq import least_busy
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute
from qiskit.quantum_info import Statevector
from qiskit.visualization import plot_s... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
from qiskit import *
from qiskit.providers.ibmq import least_busy
from qiskit.tools.visualization import plot_histogram
from IPython.display import display, Math, Latex
def Increment(size):
U = QuantumCircuit(size)
control = [x... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | import numpy as np
# Importing standard Qiskit libraries
from qiskit import QuantumCircuit, transpile, Aer, IBMQ
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from ibm_quantum_widgets import *
from qiskit.providers.aer import QasmSimulator
# Loading your IBM Quantum account(s)
provid... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | from qiskit import BasicAer, execute
from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.circuit.library.standard_gates import PhaseGate
from qiskit.circuit.library.basis_change import QFT
import math
from src.util.util import run_qc
q = QuantumRegister(3)
b = QuantumReg... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
import math
from qiskit.visualization import plot_state_qsphere
from qiskit import *
from qiskit.tools.visualization import plot_histogram
from IPython.display import display, Math, Latex
def reflect(U, n):
for i in range(int(n/2))... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
from qiskit import *
from qiskit.providers.ibmq import least_busy
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute
from qiskit.quantum_info import Statevector
from qiskit.circuit.library import QFT
from qiskit.... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | import numpy as np
from scipy.linalg import expm, sinm, cosm
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import math
from scipy import stats
%matplotlib inline
from IPython.display import Image, display, Math, Latex
sns.set(color_codes=True) |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # A jupyter notebook is composed by one or more cells.
# There are two main cells: Code and Markdown.
# A code cell is used to write and execute your codes.
# A markdown cell is used to write text descriptions, notes, formulas or include graphics and images.
# On a markdown cell, you can format your content by usin... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | number = 5 # integer
real = -3.4 # float
name = 'Asja' # string
surname = "Sarkana" # string
boolean1 = True # Boolean
boolean2 = False # Boolean
a = 13
b = 5
print("a =",a)
print("b =",b)
print()
# basics operators
print("a + b =",a+b)
print("a - b =",a-b)
print("a * b =",a*b)
print("a / b =",... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | from matplotlib.pyplot import plot, figure, arrow, Circle, gca, text, bar
figure(figsize=(6,6), dpi=60)
#The higher dpi value makes the figure bigger.
plot(1,5,'bo')
arrow(0.5,0.5,0.1,0.1,head_width=0.04,head_length=0.08,color="blue")
arrow(0,0,1.1,0,head_width=0.04,head_length=0.08)
arrow(0,0,-1.1... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # This is a comment
# A comment is used for explanations/descriptions/etc.
# Comments do not affect the programs
# let's define an integer variable named a
a = 5
# let's print its value
print(a)
# let's define three integer variables named a, b, and c
a = 2
b = 4
c = a + b # summation of a and b
# le... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # let's print all numbers between 0 and 9
for i in range(10): print(i)
# range(n) represents the list of all numbers from 0 to n-1
# i is the variable to take the values in the range(n) iteratively: 0, 1, ..., 9 in our example
# let's write the same code in two lines
for i in range(10): # do not forget to use co... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # let's randomly pick a number between 0 and 9, and print its value if it is greater than 5
from random import randrange
r = randrange(10)
if r > 5: print(r) # when the condition (r > 5) is valid/true, the code (print(r)) will be executed
# you may need to execute your code more than once to see an outcome
#... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # here is a list holding all even numbers between 10 and 20
L = [10, 12, 14, 16, 18, 20]
# let's print the list
print(L)
# let's print each element by using its index but in reverse order
print(L[5],L[4],L[3],L[2],L[1],L[0])
# let's print the length (size) of list
print(len(L))
# let's print each elemen... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
# define a quantum register with one qubit
q = QuantumRegister(1,"qreg")
# define a classical register with one bit
# it stores the measurement result of the quan... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # the given matrix
M = [
[0.05, 0, 0.70, 0.60],
[0.45, 0.50, 0.20, 0.25],
[0.20, 0.35, 0.10, 0],
[0.30, 0.15, 0, 0.15]
]
#
# you may enumarate the columns and rows by the strings '00', '01', '10', and '11'
# int('011',2) returns the decimal value of the binary string '011'
#
#
# your so... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | from random import randrange
#
# you may use method 'randrange' for this task
# randrange(n) returns a value from {0,1,...,n-1} randomly
#
#
# your solution is here
#
from random import randrange
for experiment in [100,1000,10000,100000]:
heads = tails = 0
for i in range(experiment):
if ... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | #
# OUR SOLUTION
#
# initial condition:
# Asja will start with one euro,
# and so, we assume that the probability of having head is 1 at the beginning.
prob_head = 1
prob_tail = 0
#
# first coin-flip
#
# the new probability of head is calculated by using the first row of table
new_prob_head = pro... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | #
# your code is here
#
# all portions are stored in a list
all_portions = [7,5,4,2,6,1];
# calculate the total portions
total_portion = 0
for i in range(6):
total_portion = total_portion + all_portions[i]
print("total is",total_portion)
# find the weight of one portion
one_portion = 1/total_porti... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | #
# your solution is here
#
# let's start with a zero matrix
A = [
[0,0,0],
[0,0,0],
[0,0,0]
]
# we will randomly pick the entries and then make normalization for each column
# it will be easier to iteratively construct the columns
# you may notice that each column is a probabilistic state
fro... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # the initial state
initial = [0.5, 0, 0.5, 0]
# probabilistic operator for symbol a
A = [
[0.5, 0, 0, 0],
[0.25, 1, 0, 0],
[0, 0, 1, 0],
[0.25, 0, 0, 1]
]
# probabilistic operator for symbol b
B = [
[1, 0, 0, 0],
[0, 1, 0.25, 0],
[0, 0, 0.5, 0],
[0, 0, 0.25, 1]... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | #
# A quantum circuit is composed by quantum and classical bits in Qiskit.
#
# here are the objects that we use to create a quantum circuit in qiskit
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
# we use a quantum register to keep our quantum bits.
q = QuantumRegister(1,"qreg") # in... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | def biased_coin(N,B):
from random import randrange
random_number = randrange(N)
if random_number < B:
return "Heads"
else:
return "Tails"
from random import randrange
N = 1001
B = randrange(1000)
total_tosses = 1000
the_number_of_heads = 0
for i in range(total_tosses):
... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | #
# your solution is here
#
|
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | #
# your code is here
# (you may find the values by hand (in mind) as well)
#
# vector |v>
print("vector |v>")
values = [-0.1, -0.3, 0.4, 0.5]
total = 0 # summation of squares
for i in range(len(values)):
total += values[i]**2; # add the square of each value
print("total is ",total)
print("the ... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # import the drawing methods
from matplotlib.pyplot import plot, figure, show
# draw a figure
figure(figsize=(6,6), dpi=80)
# include our predefined functions
%run qlatvia.py
# draw the axes
draw_axes()
# draw the origin
plot(0,0,'ro') # a point in red color
# draw these quantum states as points (in... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
# define a quantum register with a single qubit
q = QuantumRegister(1,"q")
# define a classical register with a single bit
c = ClassicalRegister(1,"c")
# define a q... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | %run qlatvia.py
draw_qubit()
sqrttwo=2**0.5
draw_quantum_state(1,0,"")
draw_quantum_state(1/sqrttwo,1/sqrttwo,"|+>")
# drawing the angle with |0>-axis
from matplotlib.pyplot import gca, text
from matplotlib.patches import Arc
gca().add_patch( Arc((0,0),0.4,0.4,angle=0,theta1=0,theta2=45) )
text(0.08,... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | %run qlatvia.py
draw_qubit()
sqrttwo=2**0.5
draw_quantum_state(1,0,"")
draw_quantum_state(1/sqrttwo,1/sqrttwo,"|+>")
# drawing the angle with |0>-axis
from matplotlib.pyplot import gca, text
from matplotlib.patches import Arc
gca().add_patch( Arc((0,0),0.4,0.4,angle=0,theta1=0,theta2=45) )
text(0.08,... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | %run qlatvia.py
draw_qubit()
draw_quantum_state(3/5,4/5,"u")
draw_quantum_state(3/5,-4/5,"u'")
# import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
# import randrange for random choices
from random import randr... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | from qiskit import *
q = QuantumRegister(2,"q")
c = ClassicalRegister(2,"c")
qc = QuantumCircuit(q,c)
qc.x(q[0])
qc.measure(q[0],c[0])
qc.h(q[1]).c_if(c,0)
qc.measure(q,c)
print(qc)
job = execute(qc,Aer.get_backend('qasm_simulator'),shots=1024)
counts = job.result().get_counts(qc)
print(counts)... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # class unknown_qubit
# available_qubit = 1000 -> you get at most 1000 qubit copies
# get_qubits(number_of_qubits) -> you get the specified number of qubits for your experiment
# measure_qubits() -> your qubits are measured and the result is returned as a dictionary variable
# -> after meas... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | from qiskit import QuantumCircuit
# remark the coincise representation of a quantum circuit
qc = QuantumCircuit(2)
qc.h(0)
qc.h(1)
qc.draw(output='mpl',reverse_bits=True)
from qiskit import execute, Aer
job = execute(qc, Aer.get_backend('unitary_simulator'),shots=1,optimization_level=0)
current_unitar... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
#
# your code is here
#
# import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
q = QuantumRegister(2, "q")
c = ClassicalRegister(2, "c")
qc = QuantumCircuit(q,c)
qc.x(q[1])
qc.cx(q[1],q[0])
# Returning control qubit to the initial state
qc.x(q[1])
job = execute(qc,Aer.get_backend('unitary_simul... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | from qiskit import *
q2=QuantumRegister(3,"qreg")
c2=ClassicalRegister(3,"creg")
qc2=QuantumCircuit(q2,c2)
qc2.x(q2[1])
qc2.barrier()
qc2.x(q2[2])
qc2.ccx(q2[2],q2[1],q2[0])
qc2.x(q2[2])
qc2.barrier()
qc2.measure(q2,c2)
job=execute(qc2,Aer.get_backend('qasm_simulator'),shots=100)
counts=job.result... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
all_pairs = ['00','01','10','11']
#
# your code is here
#
# import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, Cla... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | #
# your code is here
#
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
from math import pi, cos, sin
from random import randrange
# quantum circuit with three qubits and three bits
q = QuantumRegister(3,"q")
c = ClassicalRegister(3,"c")
qc = QuantumCircuit(q,c)
# ro... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
from math import pi
# the angle of rotation
theta = pi/16
# we read streams of length 8, 16, 24, 32, 40, 48, 56, 64
for i in [8, 16, 24, 32, 40, 48, 56, 64]:
# quantum circuit with one qubit and one bit
qreg = Quantu... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
q = QuantumRegister(2, "q")
c = ClassicalRegister(2, "c")
qc = QuantumCircuit(q,c)
qc.x(q[1])
qc.cx(q[1],q[0])
# Returning control qubit to the initial state
qc.x(q[1])
job = execute(qc,Aer.get_backend('unitary_simul... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
from math import pi
# the angles of rotations
theta1 = pi/4
theta2 = pi/6
# the circuit with two qubits
qreg = QuantumRegister(2)
creg = ClassicalRegister(2)
mycircuit = QuantumCircuit(qreg,creg)
# when the second qub... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | from matplotlib.pyplot import bar
labels = []
elements = []
for i in range(8):
labels = labels + [i+1]
elements = elements + [1]
# visualize the values of elements in the list
bar(labels,elements)
#
# 1st step - query
#
# change the sign of the marked element, i.e., multiply it by -1
# ... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | %run qlatvia.py
draw_qubit_grover()
draw_quantum_state((5/8)**0.5,(3/8)**0.5,"|u>")
def query(elements=[1],marked_elements=[0]):
for i in marked_elements:
elements[i] = -1 * elements[i]
return elements
def inversion (elements=[1]):
# summation of all values
summation = 0
... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | %run ../include/quantum.py
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
qreg = QuantumRegister(3)
#No need to define classical register as we are not measuring
mycircuit = QuantumCircuit(qreg)
#set ancilla
mycircuit.x(qreg[2])
mycircuit.h(qreg[2])
Uf(mycircuit,... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # consider the following list with 4 elements
L = [1,-2,0,5]
print(L)
# 3 * v
v = [1,-2,0,5]
print("v is",v)
# we use the same list for the result
for i in range(len(v)):
v[i] = 3 * v[i]
print("3v is",v)
# -0.6 * u
# reinitialize the list v
v = [1,-2,0,5]
for i in range(len(v)):
v[i] = -0.6 *... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # let's define both vectors
u = [-3,-2,0,-1,4]
v = [-1,-1,2,-3,5]
uv = 0; # summation is initially zero
for i in range(len(u)): # iteratively access every pair with the same indices
print("pairwise multiplication of the entries with index",i,"is",u[i]*v[i])
uv = uv + u[i]*v[i] # i-th entries are multi... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # we may break lines when defining our list
M = [
[8 , 0 , -1 , 0 , 2],
[-2 , -3 , 1 , 1 , 4],
[0 , 0 , 1 , -7 , 1],
[1 , 4 , -2 , 5 , 9]
]
# let's print matrix M
print(M)
# let's print M in matrix form, row by row
for i in range(4): # there are 4 rows
print(M[i])
M = [
... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # vector v
v = [1,2,-3]
# vector u
u=[-2,3]
vu = []
for i in range(len(v)): # each element of v will be replaced
for j in range(len(u)): # the vector u will come here after multiplying with the entry there
vu.append( v[i] * u[j] )
print("v=",v)
print("u=",u)
print("vu=",vu)
#
# your solu... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | import qiskit
versions = qiskit.__qiskit_version__
print("The version of Qiskit is",versions['qiskit'])
print()
print("The version of each component:")
for key in versions:
print(key,"->",versions[key])
!pip install qiskit[visualization] --user
#!pip install -U qiskit --user
#!pip uninstall qiskit
#... |
https://github.com/aryashah2k/Quantum-Computing-Collection-Of-Resources | aryashah2k | # I am a comment in python
print("Hello From Quantum World :-)")
# please run this cell
# import the objects from qiskit
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
from random import randrange
# create a quantum circuit and its register objects
qreg = QuantumRegis... |
https://github.com/NTU-ALComLab/SliQSim-Qiskit-Interface | NTU-ALComLab | # -*- coding: utf-8 -*-
# Copyright 2018, IBM.
#
# This source code is licensed under the Apache License, Version 2.0 found in
# the LICENSE.txt file in the root directory of this source tree.
"""
Exception for errors raised by SliQSim simulator.
"""
from qiskit import QiskitError
class SliQSimErro... |
https://github.com/NTU-ALComLab/SliQSim-Qiskit-Interface | NTU-ALComLab | # Import tools
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute
from qiskit_sliqsim_provider import SliQSimProvider
# Initiate SliQSim Provider
provider = SliQSimProvider()
# Construct a quantum circuit: 2-qubit bell-state
qr = QuantumRegister(2)
cr = ClassicalRegister(2)
qc = ... |
https://github.com/Naphann/Solving-TSP-Grover | Naphann | import qiskit
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit import Aer
import numpy as np
from math import floor, ceil
%matplotlib inline
def max_number(arr_size):
return (2 ** arr_size)-1
def check_min_circuit(a, threshold):
max = max_number(a)
foo = ma... |
https://github.com/Naphann/Solving-TSP-Grover | Naphann | from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit import IBMQ, Aer, execute
from qiskit.tools.visualization import plot_histogram
## distance_black_box
distances = {
"32": 3,
"31": 2,
"30": 4,
"21": 7,
"20": 6,
"10": 5,
}
def dist_single():
... |
https://github.com/Naphann/Solving-TSP-Grover | Naphann | from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit import IBMQ, Aer, execute
from qiskit.tools.visualization import plot_histogram
## oracle_initialize_part
def OR(qubit_1, qubit_2, k):
# enter qubit numbers here
""" function does the equivalent of a classical OR betwee... |
https://github.com/Naphann/Solving-TSP-Grover | Naphann | from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit import IBMQ, Aer, execute
from qiskit.tools.visualization import plot_histogram
## oracle_initialize_part
def OR(qubit_1, qubit_2, k):
# enter qubit numbers here
""" function does the equivalent of a classical OR betwee... |
https://github.com/Naphann/Solving-TSP-Grover | Naphann | import qiskit
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit import Aer
import numpy as np
from math import floor, ceil
%matplotlib inline
import gate_extensions
for n in range(5, 7):
print('{}-bit controls'.format(n))
for inp in range(2**n):
qr = Qua... |
https://github.com/Naphann/Solving-TSP-Grover | Naphann | import qiskit
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit import Aer
import numpy as np
from math import floor, ceil
%matplotlib inline
def RTL(qc, a, b, c):
## fig 3 dashed
qc.rccx(a, b, c)
def RTL_inv(qc, a, b, c):
RTL(qc, a, b, c)
def RTS(qc,... |
https://github.com/Naphann/Solving-TSP-Grover | Naphann | #initialization
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
# importing Qiskit
from qiskit import IBMQ, BasicAer, Aer
from qiskit.providers.ibmq import least_busy
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute
# import basic plot tools
from qiskit.t... |
https://github.com/Naphann/Solving-TSP-Grover | Naphann | #initialization
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
# importing Qiskit
from qiskit import IBMQ, BasicAer, Aer
from qiskit.providers.ibmq import least_busy
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute
# import basic plot tools
from qiskit.t... |
https://github.com/Naphann/Solving-TSP-Grover | Naphann | #initialization
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
# importing Qiskit
from qiskit import IBMQ, BasicAer, Aer
from qiskit.providers.ibmq import least_busy
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute
# import basic plot tools
from qiskit.t... |
https://github.com/Naphann/Solving-TSP-Grover | Naphann | import qiskit
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit import Aer
from qiskit.circuit import Qubit
import numpy as np
from math import floor, ceil
def RTL(qc, a, b, c):
## fig 3 dashed
qc.rccx(a, b, c)
def RTL_inv(qc, a, b, c):
RTL(qc, a, b, c)
... |
https://github.com/samuraigab/Quantum-Basic-Algorithms | samuraigab | from qiskit import QuantumCircuit
from qiskit.visualization import plot_histogram
qc=QuantumCircuit(4,2) ## for adder we need four quantum register and 2 classical register
qc.barrier()
# use cnots to write the XOR of the inputs on qubit 2
qc.cx(0,2)
qc.cx(1,2)
qc.ccx(0,1,3)
qc.barrier()
# extract outputs
q... |
https://github.com/samuraigab/Quantum-Basic-Algorithms | samuraigab | import numpy as np
# Importing standard Qiskit libraries
from qiskit import QuantumCircuit, transpile, Aer, IBMQ,execute
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from ibm_quantum_widgets import *
# Loading your IBM Quantum account(s)
provider = IBMQ.load_account()
# Criando um c... |
https://github.com/samuraigab/Quantum-Basic-Algorithms | samuraigab | import numpy as np
# Importing standard Qiskit libraries
from qiskit import *
from qiskit import QuantumCircuit, transpile, Aer, IBMQ
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from ibm_quantum_widgets import *
from qiskit_textbook.tools import array_to_latex
# Loading your IBM ... |
https://github.com/samuraigab/Quantum-Basic-Algorithms | samuraigab | import numpy as np
from numpy import pi
# importing Qiskit
from qiskit import QuantumCircuit, transpile, assemble, Aer
from qiskit.visualization import plot_histogram, plot_bloch_multivector
qc = QuantumCircuit(3)
qc.h(2)
qc.cp(pi/2, 1, 2)
qc.cp(pi/4, 0, 2)
qc.h(1)
qc.cp(pi/2, 0, 1)
qc.h(0)
qc.swap(0, 2)
... |
https://github.com/samuraigab/Quantum-Basic-Algorithms | samuraigab | import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
from qiskit import QuantumCircuit, Aer, transpile, assemble
from qiskit.visualization import plot_histogram, plot_bloch_multivector
qc = QuantumCircuit(1,1)
# Alice prepares qubit in state |+>
qc.h(0)
qc.barrier()
# Alice now sends t... |
https://github.com/samuraigab/Quantum-Basic-Algorithms | samuraigab | '''
Quantum Phase Estimation
Por Samuraí Brito
Data:02072021
'''
import numpy as np
# Importing standard Qiskit libraries
from qiskit import QuantumCircuit, transpile, Aer, IBMQ, execute
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from ibm_quantum_widgets import *
# Lo... |
https://github.com/samuraigab/Quantum-Basic-Algorithms | samuraigab | # !pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org Ipython
# pip install -U notebook-as-pdf
from IPython.display import display, Latex
from IPython.display import Image
from qiskit import *
from qiskit.visualization import *
from qiskit.quantum_info import Statevector
import num... |
https://github.com/weiT1993/qiskit_helper_functions | weiT1993 | """
Teague Tomesh - 2/10/2020
Implementation of an n-bit ripple-carry adder.
Based on the specification given in Cuccaro, Draper, Kutin, Moulton.
(https://arxiv.org/abs/quant-ph/0410184v1)
"""
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
class RCAdder:
"""
An n-bit ri... |
https://github.com/weiT1993/qiskit_helper_functions | weiT1993 | from qiskit import QuantumCircuit
from QCLG_lvl3.oracles.secret_number_oracle import SecretNUmberOracle
class BernsteinVazirani:
@classmethod
def bernstein_vazirani(cls, random_binary, eval_mode: bool) -> QuantumCircuit:
# Construct secret number oracle
secret_number_oracle = Sec... |
https://github.com/weiT1993/qiskit_helper_functions | weiT1993 | from qiskit import QuantumCircuit, QuantumRegister
import sys
import math
import numpy as np
class Dynamics:
"""
Class to implement the simulation of quantum dynamics as described
in Section 4.7 of Nielsen & Chuang (Quantum computation and quantum
information (10th anniv. version), 2010.)
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.