%matplotlib inline
# Importing standard Qiskit libraries and configuring account
from qiskit import QuantumCircuit, execute, Aer, IBMQ
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *
# Loading your IBM Q account(s)
provider = IBMQ.load_account() 

import scipy
from scipy.stats import unitary_group
u = unitary_group.rvs(2)
print(u)
qc = QuantumCircuit(2)
qc.iso(u, [0], [])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)


import scipy
from scipy import linalg
h = scipy.linalg.hadamard(2)
import numpy as np
u1 = np.dot(h, u)
u2 = np.dot(u1, h)

c2 = []
for i in range (2):
    c2.append(u2[i,i])
print(c2)
qc = QuantumCircuit(2)
qc.diagonal(c2, [0])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)

import scipy
from scipy.stats import unitary_group
u = unitary_group.rvs(4)
print(u)
qc = QuantumCircuit(4)
qc.iso(u, [0,1], [])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)

import scipy
from scipy import linalg
h = scipy.linalg.hadamard(4)/2
import numpy as np
u1 = np.dot(h, u)
u2 = np.dot(u1, h)

c2 = []
for i in range (4):
    c2.append(u2[i,i])
print(c2)
qc = QuantumCircuit(4)
qc.diagonal(c2, [0, 1])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)

import scipy
from scipy.stats import unitary_group
u = unitary_group.rvs(8)
print(u)
qc = QuantumCircuit(4)
qc.iso(u, [0, 1, 2], [])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)


import scipy
from scipy import linalg
h = scipy.linalg.hadamard(8)/3
import numpy as np
u1 = np.dot(h, u)
u2 = np.dot(u1, h)

c2 = []
for i in range (8):
    c2.append(u2[i,i])
print(c2)

qc = QuantumCircuit(4)
qc.diagonal(c2, [0, 1, 2])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)

import scipy
from scipy.stats import unitary_group
u = unitary_group.rvs(16)
print(u)
qc = QuantumCircuit(4)
qc.iso(u, [0, 1, 2, 3], [])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)


import scipy
from scipy import linalg
h = scipy.linalg.hadamard(16)/4
import numpy as np
u1 = np.dot(h, u)
u2 = np.dot(u1, h)

c2 = []
for i in range (16):
    c2.append(u2[i,i])
print(c2)

qc = QuantumCircuit(4)
qc.diagonal(c2, [0, 1, 2, 3])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)


import scipy
from scipy.stats import unitary_group
u = unitary_group.rvs(32)
print(u)
qc = QuantumCircuit(8)
qc.iso(u, [0, 1, 2, 3, 4], [])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)


import scipy
from scipy import linalg
h = scipy.linalg.hadamard(32)/5
import numpy as np
u1 = np.dot(h, u)
u2 = np.dot(u1, h)

c2 = []
for i in range (32):
    c2.append(u2[i,i])
print(c2)

qc = QuantumCircuit(8)
qc.diagonal(c2, [0, 1, 2, 3, 4])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)



import scipy
from scipy.stats import unitary_group
u = unitary_group.rvs(64)
print(u)
qc = QuantumCircuit(8)
qc.iso(u, [0, 1, 2, 3, 4, 5], [])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)


import scipy
from scipy import linalg
h = scipy.linalg.hadamard(64)/6
import numpy as np
u1 = np.dot(h, u)
u2 = np.dot(u1, h)

c2 = []
for i in range (64):
    c2.append(u2[i,i])
print(c2)

qc = QuantumCircuit(8)
qc.diagonal(c2, [0, 1, 2, 3, 4, 5])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)


import scipy
from scipy.stats import unitary_group
u = unitary_group.rvs(128)
print(u)
qc = QuantumCircuit(8)
qc.iso(u, [0, 1, 2, 3, 4, 5, 6], [])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)


import scipy
from scipy import linalg
h = scipy.linalg.hadamard(128)/7
import numpy as np
u1 = np.dot(h, u)
u2 = np.dot(u1, h)

c2 = []
for i in range (128):
    c2.append(u2[i,i])
print(c2)

qc = QuantumCircuit(8)
qc.diagonal(c2, [0, 1, 2, 3, 4, 5, 6])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)


import scipy
from scipy.stats import unitary_group
u = unitary_group.rvs(256)
print(u)
qc = QuantumCircuit(8)
qc.iso(u, [0, 1, 2, 3, 4, 5, 6, 7], [])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)


import scipy
from scipy import linalg
h = scipy.linalg.hadamard(256)/8
import numpy as np
u1 = np.dot(h, u)
u2 = np.dot(u1, h)

c2 = []
for i in range (256):
    c2.append(u2[i,i])
print(c2)

qc = QuantumCircuit(8)
qc.diagonal(c2, [0, 1, 2, 3, 4, 5, 6, 7])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)


import scipy
from scipy.stats import unitary_group
u = unitary_group.rvs(512)
print(u)
qc = QuantumCircuit(16)
qc.iso(u, [0, 1, 2, 3, 4, 5, 6, 7, 8], [])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)



import scipy
from scipy import linalg
h = scipy.linalg.hadamard(512)/9
import numpy as np
u1 = np.dot(h, u)
u2 = np.dot(u1, h)

c2 = []
for i in range (512):
    c2.append(u2[i,i])
print(c2)

qc = QuantumCircuit(16)
qc.diagonal(c2, [0, 1, 2, 3, 4, 5, 6, 7, 8])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)

import scipy
from scipy.stats import unitary_group
u = unitary_group.rvs(1024)
print(u)
qc = QuantumCircuit(16)
qc.iso(u, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)



import scipy
from scipy import linalg
h = scipy.linalg.hadamard(1024)/10
import numpy as np
u1 = np.dot(h, u)
u2 = np.dot(u1, h)

c2 = []
for i in range (1024):
    c2.append(u2[i,i])
print(c2)

qc = QuantumCircuit(16)
qc.diagonal(c2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
qc = transpile(qc, basis_gates = ['u3', 'cx'], seed_transpiler=0, optimization_level=3)
circuit_drawer(qc)






