QuantumMinesweeper/minesweeper.py

1330 lines
31 KiB
Python
Raw Permalink Normal View History

2022-10-02 13:54:54 +03:00
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 1 16:50:14 2022
@author: mtbbk
"""
import pygame
import time
import random
import json
import math
"""
Qiskit
"""
import numpy as np
# Importing standard Qiskit libraries
from qiskit import QuantumCircuit, execute, transpile, QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer, IBMQ
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from ibm_quantum_widgets import *
def rastgele():
2022-10-02 14:59:49 +03:00
2022-10-02 13:54:54 +03:00
# Loading your IBM Quantum account(s)
print('Libraries imported successfully!')
qc = QuantumCircuit(1,1)
qc.h(0)
qc.x(0)
qc.measure(0,0)
print(qc)
backend = Aer.get_backend('qasm_simulator') # Choosing the simulator we want to use
job = execute(qc, backend, shots = 1024) # Running the simulator - specifying the circuit we want to simulate and the number of times we want to simulate it (shots)
result = job.result()
counts = result.get_counts() # Getting the counts of 0 and 1 from the result
plot_histogram(counts)
print(counts)
coundDeger = str(counts)
coundDeger = coundDeger.replace("'", " ")
coundDeger = coundDeger.replace(",", " ")
coundDeger = coundDeger.replace("}", " ")
first_word = coundDeger.split()[1]
print("Deger: ", first_word)
print(coundDeger)
xDeger = coundDeger.split()[3]
yDeger = coundDeger.split()[6]
xDegerXE = int(xDeger)
yDegerYE = int(yDeger)
valueX = random.randint(0, 512)
while True:
if valueX%32 != 0:
valueX= valueX+1
else:
break
valueY = random.randint(0, 512)
while True:
if valueY%32 != 0:
valueY= valueY+1
else:
break
xDegerX = valueX
yDegerY = valueY
Test = 54
while True:
if Test%32 != 0:
Test= Test+1
else:
break
print(Test)
print("DegerX: ", xDegerX)
print("DegerY: ", yDegerY)
type(qc)
"""
Qiskit Bitti / JSON
"""
print('\nGrovers Algorithm')
print('------------------\n')
grid_konumu = 0
brid=[[0]*16]*16
y = xDegerX
x = yDegerY
#mayin = T[x][y]
a = f"{x//4}"
b = f"{y//4}"
a_int = int(a)
b_int = int(b)
z = a_int*4 +b_int
grid_konumu = z
print(grid_konumu)
pi = math.pi
q = QuantumRegister(4,'q')
c = ClassicalRegister(4,'c')
qc = QuantumCircuit(q,c)
print('\nInitialising Circuit...\n')
### Initialisation ###
qc.h(q[0])
qc.h(q[1])
qc.h(q[2])
qc.h(q[3])
print('\nPreparing Oracle circuit....\n')
### 0000 Oracle ###
if(grid_konumu == 0):
qc.x(q[0])
qc.x(q[1])
qc.x(q[2])
qc.x(q[3])
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.x(q[0])
qc.x(q[1])
qc.x(q[2])
qc.x(q[3])
### 0001 Oracle ###
if(grid_konumu == 1):
qc.x(q[1])
qc.x(q[2])
qc.x(q[3])
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.x(q[1])
qc.x(q[2])
qc.x(q[3])
### 0010 Oracle ###
if(grid_konumu == 2):
qc.x(q[0])
qc.x(q[2])
qc.x(q[3])
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.x(q[0])
qc.x(q[2])
qc.x(q[3])
### 0011 Oracle ###
if(grid_konumu == 3):
qc.x(q[2])
qc.x(q[3])
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.x(q[2])
qc.x(q[3])
### 0100 Oracle ###
if(grid_konumu == 4):
qc.x(q[0])
qc.x(q[1])
qc.x(q[3])
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.x(q[0])
qc.x(q[1])
qc.x(q[3])
### 0101 Oracle ###
if(grid_konumu == 5):
qc.x(q[1])
qc.x(q[3])
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.x(q[1])
qc.x(q[3])
### 0110 Oracle ###
if(grid_konumu == 6):
qc.x(q[0])
qc.x(q[3])
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.x(q[0])
qc.x(q[3])
### 0111 Oracle ###
if(grid_konumu == 7):
qc.x(q[3])
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.x(q[3])
### 1000 Oracle ###
if(grid_konumu == 8):
qc.x(q[0])
qc.x(q[1])
qc.x(q[2])
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.x(q[0])
qc.x(q[1])
qc.x(q[2])
### 1001 Oracle ###
if(grid_konumu == 9):
qc.x(q[1])
qc.x(q[2])
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.x(q[1])
qc.x(q[2])
### 1010 Oracle ###
if(grid_konumu == 10):
qc.x(q[0])
qc.x(q[2])
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.x(q[0])
qc.x(q[2])
### 1011 Oracle ###
if(grid_konumu == 11):
qc.x(q[3])
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.x(q[3])
### 1100 Oracle ###
if(grid_konumu == 12):
qc.x(q[0])
qc.x(q[1])
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.x(q[0])
qc.x(q[1])
### 1101 Oracle ###
if(grid_konumu == 13):
qc.x(q[1])
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.x(q[1])
print("aaaaaaaaaaaaaaaa")
### 1110 Oracle ###
if(grid_konumu == 14):
qc.x(q[0])
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.x(q[0])
###1111 Oracle###
if(grid_konumu == 15):
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
print('\nPreparing Amplification circuit....\n')
#### Amplification ####
qc.h(q[0])
qc.h(q[1])
qc.h(q[2])
qc.h(q[3])
qc.x(q[0])
qc.x(q[1])
qc.x(q[2])
qc.x(q[3])
qc.cp(pi/4, q[0], q[3])
qc.cx(q[0], q[1])
qc.cp(-pi/4, q[1], q[3])
qc.cx(q[0], q[1])
qc.cp(pi/4, q[1], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.cx(q[1], q[2])
qc.cp(-pi/4, q[2], q[3])
qc.cx(q[0], q[2])
qc.cp(pi/4, q[2], q[3])
qc.x(q[0])
qc.x(q[1])
qc.x(q[2])
qc.x(q[3])
qc.h(q[0])
qc.h(q[1])
qc.h(q[2])
qc.h(q[3])
### Measurment ###
qc.barrier(q)
qc.measure(q[0], c[0])
qc.measure(q[1], c[1])
qc.measure(q[2], c[2])
qc.measure(q[3], c[3])
backend = Aer.get_backend('qasm_simulator')
print('\nExecuting job....\n')
job = execute(qc, backend, shots=250)
result = job.result()
counts = result.get_counts(qc)
coundDeger = str(counts)
coundDeger = coundDeger.replace("'", " ")
coundDeger = coundDeger.replace("{", " ")
coundDeger = coundDeger.replace(":", " ")
coundDeger = coundDeger.replace(",", " ")
coundDeger = coundDeger.replace("}", " ")
print(coundDeger)
grids = ["0000","0001","0010","0100","1000","0011","0101","1001","0110","1010","1100","0111","1011","1101","1110","1111"]
grids_count = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]
# Bubble sort in Python
ali=max(counts,key=lambda x:counts[x])
print(20*"-")
print(int(ali,2))
print(20*"-")
print(max(counts,key=lambda x:counts[x]))
print(20*"-")
print('RESULT: ',counts,'\n')
print('Press any key to close')
buyuk_x = x%4
buyuk_y = y%4
q1 = QuantumRegister(4,'q')
c1 = ClassicalRegister(4,'c')
qc1 = QuantumCircuit(q1,c1)
z = (buyuk_x)*4 + buyuk_y
grid_konumu = z
print(grid_konumu)
qc1.h(q1[0])
qc1.h(q1[1])
qc1.h(q1[2])
qc1.h(q1[3])
if(grid_konumu == 0):
qc1.x(q1[0])
qc1.x(q1[1])
qc1.x(q1[2])
qc1.x(q1[3])
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.x(q1[0])
qc1.x(q1[1])
qc1.x(q1[2])
qc1.x(q1[3])
### 0001 Oracle ###
if(grid_konumu == 1):
qc1.x(q1[1])
qc1.x(q1[2])
qc1.x(q1[3])
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.x(q1[1])
qc1.x(q1[2])
qc1.x(q1[3])
### 0010 Oracle ###
if(grid_konumu == 2):
print("AAAAAAAAAAAAAAAAAAAAA")
qc1.x(q1[0])
qc1.x(q1[2])
qc1.x(q1[3])
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.x(q1[0])
qc1.x(q1[2])
qc1.x(q1[3])
### 0011 Oracle ###
if(grid_konumu == 3):
qc1.x(q1[2])
qc1.x(q1[3])
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.x(q1[2])
qc1.x(q1[3])
### 0100 Oracle ###
if(grid_konumu == 4):
qc1.x(q1[0])
qc1.x(q1[1])
qc1.x(q1[3])
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.x(q1[0])
qc1.x(q1[1])
qc1.x(q1[3])
### 0101 Oracle ###
if(grid_konumu == 5):
qc1.x(q1[1])
qc1.x(q1[3])
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.x(q1[1])
qc1.x(q1[3])
### 0110 Oracle ###
if(grid_konumu == 6):
qc1.x(q1[0])
qc1.x(q1[3])
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.x(q1[0])
qc1.x(q1[3])
### 0111 Oracle ###
if(grid_konumu == 7):
qc1.x(q1[3])
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.x(q1[3])
### 1000 Oracle ###
if(grid_konumu == 8):
qc1.x(q1[0])
qc1.x(q1[1])
qc1.x(q1[2])
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.x(q1[0])
qc1.x(q1[1])
qc1.x(q1[2])
### 1001 Oracle ###
if(grid_konumu == 9):
qc1.x(q1[1])
qc1.x(q1[2])
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.x(q1[1])
qc1.x(q1[2])
### 1010 Oracle ###
if(grid_konumu == 10):
qc1.x(q1[0])
qc1.x(q1[2])
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.x(q1[0])
qc1.x(q1[2])
### 1011 Oracle ###
if(grid_konumu == 11):
qc1.x(q1[3])
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.x(q1[3])
### 1100 Oracle ###
if(grid_konumu == 12):
qc1.x(q1[0])
qc1.x(q1[1])
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.x(q1[0])
qc1.x(q1[1])
### 1101 Oracle ###
if(grid_konumu == 13):
qc1.x(q1[1])
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.x(q1[1])
print("aaaaaaaaaaaaaaaa")
### 1110 Oracle ###
if(grid_konumu == 14):
qc1.x(q1[0])
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.x(q1[0])
###1111 Oracle###
if(grid_konumu == 15):
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
print('\nPreparing Amplification circuit....\n')
#### Amplification ####
qc1.h(q1[0])
qc1.h(q1[1])
qc1.h(q1[2])
qc1.h(q1[3])
qc1.x(q1[0])
qc1.x(q1[1])
qc1.x(q1[2])
qc1.x(q1[3])
qc1.cp(pi/4, q1[0], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(-pi/4, q1[1], q1[3])
qc1.cx(q1[0], q1[1])
qc1.cp(pi/4, q1[1], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1[2], q1[3])
qc1.cx(q1[0], q1[2])
qc1.cp(pi/4, q1[2], q1[3])
qc1.cx(q1[1], q1[2])
qc1.cp(-pi/4, q1