This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## results | |
shost = 10000 | |
job = execute (qc,Aer.get_backend('qasm_simulator'),shots=shots) | |
job_result = job.result() | |
counts = job_result.get_counts(qc) | |
x = abs(((counts['0']/shots - 0.5)/0.5) * 2 * Z) | |
Q_Dist = round(m.sqrt(x),4) | |
print('Quantum Distance: ', round(Q_Dist,3)) | |
print('Euclidean Distance: ',round(Dist,3)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Quantum Circuit | |
q1 = QuantumRegister(1, name = 'q1') | |
q2 = QuantumRegister(4, name = 'q2') | |
c = ClassicalRegister(1, name = 'c') | |
qc = QuantumCircuit(q1,q2,c) | |
#States initialization | |
qc.initialize(phi, q2[0]) | |
qc.initialize(psi, q2[1:4]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#The first step is to encode the data into quantum states. | |
#There are some techniques to do it, in this case Amplitude embedding was used | |
A = [2,9,8,5] | |
B = [7,5,10,3] | |
norm_A = 0 | |
norm_B = 0 | |
Dist = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Import the necessary libraries | |
import math as m | |
from qiskit import * | |
from qiskit import BasicAer | |
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#result | |
shots = 1024 | |
job = execute(qc,Aer.getbackend('qasm_simulator'), shots=shots) | |
job_result = job.result() | |
counts = job_result.get_counts(qc) | |
print(counts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
qreg = QuantumRegister(3, 'qreg') | |
creg = ClassicalRegister(3, 'creg') | |
qc = QuantumCircuit (qreg,creg) | |
#Initial state |01> | |
qc.x(qreg[1]) | |
#swap_test | |
qc.h(qreg[0]) #apply superposition on the auxiliary qubit | |
qc.cswap(qreg[0], qreg[1], qreg[2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from qiskit import * | |
from qiskit import BasicAer | |
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn import metrics | |
from qiskit import QuantumCircuit | |
from qiskit.circuit import ParameterVector | |
from qiskit.circuit.library import ZZFeatureMap | |
from qiskit.providers.aer import AerSimulator | |
from qiskit.algorithms.optimizers import SPSA | |
from qiskit_machine_learning.algorithms import QSVC | |
from qiskit_machine_learning.kernels import QuantumKernel | |
from qiskit_machine_learning.kernels.algorithms import QuantumKernelTrainer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn import metrics | |
from qiskit.circuit.library import ZZFeatureMap | |
from qiskit.providers.aer import AerSimulator | |
from qiskit_machine_learning.algorithms import QSVC | |
from qiskit_machine_learning.kernels import QuantumKernel | |
# Read data and set training and testing sets | |
input_data = read_data('flash_flood_data.csv') | |
X_train, y_train, X_test, y_test = train_test_split(input_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Initialization | |
max_trials = 3 | |
qi = QuantumInstance(Aer.get_backend('statevector_simulator'), seed_transpiler=seed, seed_simulator=seed, shots=1024) | |
rng = np.random.default_rng(seed=seed) # RNG | |
optim = SLSQP(maxiter=1000) # Init classical optimizer. | |
def trial(): | |
# Randomize initial parameters. | |
initial_point = (rng.uniform(size=len(qc.parameters)) - 1/2) * np.pi | |
NewerOlder