├── I_Theta (2 X 2).py ├── Revised ├── Code │ ├── __pycache__ │ │ ├── frqi_cirq.cpython-36.pyc │ │ ├── frqi_qiskit.cpython-36.pyc │ │ └── utils.cpython-36.pyc │ ├── frqi_cirq.py │ ├── frqi_qiskit.py │ ├── main_cirq.py │ ├── main_qiskit.py │ └── utils.py ├── Coding Assignment 2.pdf ├── Coding Assignment 2.zip ├── Notes ├── __pycache__ │ ├── cirq_compare.cpython-36.pyc │ ├── compare.cpython-36.pyc │ ├── frqi_cirq.cpython-36.pyc │ ├── frqi_qiskit.cpython-36.pyc │ ├── qiskit_compare.cpython-36.pyc │ └── utils.cpython-36.pyc ├── cirq_compare.py ├── code_storage.py ├── compare.py ├── frqi_cirq.py ├── frqi_qiskit.py ├── main_cirq.py ├── main_qiskit.py ├── qiskit_compare.py └── utils.py ├── __pycache__ ├── i_theta.cpython-36.pyc ├── image_testing.cpython-36.pyc ├── main_test.cpython-36.pyc └── testing_stuff.cpython-36.pyc ├── aman_code.py ├── code_storage.py ├── i_theta.py ├── i_theta_saved.py ├── image.png ├── image_testing.py ├── images ├── 10000.png ├── 100000.png ├── 2x2_black.png ├── 2x2_w64_1-000-000-000_All_three_s4.png ├── 2x2_w64_10-000-000_RED.png ├── 2x2_w64_100-000-000_All_THREE.png ├── 2x2_w64_100-000-000_All_three_s4.png ├── 2x2_w64_100-000-000_BLACK.png ├── 2x2_w64_100-000-000_RED.png ├── 4test.png ├── 4test_16.png ├── 4test_16_WHITE.png ├── Four_1-000-000-000.png ├── Four_10-000-000.png ├── Four_100-000-000.png ├── Four_1000000.png ├── Four_5-000-000-000.png ├── Four_w16_1-000-000-000.png ├── Four_w16_1-000-000-000_changed_to_less_extreme_239_and_16.png ├── Four_w16_100-000-000.png ├── Four_w16_100-000-000_SHIFTED.png ├── Four_w16_100-000-000_changed.png ├── aman_test.png ├── ijijiijjij.png ├── test_4x4.png ├── w64_1-000-000-000.png ├── w64_1-000-000.png ├── w64_10-000-000.png ├── w64_100-000-000.png ├── w64_100-000.png ├── w64_10000.png ├── w64_5-000-000-000.png ├── w64_original.png └── ~$4_original.png ├── main4.py ├── main_test.py ├── pil_red.png ├── secondTest.md ├── test.md └── testing_stuff.py /I_Theta (2 X 2).py: -------------------------------------------------------------------------------- 1 | 2 | # coding: utf-8 3 | # In[40]: 4 | import qiskit as qk 5 | from qiskit import Aer,execute 6 | 7 | pi = 3.14 8 | 9 | def run(): 10 | qr =qk.QuantumRegister(3) 11 | cr = qk.ClassicalRegister(3) 12 | 13 | qc= qk.QuantumCircuit(qr,cr) 14 | 15 | #Creating the Hadamard State 16 | 17 | qc.h(qr[0]) 18 | qc.h(qr[1]) 19 | 20 | # Circuit for I(theta) starts here 21 | qc.x(qr[0]) 22 | qc.x(qr[1]) 23 | 24 | angles = [pi/2, 0, pi/4, pi/6] 25 | #pi/4=0.7853 26 | qc.cu3(angles[0],0,0,qr[0],qr[2]) 27 | 28 | qc.cx(qr[0],qr[1]) 29 | 30 | qc.cu3(-angles[0],0,0,qr[1],qr[2]) 31 | 32 | qc.cx(qr[0],qr[1]) 33 | 34 | qc.cu3(angles[0],0,0,qr[0],qr[2]) 35 | 36 | #pi/12=0.2617 37 | 38 | qc.x(qr[1]) 39 | 40 | qc.cu3(angles[1],0,0,qr[0],qr[2]) 41 | qc.cx(qr[0],qr[1]) 42 | qc.cu3(-angles[1],0,0,qr[1],qr[2]) 43 | qc.cx(qr[0],qr[1]) 44 | qc.cu3(angles[1],0,0,qr[0],qr[2]) 45 | 46 | #pi/6=0.5234 47 | 48 | qc.x(qr[0]) 49 | qc.x(qr[1]) 50 | 51 | qc.cu3(angles[2],0,0,qr[0],qr[2]) 52 | qc.cx(qr[0],qr[1]) 53 | qc.cu3(-angles[2],0,0,qr[1],qr[2]) 54 | qc.cx(qr[0],qr[1]) 55 | qc.cu3(angles[2],0,0,qr[0],qr[2]) 56 | 57 | #pi/16=0.1963 58 | 59 | qc.x(qr[1]) 60 | 61 | qc.cu3(angles[3],0,0,qr[0],qr[2]) 62 | qc.cx(qr[0],qr[1]) 63 | qc.cu3(-angles[3],0,0,qr[1],qr[2]) 64 | qc.cx(qr[0],qr[1]) 65 | qc.cu3(angles[3],0,0,qr[0],qr[2]) 66 | 67 | qc.barrier(qr) 68 | qc.measure(qr,cr) 69 | 70 | # In[41]: 71 | backend_sim = Aer.get_backend('qasm_simulator') 72 | job_sim = execute(qc, backend_sim) 73 | result_sim = job_sim.result() 74 | 75 | # In[42]: 76 | 77 | counts = result_sim.get_counts(qc) 78 | print(counts) -------------------------------------------------------------------------------- /Revised/Code/__pycache__/frqi_cirq.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/Revised/Code/__pycache__/frqi_cirq.cpython-36.pyc -------------------------------------------------------------------------------- /Revised/Code/__pycache__/frqi_qiskit.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/Revised/Code/__pycache__/frqi_qiskit.cpython-36.pyc -------------------------------------------------------------------------------- /Revised/Code/__pycache__/utils.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/Revised/Code/__pycache__/utils.cpython-36.pyc -------------------------------------------------------------------------------- /Revised/Code/frqi_cirq.py: -------------------------------------------------------------------------------- 1 | import cirq 2 | from cirq.ops import H, CZ, CNOT, X, RotYGate 3 | from math import pi, sqrt, acos 4 | from utils import r_num, g_num, b_num 5 | 6 | def probs(results, num_shots): 7 | 8 | # obtain all results for each qubit in each measurement 9 | a_meas = results.measurements['a'] 10 | b_meas = results.measurements['b'] 11 | c_meas = results.measurements['c'] 12 | 13 | # will store the number of times '0' and '1' are measured for each pixel 14 | measurements = {} 15 | for i in range(4): 16 | measurements[i] = [] 17 | measurements[i].append(0) 18 | measurements[i].append(0) 19 | 20 | # for each measurement that was made 21 | for i in range(num_shots): 22 | 23 | # obtain the results for each qubit in the current measurement 24 | a_res = a_meas[i][0] 25 | b_res = b_meas[i][0] 26 | c_res = c_meas[i][0] 27 | 28 | # if 'row' qubit is 0 29 | if (b_res == False): 30 | # pixel is 00 31 | if (a_res == False): 32 | # increment the measurements for the pixel for either '0' or '1' 33 | if (c_res == False): 34 | measurements[0][0] += 1 35 | else: 36 | measurements[0][1] += 1 37 | # pixel is 01 38 | else: 39 | if (c_res == False): 40 | measurements[1][0] += 1 41 | else: 42 | measurements[1][1] += 1 43 | 44 | # if 'row' qubit is 1 45 | else: 46 | # pixel is 10 47 | if (a_res == False): 48 | if (c_res == False): 49 | measurements[2][0] += 1 50 | else: 51 | measurements[2][1] += 1 52 | # pixel is 11 53 | else: 54 | if (c_res == False): 55 | measurements[3][0] += 1 56 | else: 57 | measurements[3][1] += 1 58 | 59 | # using the probability of measuring zero for each pixel, can estimate theta 60 | angles = [] 61 | for i in range(4): 62 | zero_prob = measurements[i][0]/(measurements[i][0] + measurements[i][1]) 63 | angles.append(acos(sqrt(zero_prob))) 64 | 65 | return angles 66 | 67 | # this function creates the FRQI state for the image 68 | def run(angles, num_shots): 69 | 70 | # create the qubits to be used in the circuit 71 | a = cirq.NamedQubit("a") 72 | b = cirq.NamedQubit("b") 73 | c = cirq.NamedQubit("c") 74 | 75 | # store the gates to be used when creating the circuit 76 | x = cirq.X 77 | CRy = [] 78 | NegCRy = [] 79 | # need to store a controlled Ry gate for each angle, as well as a negative angle one 80 | for ang in angles: 81 | CRy.append(cirq.ControlledGate(RotYGate(rads=ang))) 82 | NegCRy.append(cirq.ControlledGate(RotYGate(rads=-ang))) 83 | 84 | # create the circuit and add H operations to it 85 | circuit = cirq.Circuit() 86 | circuit.append(H.on(a)) 87 | circuit.append(H.on(b)) 88 | 89 | # for every angle, add to the circuit the encoding of that angle 90 | for i in range(len(angles)): 91 | 92 | # to make sure we are transforming the correct vector, need to NOT certain qubits 93 | circuit.append(x.on(a)) 94 | 95 | if(i%2 == 0): 96 | circuit.append(x.on(b)) 97 | 98 | # The C^2-Ry operation 99 | circuit.append(CRy[i].on(a, c)) 100 | circuit.append(CNOT.on(a, b)) 101 | circuit.append(NegCRy[i].on(b, c)) 102 | circuit.append(CNOT.on(a, b)) 103 | circuit.append(CRy[i].on(b, c)) 104 | 105 | # measure all of the qubits 106 | circuit.append(cirq.measure(a)) 107 | circuit.append(cirq.measure(b)) 108 | circuit.append(cirq.measure(c)) 109 | 110 | simulator = cirq.google.XmonSimulator() 111 | 112 | # run the circuit and get measurements 113 | trials = simulator.run(circuit, repetitions=num_shots) 114 | 115 | # use the measurements to recover the angles encoding the colors 116 | recovered_angles = probs(trials, num_shots) 117 | 118 | return recovered_angles -------------------------------------------------------------------------------- /Revised/Code/frqi_qiskit.py: -------------------------------------------------------------------------------- 1 | # This file contains the implementation of the FRQI algorithm in Qiskit 2 | 3 | import qiskit as qk 4 | from qiskit import Aer,execute 5 | from math import pi, sqrt, acos 6 | from utils import r_num, g_num, b_num 7 | 8 | # this function takes the results for the measurements and returns the angles it finds 9 | def probs(results, num_shots): 10 | 11 | prob = {} 12 | 13 | # create every possible basis vector and add the estimated prob of that vector being measured 14 | chars = ["0", "1"] 15 | for c in chars: 16 | for d in chars: 17 | for e in chars: 18 | state = c + d + e 19 | if (state in results): 20 | prob[state] = results[state]/num_shots 21 | else: 22 | prob[state] = 0. 23 | 24 | # using the probability of every pixel being 0, estimate the angle stored 25 | angles = [] 26 | for c in chars: 27 | for d in chars: 28 | zero = "0" + c + d 29 | one = "1" + c + d 30 | zero_prob = prob[zero]/(prob[zero] + prob[one]) 31 | # prob(|0>) = cos^2(theta), so to solve for theta need to do inverse 32 | angles.append(acos(sqrt(zero_prob))) 33 | 34 | return angles 35 | 36 | # this function creates the FRQI state for the image 37 | def run(angles, num_shots): 38 | 39 | qr = qk.QuantumRegister(3) 40 | cr = qk.ClassicalRegister(3) 41 | 42 | # create a circuit 43 | qc= qk.QuantumCircuit(qr,cr) 44 | 45 | #Creating the Hadamard State 46 | qc.h(qr[0]) 47 | qc.h(qr[1]) 48 | 49 | i = 0 50 | # for every angle, add to the circuit the encoding of that angle 51 | for ang in angles: 52 | 53 | # to make sure we are transforming the correct vector, need to NOT certain qubits 54 | qc.x(qr[0]) 55 | 56 | if(i%2 == 0): 57 | qc.x(qr[1]) 58 | 59 | # The C^2-Ry operation 60 | qc.cu3(ang,0,0,qr[0],qr[2]) 61 | qc.cx(qr[0],qr[1]) 62 | qc.cu3(-ang,0,0,qr[1],qr[2]) 63 | qc.cx(qr[0],qr[1]) 64 | qc.cu3(ang,0,0,qr[1],qr[2]) 65 | 66 | i += 1 67 | 68 | qc.barrier(qr) 69 | qc.measure(qr,cr) 70 | 71 | # run the circuit 72 | backend_sim = Aer.get_backend('qasm_simulator') 73 | job_sim = execute(qc, backend_sim, shots=num_shots) 74 | result_sim = job_sim.result() 75 | 76 | # get the dictionary that contains number of times each outcome was measured 77 | counts = result_sim.get_counts(qc) 78 | 79 | new_angles = probs(counts, num_shots) 80 | 81 | return new_angles -------------------------------------------------------------------------------- /Revised/Code/main_cirq.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import utils 3 | import frqi_cirq 4 | 5 | def main(): 6 | 7 | # if no command line argument is give, use 10,000 shots 8 | if (len(sys.argv) == 1): 9 | num_shots = 10000 10 | else: 11 | num_shots = int(sys.argv[1]) 12 | 13 | image = utils.get_image() 14 | size = len(image) 15 | 16 | angles = [] 17 | # convert all rgb pixel values into angles in [0, pi/2] 18 | for i in range(size): 19 | for j in range(size): 20 | angles.append((utils.rgb_to_theta(image[i][j]))) 21 | 22 | new_angles = frqi_cirq.run(angles, num_shots) 23 | 24 | im = [] 25 | i = 0 26 | # converting all the recovered angles, back into rgb values 27 | for ang in new_angles: 28 | 29 | rgb = utils.theta_to_rgb(ang) 30 | if (i % 2 == 0): 31 | row = [] 32 | 33 | row.append(rgb) 34 | 35 | if (i % 2 != 0): 36 | im.append(row) 37 | 38 | i += 1 39 | 40 | # make an image using the recovered RGB values 41 | new_image = utils.make_image(im) 42 | 43 | # double the size of the image 7 times, so that it is larger enough to actually see what the colors are 44 | for i in range(7): 45 | new_image = utils.double_size(new_image) 46 | 47 | utils.show_image(new_image) 48 | 49 | 50 | if __name__ == "__main__": 51 | main() -------------------------------------------------------------------------------- /Revised/Code/main_qiskit.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import utils 3 | import frqi_qiskit 4 | 5 | def main(): 6 | 7 | # if no command line argument is give, use 10,000 shots 8 | if (len(sys.argv) == 1): 9 | num_shots = 10000 10 | else: 11 | num_shots = int(sys.argv[1]) 12 | 13 | image = utils.get_image() 14 | size = len(image) 15 | 16 | angles = [] 17 | # convert all rgb pixel values into angles in [0, pi/2] 18 | for i in range(size): 19 | for j in range(size): 20 | angles.append((utils.rgb_to_theta(image[i][j]))) 21 | 22 | new_angles = frqi_qiskit.run(angles, num_shots) 23 | 24 | im = [] 25 | i = 0 26 | # converting all the recovered angles, back into rgb values 27 | for ang in new_angles: 28 | 29 | rgb = utils.theta_to_rgb(ang) 30 | if (i % 2 == 0): 31 | row = [] 32 | 33 | row.append(rgb) 34 | 35 | if (i % 2 != 0): 36 | im.append(row) 37 | 38 | i += 1 39 | 40 | # make an image using the recovered RGB values 41 | new_image = utils.make_image(im) 42 | 43 | # double the size of the image 7 times, so that it is larger enough to actually see what the colors are 44 | for i in range(7): 45 | new_image = utils.double_size(new_image) 46 | 47 | utils.show_image(new_image) 48 | 49 | 50 | if __name__ == "__main__": 51 | main() -------------------------------------------------------------------------------- /Revised/Code/utils.py: -------------------------------------------------------------------------------- 1 | # This file contains functions which have to do with manipulating RGB images 2 | from PIL import Image 3 | import numpy as np 4 | from math import pi, floor 5 | 6 | # the number of possible RGB values used (default would be 256) 7 | r_num = 16 8 | g_num = r_num ** 2 9 | b_num = r_num ** 3 10 | 11 | # this function doubles the size of an image with 4 colors, because a 2x2 pixel image is very small 12 | def double_size(im): 13 | 14 | rows = len(im) 15 | cols = len(im[0]) 16 | 17 | new_im = np.zeros(((rows * 2, cols * 2, 3))) 18 | 19 | r = im[0] 20 | first = r[0] 21 | second = r[int(cols/2)] 22 | 23 | for i in range(rows): 24 | for j in range(cols): 25 | for k in range(3): 26 | new_im[i][j][k] = first[k] 27 | for j in range(cols, cols * 2): 28 | for k in range(3): 29 | new_im[i][j][k] = second[k] 30 | 31 | r = im[int(rows/2)] 32 | first = r[0] 33 | second = r[int(cols/2)] 34 | 35 | for i in range(rows, rows * 2): 36 | for j in range(cols): 37 | for k in range(3): 38 | new_im[i][j][k] = first[k] 39 | for j in range(cols, cols * 2): 40 | for k in range(3): 41 | new_im[i][j][k] = second[k] 42 | 43 | return new_im 44 | 45 | # given an rgb image as a regular python list, converts it into a numpy array image 46 | def make_image(rgbs): 47 | 48 | rows = len(rgbs) 49 | cols = len(rgbs[0]) 50 | 51 | new_im = np.zeros(((rows, cols, 3))) 52 | 53 | # convert to numpy array and scale the image back up 54 | for i in range(rows): 55 | for j in range(cols): 56 | for k in range(3): 57 | new_im[i][j][k] = rgbs[i][j][k] 58 | 59 | new_im = scale_up(new_im) 60 | 61 | return new_im 62 | 63 | # This function displays an image and saves it to the current directory 64 | def show_image(pixels): 65 | 66 | # Create a PIL image from the NumPy array 67 | image = Image.fromarray(pixels.astype('uint8'), 'RGB') 68 | 69 | image.show() 70 | 71 | # This function takes an image as a list of RGB values and converts it to a numpy array of RGB values and scales up the values 72 | def scale_up(image): 73 | 74 | rows = len(image) 75 | cols = len(image[0]) 76 | scale = 256/r_num 77 | new_im = np.zeros(((rows, cols, 3))) 78 | 79 | for i in range(rows): 80 | for j in range(rows): 81 | for k in range(3): 82 | new_im[i][j][k] = image[i][j][k] * scale 83 | 84 | return new_im 85 | 86 | # this function takes an RGB triplet and converts it to an angle in [0, pi/2] 87 | def rgb_to_theta(rgb): 88 | 89 | r, g, b = rgb 90 | theta = (pi/2) * ((r/r_num) + (g/g_num) + (b/b_num)) 91 | return theta 92 | 93 | # this function takes an angle and converts it to an RGB triplett 94 | def theta_to_rgb(theta): 95 | 96 | r = floor(theta/(pi/(r_num * 2))) 97 | theta = theta - r*(pi/(r_num * 2)) 98 | 99 | g = floor(theta/(pi/(g_num * 2))) 100 | theta = theta - g*(pi/(g_num * 2)) 101 | 102 | b = floor(theta/(pi/(b_num * 2))) 103 | 104 | return [r,g,b] 105 | 106 | # this function has the image which will be stored and recovered 107 | def get_image(): 108 | 109 | pixels = np.array([[[17, 17, 17], [240, 17, 17]], [[17, 240, 17], [17, 17, 240]]]) 110 | scale = 256/r_num 111 | 112 | for i in range(2): 113 | for j in range(2): 114 | for k in range(3): 115 | pixels[i][j][k] = floor(pixels[i][j][k] / scale) 116 | 117 | return pixels -------------------------------------------------------------------------------- /Revised/Coding Assignment 2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/Revised/Coding Assignment 2.pdf -------------------------------------------------------------------------------- /Revised/Coding Assignment 2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/Revised/Coding Assignment 2.zip -------------------------------------------------------------------------------- /Revised/Notes: -------------------------------------------------------------------------------- 1 | Notes for Coding Assignment 2: 2 | 3 | ---OK, so need to make a note that I changed one of the languages to Qiskit. 4 | 5 | -I was thinking about doing an 8x8 implementation instead, but I realized that if i do it with the ancilla qubits, it's not really the same algorithm. I mean the algorithm is supposed to use 2n + 1 qubits, but this one uses 2n + ancilla + 1 qubits. Also, I don't think doing that would really increase the number of things I could talk about regarding the coding or anything, since it would still be using the same gates and stuff. So fuck it, I'm doing a 2x2 implementation. Plus, the algorithm does also include the probability stuff, so there is more to it than just storing the image. I also kinda feel like I'd be betraying Aman if I did a different one. I think as long as I can draw enough comparisons between Qiskit and Cirq, it will be ok. 6 | -Things to compare: 7 | -Documentation 8 | -Speed 9 | -Ease of use 10 | -Any special features for either one 11 | 12 | -Qiskit requires a "classical register" 13 | -Nevermind, there totally is one. When you call Simulator.run(circuit, repetitions=10000) 14 | -In Cirq I was making new names for the gates, but in qiskit, that wasn't really necessary. The fact that Qiskit does not have specific rotation gates, but cirq does. Pretty surprising. See if this can be done in qiskit, actually. 15 | -I guess ultimately I can say which one I thought was better. 16 | -The fact that I was able to name the qubits maybe made it easier to reference them. 17 | -Cirq documentation: https://cirq.readthedocs.io/en/latest/_modules/cirq/google/xmon_gates.html 18 | -"does not exist yet" 19 | -Printed the circuit and it looks right. I guess you can actually do this in both. 20 | -Which one seems more accurate? 21 | 22 | -Also don't forget to comment the code. 23 | -Whoa, what if I used a T-test to compare the speed and accuracies. 24 | 25 | for i in range(100000000, 1000000001, 100000000): 26 | 27 | ======================================= 28 | 29 | -The algorithm 30 | 31 | -The algorithm I have implemented is for transforming qubits from the 0 state to the FRQI state, which stores an RGB image. Once the image has been stored the state is measure some large number of times to attempt to recover the RGB values in the image. There are three main phases for the algorithm. The first phase involves converting an array of RGB triplets, which represent an image, into angles in [0, pi/2]. Each of these angles is then sent to a function which uses two operations to store these angles in a quantum state, keeping track of which angle represents a color in which pixel of the image. The algorithm starts with 2n + 1 qubits in the |0> state. The first operation applies hadamard gates to 2n of the qubits, leaving one of them in the |0> state. The second operation is a succession of rotations about the y axis by 2 theta, controlled by 2n qubits. The C^2n operations are broken down into CNOT and cotrolled y-rotation gates, to accomplish rotating by 2theta only the basis vector corresponding to the pixel whose color is being encoded in the state. Once all the colors have been encoded in this fashion, the state is final. The third phase of the algorithm is recovery of the image. This is accomplished by first measure the state some number of times, which is determined by the user with more measurements leading to more accurate recovery of the image. Following these measurements, the probability of measure the |0> state for each pixel is estimated and in this way the value of theta corresponding to each pixel is recovered. Then the angles can be converted back into an array of RGB triplets, and the the full image is recovered. 32 | 33 | The quantum languages used to code this algorithm were Qiskit and Google Cirq. There were similarities in implementing with these two languages in certain respects and some noticable differences as well. 34 | 35 | -Language Comparison 36 | 37 | -Documentation 38 | 39 | -Qiskits documentation seemed pretty good, especially the beginner stuff. There was also much more discussion about how to do things by others, which was very helpful. 40 | -The tutorials were nice for beginner users. 41 | 42 | -Cirq has a fairly large documentation pdf which was helpful for certain things, but not so much for other things. There was not as much discussion about how to do things in the language as for Qiskit. It took a long time for me to find out how to conrtol a gate with Cirq. It was especially difficult to find out how to make use of a controlled rotation gate, which is the main reason we did not use Cirq to code the algorithm for the project. Eventually I did find a site where people were discussing how to do it, which was helpful. 43 | -There was a time when I doc which was supposed to discuss the use of xmon gates, which I thought would be very useful, but when I clicked the link it just had a text art image of someone walking down a hallway, and it said "Sorry, does not exist yet", which I found fitting for Cirq. 44 | -I also had a tough time finding out how to make multiple measurements on a circuit with Cirq. Instead I started by literally creating a for loop to run the entire circuit a number of times in order to get the number of measurements I needed. As you may imagine this took a very long time. Eventually I did find out how to do it by specifying the number of "repetitions" in the running of a circuit. (( this is kinda my fault, though. I mean it does say that in the Documentation. Although it doesn't in the tutorial I think. Nevermind yeah it does. Just take this out. )) 45 | -Cirq does have a tutorial, but it is much more technical than I feel a beginning tutorial should be. It describes "variational quantum algorithms", "wave functions", and preparing an "ansatz state". I found this confusing and in strict contrast to the tutorial for qiskit which included a "Hello World" section for quantum programming. 46 | 47 | -Cirq documentation doesn't have as many examples. 48 | 49 | ===================================== 50 | 51 | When learning to use a new language it is very important to have good documentation and be able to look at examples of using the language. I found Qiskits documentation very helpful, and there was a lot of discussion online about how to use different aspects of Qiskit. The documentation for Cirq was helpful for a few things, but was lacking in many others. For example, there was a section in the documentation about gates, but there was no gate given for a controlled rotation gates. After searching for a while, I did find a place where users were discussing controlled gates and I found out that there was function which would control any gate, which is what I used. Tutorials are also very useful when using a new language. While Cirq does have a tutorial, I found it much more technical than a beginning tutorial should be. It describes "variational quantum algorithms", "wave functions", and preparing an "ansatz state". I found this confusing and in strict contrast to the tutorial for qiskit which included a "Hello World" section for quantum programming. 52 | 53 | -Ease of use 54 | 55 | -In implementing the algorithm there were three main aspects where Qiskit and Cirq differed: the instantiation of the qubits, the creation of the circuit and the format of the results of running the circuit. In Qiskit the qubits are created as a group in a quantum register, with each one being referred to by an index in the register. This was fairly straight forward, but when printing the results of a measurement the indices for the qubits were the reverse of what I was expecting. The index 0 referred to the rightmost qubit, which I suppose makes sense in a binary counter sense of the qubits. When I first started using Cirq I used the "GridQubit" style of creating a lattice of qubits and referring to them by the location in the lattice. I then found out that you can use them individually and give each qubit its own name. I liked this because I could easily keep track of which qubit I was manipulating and measuring at different times in the algorithm. I realize there are advantages to using GridQubit, but since I am new to quantum programming I felt it was most important that the code was clear and readable. 56 | 57 | In creating the quantum circuit the main difference I found between Qiskit and Cirq was use of controlled gates. For qiskit there is not a controlled y rotation gate, but there is a general controlled rotation gate. Using this gate and setting the phi and lambda arguments to 0, turned this gate into a controlled y rotation gate. Once I figured this out, it went smoothly. To get the controlled y rotation using Cirq, I simply wrapped the Y rotation gate in "cirq.controlledGate()". This was very flexible and I could simply store this controlled gate in a variable and use it even more easily later on. To further simplify the process I created lists of controlled y rotations for each angle and the reverse rotation of this angle all at once before adding them to the circuit. This way I could just refer to the index in these lists corresponding to the pixel position, which I think makes the code more readable. This style of getting controlled gates is simple and intuitive, which could help on future programs as well. 58 | 59 | When running the circuit Qiskit and Cirq are very similar, in that you can simply run the circuit and pass the number of "shots" or "repetitions" to the simulator. Where they differ is in how they format the results of running the circuit. Quskit returns a very simple dictionary in which the keys are the basis vectors (stored as a string) and the values are the number of times the vector was the output. In order to use these results in the algorithm I cycled through every possible outcome and extracted the number of measurements from the dictionary. In Cirq the results of running the circuit are formed into a dictionary in which there is a key for each individual qubit. The values are a list, where each element is a list of one element which is either "False" if the measurement for the qubit was 0 or "True" if the measurement was 1. I'm not sure why the individual measurements are in a list when there is only one element, but once I figured that out it was not difficult to deal with. To use the results given in this fashion I cycled through the lists for each qubit together, one measurement at a time to put together what the total outcome of each measurement was. This was one point for Qiskit I think because it was much easier to interpret the results of a group of measurements simpy by printing the output. 60 | 61 | 62 | 63 | 64 | -Speed and Accuracy 65 | -The accuracies seem comparable 66 | -As for speed, cirq seems slower than qiskit. This could be because of differences in my implementations but I do think its worth noting that qiskit did perform better every time. 67 | 68 | The speed and Accuracy testing for the actual quantum part (Cirq is still slower than Qiskit) 69 | 70 | qiskit 71 | cirq 72 | Avg time for cirq: 2.788823199272156 73 | Avg error for cirq: 0.0012096051214900503 74 | Avg time for qiskit: 0.5313672542572021 75 | Avg error for qiskit: 0.0013801986995863886 76 | Time stats: 77 | Ttest_indResult(statistic=4.57080726165037, pvalue=0.00023698886891334233) 78 | Error stats: 79 | Ttest_indResult(statistic=-0.6409023627369154, pvalue=0.5296621615654747) 80 | 81 | (py36) C:\Users\mhard\CMSC657\Project\Revised>the one above is when I started doing a better comparison 82 | 'the' is not recognized as an internal or external command, 83 | operable program or batch file. 84 | 85 | (py36) C:\Users\mhard\CMSC657\Project\Revised> 86 | (py36) C:\Users\mhard\CMSC657\Project\Revised> 87 | (py36) C:\Users\mhard\CMSC657\Project\Revised> 88 | (py36) C:\Users\mhard\CMSC657\Project\Revised>the one above is when I started doing a better comparison 89 | 'the' is not recognized as an internal or external command, 90 | operable program or batch file. 91 | 92 | (py36) C:\Users\mhard\CMSC657\Project\Revised>python compare.py 93 | qiskit 94 | cirq 95 | Avg time for cirq: 2.7580758810043333 96 | Avg error for cirq: 0.0013158407868343008 97 | Avg time for qiskit: 1.336278462409973 98 | Avg error for qiskit: 0.0012654051705504304 99 | Time stats: 100 | Ttest_indResult(statistic=1.458062074018002, pvalue=0.16205125539602744) 101 | Error stats: 102 | Ttest_indResult(statistic=0.14956078652540647, pvalue=0.8827741696368566) 103 | 104 | (py36) C:\Users\mhard\CMSC657\Project\Revised>python compare.py 105 | qiskit 106 | cirq 107 | Avg time for cirq: 2.4988972425460814 108 | Avg error for cirq: 0.0009641585374690467 109 | Avg time for qiskit: 1.5672604084014892 110 | Avg error for qiskit: 0.001481082855979526 111 | Time stats: 112 | Ttest_indResult(statistic=0.8206730296698455, pvalue=0.4225685199490363) 113 | Error stats: 114 | Ttest_indResult(statistic=-1.1475513864588163, pvalue=0.26617798962014894) 115 | 116 | (py36) C:\Users\mhard\CMSC657\Project\Revised>python compare.py 117 | cirq 118 | qiskit 119 | Avg time for cirq: 2.4674896478652952 120 | Avg error for cirq: 0.001225896691997191 121 | Avg time for qiskit: 1.8195255756378175 122 | Avg error for qiskit: 0.0014718699853990534 123 | Time stats: 124 | Ttest_indResult(statistic=0.5279401974095984, pvalue=0.60398897442193) 125 | Error stats: 126 | Ttest_indResult(statistic=-0.6125271743053186, pvalue=0.5478500546101828) 127 | 128 | (py36) C:\Users\mhard\CMSC657\Project\Revised>python main_qiskit.py 129 | [0.10469418877319502, 1.4791409747187294, 0.19059711289479092, 0.11006312153079476] 130 | qiskit._schema_validation._SummaryValidationError: "Original message too long to be useful: {'qobj_id': '9f5f3ad2-eab6-46e4-8dcc-cd926d5df597', 'config': {'shots': [10, 0], 'memory_slots': 3, 'max_credits': 10, 'n_qubits': 3}, 'experiments': [{'instructions': [{'name': 'u1', 'params': [0.0], 'texparams': ['0'], 'qubits': [2]}, {'name': 'h', 'params': [], 'texparams': [], 'qubits': [1]}, {'name': 'x', 'params': [], 'texparams': [], 'qubits': [1]}, {'name': 'h', 'params': [], 'texparams': [], 'qubits': [0]}, {'name': 'x', 'params': [], 'texparams': [], 'qubits': [0]}, {'name': 'cx', 'params': [], 'texparams': [], 'qubits': [0, 2]}, {'name': 'u3', 'params': [-0.05234709438659751, 0.0, 0.0], 'texparams': ['-0.0523470943865975', '0', '0'], 'qubits': [2]}, {'name': 'cx', 'params': [], 'texparams': [], 'qubits': [0, 2]}, {'name': 'cx', 'params': [], 'texparams': [], 'qubits': [0, 1]}, {'name': 'u3', 'params': [0.05234709438659751, 0.0, 0.0], 'texparams': ['0.0523470943865975', '0', '0'], 'qubits': [2]}, {'name': 'u1', 'params': [0.0], 'texparams': ['0'], 'qubits': [2]}, {'name': 'cx[...]" 131 | 132 | The above exception was the direct cause of the following exception: 133 | 134 | Traceback (most recent call last): 135 | File "main_qiskit.py", line 52, in 136 | main() 137 | File "main_qiskit.py", line 23, in main 138 | new_angles = frqi_qiskit.run(angles, num_shots) 139 | File "C:\Users\mhard\CMSC657\Project\Revised\frqi_qiskit.py", line 73, in run 140 | job_sim = execute(qc, backend_sim, shots=num_shots) 141 | File "C:\Users\mhard\Anaconda2\envs\py36\lib\site-packages\qiskit\wrapper\_wrapper.py", line 322, in execute 142 | return backend.run(qobj) 143 | File "C:\Users\mhard\Anaconda2\envs\py36\lib\site-packages\qiskit\backends\aer\qasm_simulator.py", line 81, in run 144 | aer_job.submit() 145 | File "C:\Users\mhard\Anaconda2\envs\py36\lib\site-packages\qiskit\backends\aer\aerjob.py", line 71, in submit 146 | validate_qobj_against_schema(self._qobj) 147 | File "C:\Users\mhard\Anaconda2\envs\py36\lib\site-packages\qiskit\qobj\_validation.py", line 22, in validate_qobj_against_schema 148 | err_msg='Qobj failed validation. ' 149 | File "C:\Users\mhard\Anaconda2\envs\py36\lib\site-packages\qiskit\_schema_validation.py", line 148, in validate_json_against_schema 150 | raise newerr 151 | qiskit._schema_validation.SchemaValidationError: 'Qobj failed validation. Set Qiskit log level to DEBUG for further information.' 152 | 153 | (py36) C:\Users\mhard\CMSC657\Project\Revised>python compare.py 154 | cirq 155 | Traceback (most recent call last): 156 | File "compare.py", line 35, in 157 | time, acc = cirq_compare.run(i) 158 | File "C:\Users\mhard\CMSC657\Project\Revised\cirq_compare.py", line 28, in run 159 | new_angles, totalTime = frqi_cirq.run(angles, num_shots) 160 | File "C:\Users\mhard\CMSC657\Project\Revised\frqi_cirq.py", line 118, in run 161 | return recovered_angles, totalTime 162 | NameError: name 'totalTime' is not defined 163 | 164 | (py36) C:\Users\mhard\CMSC657\Project\Revised>python main_qiskit.py 165 | [0.10469418877319502, 1.4791409747187294, 0.19059711289479092, 0.11006312153079476] 166 | [0.13021643921252826, 1.4659460808532305, 0.17500429888094965, 0.11254649911795324] 167 | 168 | (py36) C:\Users\mhard\CMSC657\Project\Revised>python main_qiskit.py 100000 169 | [0.10469418877319502, 1.4791409747187294, 0.19059711289479092, 0.11006312153079476] 170 | [0.10288619003997611, 1.4835841186685508, 0.18690417961683248, 0.10830765026256593] 171 | 172 | (py36) C:\Users\mhard\CMSC657\Project\Revised>python main_qiskit.py 1000000 173 | [0.10469418877319502, 1.4791409747187294, 0.19059711289479092, 0.11006312153079476] 174 | [0.10444952960766295, 1.4791764089176778, 0.1902670019601433, 0.10993295676424605] 175 | 176 | (py36) C:\Users\mhard\CMSC657\Project\Revised>python main_cirq.py 10000 177 | [0.10469418877319502, 1.4791409747187294, 0.19059711289479092, 0.11006312153079476] 178 | Traceback (most recent call last): 179 | File "main_cirq.py", line 52, in 180 | main() 181 | File "main_cirq.py", line 23, in main 182 | new_angles = frqi_cirq.run(angles, num_shots) 183 | File "C:\Users\mhard\CMSC657\Project\Revised\frqi_cirq.py", line 118, in run 184 | return recovered_angles, totalTime 185 | NameError: name 'totalTime' is not defined 186 | 187 | (py36) C:\Users\mhard\CMSC657\Project\Revised>python main_cirq.py 10000 188 | [0.10469418877319502, 1.4791409747187294, 0.19059711289479092, 0.11006312153079476] 189 | [0.09472454822106749, 1.4639277080673878, 0.1922057747052489, 0.10156854368412471] 190 | 191 | (py36) C:\Users\mhard\CMSC657\Project\Revised>python main_cirq.py 100000 192 | [0.10469418877319502, 1.4791409747187294, 0.19059711289479092, 0.11006312153079476] 193 | [0.10150579939000505, 1.4821660064953868, 0.18562386056685273, 0.10961302079062096] 194 | 195 | (py36) C:\Users\mhard\CMSC657\Project\Revised>python main_cirq.py 1000000 196 | [0.10469418877319502, 1.4791409747187294, 0.19059711289479092, 0.11006312153079476] 197 | [0.10447746019075692, 1.4796680572619905, 0.1925817312903354, 0.11015897383598258] 198 | 199 | (py36) C:\Users\mhard\CMSC657\Project\Revised>python main_cirq.py 10000000 200 | [0.10469418877319502, 1.4791409747187294, 0.19059711289479092, 0.11006312153079476] 201 | [0.10461359907312502, 1.4793341450124233, 0.19064313144996278, 0.10987572162224345] -------------------------------------------------------------------------------- /Revised/__pycache__/cirq_compare.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/Revised/__pycache__/cirq_compare.cpython-36.pyc -------------------------------------------------------------------------------- /Revised/__pycache__/compare.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/Revised/__pycache__/compare.cpython-36.pyc -------------------------------------------------------------------------------- /Revised/__pycache__/frqi_cirq.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/Revised/__pycache__/frqi_cirq.cpython-36.pyc -------------------------------------------------------------------------------- /Revised/__pycache__/frqi_qiskit.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/Revised/__pycache__/frqi_qiskit.cpython-36.pyc -------------------------------------------------------------------------------- /Revised/__pycache__/qiskit_compare.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/Revised/__pycache__/qiskit_compare.cpython-36.pyc -------------------------------------------------------------------------------- /Revised/__pycache__/utils.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/Revised/__pycache__/utils.cpython-36.pyc -------------------------------------------------------------------------------- /Revised/cirq_compare.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import utils 3 | import frqi_cirq 4 | import time 5 | 6 | # return the average difference between the entries in two lists 7 | def avg_diff(list1, list2): 8 | 9 | size = len(list1) 10 | 11 | sum = 0 12 | for i in range(size): 13 | sum += abs(list1[i] - list2[i]) 14 | 15 | return sum/size 16 | 17 | def run(num_shots): 18 | 19 | image = utils.get_image() 20 | size = len(image) 21 | 22 | angles = [] 23 | # convert all rgb pixel values into angles in [0, pi/2] 24 | for i in range(size): 25 | for j in range(size): 26 | angles.append((utils.rgb_to_theta(image[i][j]))) 27 | 28 | new_angles, totalTime = frqi_cirq.run(angles, num_shots) 29 | 30 | diff = avg_diff(angles, new_angles) 31 | 32 | return totalTime, diff -------------------------------------------------------------------------------- /Revised/code_storage.py: -------------------------------------------------------------------------------- 1 | def print_results(results, num_shots): 2 | 3 | a_meas = results.measurements['a'] 4 | b_meas = results.measurements['b'] 5 | c_meas = results.measurements['c'] 6 | 7 | res = {} 8 | 9 | for i in range(num_shots): 10 | 11 | str = "" 12 | if (c_meas[i][0] == False): 13 | str += '0' 14 | else: 15 | str += '1' 16 | 17 | if (b_meas[i][0] == False): 18 | str += '0' 19 | else: 20 | str += '1' 21 | 22 | if (a_meas[i][0] == False): 23 | str += '0' 24 | else: 25 | str += '1' 26 | 27 | if(str not in res): 28 | res[str] = 1 29 | else: 30 | res[str] += 1 31 | 32 | print(res) -------------------------------------------------------------------------------- /Revised/compare.py: -------------------------------------------------------------------------------- 1 | import cirq_compare 2 | import qiskit_compare 3 | from scipy import stats 4 | import numpy as np 5 | import time 6 | 7 | def avg(list): 8 | 9 | size = len(list) 10 | 11 | sum = list[0] 12 | for i in range(1, len(list)): 13 | sum += list[i] 14 | 15 | return sum/size 16 | 17 | def convert(list): 18 | 19 | array = np.zeros(len(list)) 20 | i = 0 21 | for x in list: 22 | array[i] = x 23 | i += 1 24 | 25 | return array 26 | 27 | if __name__ == "__main__": 28 | 29 | cirq_times = [] 30 | cirq_accs = [] 31 | 32 | print("cirq") 33 | for i in range(100000, 1000001, 100000): 34 | 35 | time, acc = cirq_compare.run(i) 36 | 37 | cirq_times.append(time) 38 | cirq_accs.append(acc) 39 | 40 | qiskit_times = [] 41 | qiskit_accs = [] 42 | 43 | print("qiskit") 44 | for i in range(100000, 1000001, 100000): 45 | 46 | time, acc = qiskit_compare.run(i) 47 | 48 | qiskit_times.append(time) 49 | qiskit_accs.append(acc) 50 | 51 | print("Avg time for cirq: ", avg(cirq_times)) 52 | print("Avg error for cirq: ", avg(cirq_accs)) 53 | print("Avg time for qiskit: ", avg(qiskit_times)) 54 | print("Avg error for qiskit: ", avg(qiskit_accs)) 55 | 56 | cirq_time_array = convert(cirq_times) 57 | cirq_accs_array = convert(cirq_accs) 58 | qiskit_time_array = convert(qiskit_times) 59 | qiskit_accs_array = convert(qiskit_accs) 60 | 61 | print("Time stats:") 62 | print(stats.ttest_ind(cirq_time_array, qiskit_time_array)) 63 | 64 | print("Error stats:") 65 | print(stats.ttest_ind(cirq_accs_array, qiskit_accs_array)) 66 | -------------------------------------------------------------------------------- /Revised/frqi_cirq.py: -------------------------------------------------------------------------------- 1 | import cirq 2 | from cirq.ops import H, CZ, CNOT, X, RotYGate 3 | from math import pi, sqrt, acos 4 | from utils import r_num, g_num, b_num 5 | 6 | def probs(results, num_shots): 7 | 8 | # obtain all results for each qubit in each measurement 9 | a_meas = results.measurements['a'] 10 | b_meas = results.measurements['b'] 11 | c_meas = results.measurements['c'] 12 | 13 | # will store the number of times '0' and '1' are measured for each pixel 14 | measurements = {} 15 | for i in range(4): 16 | measurements[i] = [] 17 | measurements[i].append(0) 18 | measurements[i].append(0) 19 | 20 | # for each measurement that was made 21 | for i in range(num_shots): 22 | 23 | # obtain the results for each qubit in the current measurement 24 | a_res = a_meas[i][0] 25 | b_res = b_meas[i][0] 26 | c_res = c_meas[i][0] 27 | 28 | # if 'row' qubit is 0 29 | if (b_res == False): 30 | # pixel is 00 31 | if (a_res == False): 32 | # increment the measurements for the pixel for either '0' or '1' 33 | if (c_res == False): 34 | measurements[0][0] += 1 35 | else: 36 | measurements[0][1] += 1 37 | # pixel is 01 38 | else: 39 | if (c_res == False): 40 | measurements[1][0] += 1 41 | else: 42 | measurements[1][1] += 1 43 | 44 | # if 'row' qubit is 1 45 | else: 46 | # pixel is 10 47 | if (a_res == False): 48 | if (c_res == False): 49 | measurements[2][0] += 1 50 | else: 51 | measurements[2][1] += 1 52 | # pixel is 11 53 | else: 54 | if (c_res == False): 55 | measurements[3][0] += 1 56 | else: 57 | measurements[3][1] += 1 58 | 59 | # using the probability of measuring zero for each pixel, can estimate theta 60 | angles = [] 61 | for i in range(4): 62 | zero_prob = measurements[i][0]/(measurements[i][0] + measurements[i][1]) 63 | angles.append(acos(sqrt(zero_prob))) 64 | 65 | return angles 66 | 67 | # this function creates the FRQI state for the image 68 | def run(angles, num_shots): 69 | 70 | # create the qubits to be used in the circuit 71 | a = cirq.NamedQubit("a") 72 | b = cirq.NamedQubit("b") 73 | c = cirq.NamedQubit("c") 74 | 75 | # store the gates to be used when creating the circuit 76 | x = cirq.X 77 | CRy = [] 78 | NegCRy = [] 79 | # need to store a controlled Ry gate for each angle, as well as a negative angle one 80 | for ang in angles: 81 | CRy.append(cirq.ControlledGate(RotYGate(rads=ang))) 82 | NegCRy.append(cirq.ControlledGate(RotYGate(rads=-ang))) 83 | 84 | # create the circuit and add H operations to it 85 | circuit = cirq.Circuit() 86 | circuit.append(H.on(a)) 87 | circuit.append(H.on(b)) 88 | 89 | # for every angle, add to the circuit the encoding of that angle 90 | for i in range(len(angles)): 91 | 92 | # to make sure we are transforming the correct vector, need to NOT certain qubits 93 | circuit.append(x.on(a)) 94 | 95 | if(i%2 == 0): 96 | circuit.append(x.on(b)) 97 | 98 | # The C^2-Ry operation 99 | circuit.append(CRy[i].on(a, c)) 100 | circuit.append(CNOT.on(a, b)) 101 | circuit.append(NegCRy[i].on(b, c)) 102 | circuit.append(CNOT.on(a, b)) 103 | circuit.append(CRy[i].on(b, c)) 104 | 105 | # measure all of the qubits 106 | circuit.append(cirq.measure(a)) 107 | circuit.append(cirq.measure(b)) 108 | circuit.append(cirq.measure(c)) 109 | 110 | simulator = cirq.google.XmonSimulator() 111 | 112 | # run the circuit and get measurements 113 | trials = simulator.run(circuit, repetitions=num_shots) 114 | 115 | # use the measurements to recover the angles encoding the colors 116 | recovered_angles = probs(trials, num_shots) 117 | 118 | return recovered_angles -------------------------------------------------------------------------------- /Revised/frqi_qiskit.py: -------------------------------------------------------------------------------- 1 | # This file contains the implementation of the FRQI algorithm in Qiskit 2 | 3 | import qiskit as qk 4 | from qiskit import Aer,execute 5 | from math import pi, sqrt, acos 6 | from utils import r_num, g_num, b_num 7 | 8 | # this function takes the results for the measurements and returns the angles it finds 9 | def probs(results, num_shots): 10 | 11 | prob = {} 12 | 13 | # create every possible basis vector and add the estimated prob of that vector being measured 14 | chars = ["0", "1"] 15 | for c in chars: 16 | for d in chars: 17 | for e in chars: 18 | state = c + d + e 19 | if (state in results): 20 | prob[state] = results[state]/num_shots 21 | else: 22 | prob[state] = 0. 23 | 24 | # using the probability of every pixel being 0, estimate the angle stored 25 | angles = [] 26 | for c in chars: 27 | for d in chars: 28 | zero = "0" + c + d 29 | one = "1" + c + d 30 | zero_prob = prob[zero]/(prob[zero] + prob[one]) 31 | # prob(|0>) = cos^2(theta), so to solve for theta need to do inverse 32 | angles.append(acos(sqrt(zero_prob))) 33 | 34 | return angles 35 | 36 | # this function creates the FRQI state for the image 37 | def run(angles, num_shots): 38 | 39 | qr = qk.QuantumRegister(3) 40 | cr = qk.ClassicalRegister(3) 41 | 42 | # create a circuit 43 | qc= qk.QuantumCircuit(qr,cr) 44 | 45 | #Creating the Hadamard State 46 | qc.h(qr[0]) 47 | qc.h(qr[1]) 48 | 49 | i = 0 50 | # for every angle, add to the circuit the encoding of that angle 51 | for ang in angles: 52 | 53 | # to make sure we are transforming the correct vector, need to NOT certain qubits 54 | qc.x(qr[0]) 55 | 56 | if(i%2 == 0): 57 | qc.x(qr[1]) 58 | 59 | # The C^2-Ry operation 60 | qc.cu3(ang,0,0,qr[0],qr[2]) 61 | qc.cx(qr[0],qr[1]) 62 | qc.cu3(-ang,0,0,qr[1],qr[2]) 63 | qc.cx(qr[0],qr[1]) 64 | qc.cu3(ang,0,0,qr[1],qr[2]) 65 | 66 | i += 1 67 | 68 | qc.barrier(qr) 69 | qc.measure(qr,cr) 70 | 71 | # run the circuit 72 | backend_sim = Aer.get_backend('qasm_simulator') 73 | job_sim = execute(qc, backend_sim, shots=num_shots) 74 | result_sim = job_sim.result() 75 | 76 | # get the dictionary that contains number of times each outcome was measured 77 | counts = result_sim.get_counts(qc) 78 | 79 | new_angles = probs(counts, num_shots) 80 | 81 | return new_angles -------------------------------------------------------------------------------- /Revised/main_cirq.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import utils 3 | import frqi_cirq 4 | 5 | def main(): 6 | 7 | # if no command line argument is give, use 10,000 shots 8 | if (len(sys.argv) == 1): 9 | num_shots = 10,000 10 | else: 11 | num_shots = int(sys.argv[1]) 12 | 13 | image = utils.get_image() 14 | size = len(image) 15 | 16 | angles = [] 17 | # convert all rgb pixel values into angles in [0, pi/2] 18 | for i in range(size): 19 | for j in range(size): 20 | angles.append((utils.rgb_to_theta(image[i][j]))) 21 | 22 | new_angles = frqi_cirq.run(angles, num_shots) 23 | 24 | im = [] 25 | i = 0 26 | # converting all the recovered angles, back into rgb values 27 | for ang in new_angles: 28 | 29 | rgb = utils.theta_to_rgb(ang) 30 | if (i % 2 == 0): 31 | row = [] 32 | 33 | row.append(rgb) 34 | 35 | if (i % 2 != 0): 36 | im.append(row) 37 | 38 | i += 1 39 | 40 | # make an image using the recovered RGB values 41 | new_image = utils.make_image(im) 42 | 43 | # double the size of the image 7 times, so that it is larger enough to actually see what the colors are 44 | for i in range(7): 45 | new_image = utils.double_size(new_image) 46 | 47 | utils.show_image(new_image) 48 | 49 | 50 | if __name__ == "__main__": 51 | main() -------------------------------------------------------------------------------- /Revised/main_qiskit.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import utils 3 | import frqi_qiskit 4 | 5 | def main(): 6 | 7 | # if no command line argument is give, use 10,000 shots 8 | if (len(sys.argv) == 1): 9 | num_shots = 10000 10 | else: 11 | num_shots = int(sys.argv[1]) 12 | 13 | image = utils.get_image() 14 | size = len(image) 15 | 16 | angles = [] 17 | # convert all rgb pixel values into angles in [0, pi/2] 18 | for i in range(size): 19 | for j in range(size): 20 | angles.append((utils.rgb_to_theta(image[i][j]))) 21 | 22 | new_angles = frqi_qiskit.run(angles, num_shots) 23 | 24 | im = [] 25 | i = 0 26 | # converting all the recovered angles, back into rgb values 27 | for ang in new_angles: 28 | 29 | rgb = utils.theta_to_rgb(ang) 30 | if (i % 2 == 0): 31 | row = [] 32 | 33 | row.append(rgb) 34 | 35 | if (i % 2 != 0): 36 | im.append(row) 37 | 38 | i += 1 39 | 40 | # make an image using the recovered RGB values 41 | new_image = utils.make_image(im) 42 | 43 | # double the size of the image 7 times, so that it is larger enough to actually see what the colors are 44 | for i in range(7): 45 | new_image = utils.double_size(new_image) 46 | 47 | utils.show_image(new_image) 48 | 49 | 50 | if __name__ == "__main__": 51 | main() -------------------------------------------------------------------------------- /Revised/qiskit_compare.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import utils 3 | import frqi_qiskit 4 | import time 5 | 6 | # return the average difference between the entries in two lists 7 | def avg_diff(list1, list2): 8 | 9 | size = len(list1) 10 | 11 | sum = 0 12 | for i in range(size): 13 | sum += abs(list1[i] - list2[i]) 14 | 15 | return sum/size 16 | 17 | def run(num_shots): 18 | 19 | image = utils.get_image() 20 | size = len(image) 21 | 22 | angles = [] 23 | # convert all rgb pixel values into angles in [0, pi/2] 24 | for i in range(size): 25 | for j in range(size): 26 | angles.append((utils.rgb_to_theta(image[i][j]))) 27 | 28 | new_angles, totalTime = frqi_qiskit.run(angles, num_shots) 29 | 30 | diff = avg_diff(angles, new_angles) 31 | 32 | return totalTime, diff -------------------------------------------------------------------------------- /Revised/utils.py: -------------------------------------------------------------------------------- 1 | # This file contains functions which have to do with manipulating RGB images 2 | from PIL import Image 3 | import numpy as np 4 | from math import pi, floor 5 | 6 | # the number of possible RGB values used (default would be 256) 7 | r_num = 16 8 | g_num = r_num ** 2 9 | b_num = r_num ** 3 10 | 11 | # this function doubles the size of an image with 4 colors, because a 2x2 pixel image is very small 12 | def double_size(im): 13 | 14 | rows = len(im) 15 | cols = len(im[0]) 16 | 17 | new_im = np.zeros(((rows * 2, cols * 2, 3))) 18 | 19 | r = im[0] 20 | first = r[0] 21 | second = r[int(cols/2)] 22 | 23 | for i in range(rows): 24 | for j in range(cols): 25 | for k in range(3): 26 | new_im[i][j][k] = first[k] 27 | for j in range(cols, cols * 2): 28 | for k in range(3): 29 | new_im[i][j][k] = second[k] 30 | 31 | r = im[int(rows/2)] 32 | first = r[0] 33 | second = r[int(cols/2)] 34 | 35 | for i in range(rows, rows * 2): 36 | for j in range(cols): 37 | for k in range(3): 38 | new_im[i][j][k] = first[k] 39 | for j in range(cols, cols * 2): 40 | for k in range(3): 41 | new_im[i][j][k] = second[k] 42 | 43 | return new_im 44 | 45 | # given an rgb image as a regular python list, converts it into a numpy array image 46 | def make_image(rgbs): 47 | 48 | rows = len(rgbs) 49 | cols = len(rgbs[0]) 50 | 51 | new_im = np.zeros(((rows, cols, 3))) 52 | 53 | # convert to numpy array and scale the image back up 54 | for i in range(rows): 55 | for j in range(cols): 56 | for k in range(3): 57 | new_im[i][j][k] = rgbs[i][j][k] 58 | 59 | new_im = scale_up(new_im) 60 | 61 | return new_im 62 | 63 | # This function displays an image and saves it to the current directory 64 | def show_image(pixels): 65 | 66 | # Create a PIL image from the NumPy array 67 | image = Image.fromarray(pixels.astype('uint8'), 'RGB') 68 | 69 | image.show() 70 | 71 | # This function takes an image as a list of RGB values and converts it to a numpy array of RGB values and scales up the values 72 | def scale_up(image): 73 | 74 | rows = len(image) 75 | cols = len(image[0]) 76 | scale = 256/r_num 77 | new_im = np.zeros(((rows, cols, 3))) 78 | 79 | for i in range(rows): 80 | for j in range(rows): 81 | for k in range(3): 82 | new_im[i][j][k] = image[i][j][k] * scale 83 | 84 | return new_im 85 | 86 | # this function takes an RGB triplet and converts it to an angle in [0, pi/2] 87 | def rgb_to_theta(rgb): 88 | 89 | r, g, b = rgb 90 | theta = (pi/2) * ((r/r_num) + (g/g_num) + (b/b_num)) 91 | return theta 92 | 93 | # this function takes an angle and converts it to an RGB triplett 94 | def theta_to_rgb(theta): 95 | 96 | r = floor(theta/(pi/(r_num * 2))) 97 | theta = theta - r*(pi/(r_num * 2)) 98 | 99 | g = floor(theta/(pi/(g_num * 2))) 100 | theta = theta - g*(pi/(g_num * 2)) 101 | 102 | b = floor(theta/(pi/(b_num * 2))) 103 | 104 | return [r,g,b] 105 | 106 | # this function has the image which will be stored and recovered 107 | def get_image(): 108 | 109 | pixels = np.array([[[17, 17, 17], [240, 17, 17]], [[17, 240, 17], [17, 17, 240]]]) 110 | scale = 256/r_num 111 | 112 | for i in range(2): 113 | for j in range(2): 114 | for k in range(3): 115 | pixels[i][j][k] = floor(pixels[i][j][k] / scale) 116 | 117 | return pixels -------------------------------------------------------------------------------- /__pycache__/i_theta.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/__pycache__/i_theta.cpython-36.pyc -------------------------------------------------------------------------------- /__pycache__/image_testing.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/__pycache__/image_testing.cpython-36.pyc -------------------------------------------------------------------------------- /__pycache__/main_test.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/__pycache__/main_test.cpython-36.pyc -------------------------------------------------------------------------------- /__pycache__/testing_stuff.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/__pycache__/testing_stuff.cpython-36.pyc -------------------------------------------------------------------------------- /aman_code.py: -------------------------------------------------------------------------------- 1 | 2 | # coding: utf-8 3 | 4 | # In[40]: 5 | 6 | 7 | import qiskit as qk 8 | from qiskit import Aer,execute 9 | from math import pi 10 | 11 | qr =qk.QuantumRegister(3) 12 | cr = qk.ClassicalRegister(3) 13 | 14 | qc= qk.QuantumCircuit(qr,cr) 15 | 16 | #Creating the Hadamard State 17 | 18 | qc.h(qr[0]) 19 | qc.h(qr[1]) 20 | 21 | 22 | 23 | # Circuit for I(theta) starts here 24 | qc.x(qr[0]) 25 | qc.x(qr[1]) 26 | 27 | #pi/4=0.7853 28 | qc.cu3(0.7853,0,0,qr[0],qr[2]) 29 | 30 | qc.cx(qr[0],qr[1]) 31 | 32 | qc.cu3(-0.7853,0,0,qr[1],qr[2]) 33 | 34 | qc.cx(qr[0],qr[1]) 35 | 36 | qc.cu3(0.7853,0,0,qr[0],qr[2]) 37 | 38 | #pi/12=0.2617 39 | qc.x(qr[1]) 40 | 41 | qc.cu3(0.2617,0,0,qr[0],qr[2]) 42 | 43 | qc.cx(qr[0],qr[1]) 44 | 45 | qc.cu3(-0.2617,0,0,qr[1],qr[2]) 46 | 47 | qc.cx(qr[0],qr[1]) 48 | 49 | qc.cu3(0.2617,0,0,qr[0],qr[2]) 50 | 51 | #pi/6=0.5234 52 | 53 | qc.x(qr[0]) 54 | qc.x(qr[1]) 55 | 56 | qc.cu3(0.5234,0,0,qr[0],qr[2]) 57 | 58 | qc.cx(qr[0],qr[1]) 59 | 60 | qc.cu3(-0.5234,0,0,qr[1],qr[2]) 61 | 62 | qc.cx(qr[0],qr[1]) 63 | 64 | qc.cu3(0.5234,0,0,qr[0],qr[2]) 65 | 66 | #pi/16=0.1963 67 | qc.x(qr[1]) 68 | 69 | qc.cu3(0.1963,0,0,qr[0],qr[2]) 70 | 71 | qc.cx(qr[0],qr[1]) 72 | 73 | qc.cu3(-0.1963,0,0,qr[1],qr[2]) 74 | 75 | qc.cx(qr[0],qr[1]) 76 | 77 | qc.cu3(0.1963,0,0,qr[0],qr[2]) 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | qc.barrier(qr) 88 | 89 | qc.measure(qr,cr) 90 | 91 | 92 | 93 | 94 | 95 | 96 | # In[41]: 97 | 98 | 99 | backend_sim = Aer.get_backend('qasm_simulator') 100 | job_sim = execute(qc, backend_sim) 101 | result_sim = job_sim.result() 102 | 103 | 104 | # In[42]: 105 | 106 | 107 | counts = result_sim.get_counts(qc) 108 | print(counts) 109 | 110 | -------------------------------------------------------------------------------- /code_storage.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | import numpy as np 3 | from math import pi, floor 4 | 5 | """ 6 | img = Image.new('RGB', (60, 30), color = 'red') 7 | img.save('pil_red.png') 8 | """ 9 | # Create a NumPy array, which has four elements. The top-left should be pure red, the top-right should be pure blue, the bottom-left should be pure green, and the bottom-right should be yellow 10 | def double_size(im): 11 | 12 | rows = len(im) 13 | cols = len(im[0]) 14 | 15 | half_r = rows/2 16 | half_c = cols/2 17 | 18 | new_im = np.zeros(((rows * 2, cols * 2, 3))) 19 | 20 | r = im[0] 21 | first = r[0] 22 | second = r[int(cols/2)] 23 | 24 | for i in range(rows): 25 | for j in range(cols): 26 | for k in range(3): 27 | new_im[i][j][k] = first[k] 28 | for j in range(cols, cols * 2): 29 | for k in range(3): 30 | new_im[i][j][k] = second[k] 31 | 32 | r = im[int(rows/2)] 33 | first = r[0] 34 | second = r[int(cols/2)] 35 | 36 | for i in range(rows, rows * 2): 37 | for j in range(cols): 38 | for k in range(3): 39 | new_im[i][j][k] = first[k] 40 | for j in range(cols, cols * 2): 41 | for k in range(3): 42 | new_im[i][j][k] = second[k] 43 | 44 | return new_im 45 | 46 | def make_image(pixels): 47 | 48 | # Create a PIL image from the NumPy array 49 | image = Image.fromarray(pixels.astype('uint8'), 'RGB') 50 | 51 | # Save the image 52 | #image.save('image.png') 53 | image.show() 54 | 55 | def get_smallest(): 56 | 57 | pixels = np.array([[[255, 0, 0], [0, 255, 0]], [[0, 0, 255], [255, 255, 0]]]) 58 | 59 | return pixels 60 | 61 | """ 62 | pixels = np.array([[[255, 0, 0], [255, 0, 0], [255, 0, 0], [255, 0, 0], [0, 255, 0], [0, 255, 0], [0, 255, 0], [0, 255, 0]], 63 | [[255, 0, 0], [255, 0, 0], [255, 0, 0], [255, 0, 0], [0, 255, 0], [0, 255, 0], [0, 255, 0], [0, 255, 0]], 64 | [[255, 0, 0], [255, 0, 0], [255, 0, 0], [255, 0, 0], [0, 255, 0], [0, 255, 0], [0, 255, 0], [0, 255, 0]], 65 | [[255, 0, 0], [255, 0, 0], [255, 0, 0], [255, 0, 0], [0, 255, 0], [0, 255, 0], [0, 255, 0], [0, 255, 0]], 66 | [[0, 0, 255], [0, 0, 255], [0, 0, 255], [0, 0, 255], [255, 255, 0], [255, 255, 0], [255, 255, 0], [255, 255, 0]], 67 | [[0, 0, 255], [0, 0, 255], [0, 0, 255], [0, 0, 255], [255, 255, 0], [255, 255, 0], [255, 255, 0], [255, 255, 0]], 68 | [[0, 0, 255], [0, 0, 255], [0, 0, 255], [0, 0, 255], [255, 255, 0], [255, 255, 0], [255, 255, 0], [255, 255, 0]], 69 | [[0, 0, 255], [0, 0, 255], [0, 0, 255], [0, 0, 255], [255, 255, 0], [255, 255, 0], [255, 255, 0], [255, 255, 0]]]) 70 | """ 71 | """ 72 | def rgb_to_theta(rgb): 73 | 74 | r, g, b = rgb 75 | theta = (pi/2) * ((r/2) + (g/4) + (b/8)) 76 | #print("Theta is ", theta) 77 | return theta 78 | 79 | def theta_to_rgb(theta): 80 | 81 | r = floor(theta/(pi/4)) 82 | 83 | theta = theta - r*(pi/4) 84 | 85 | g = floor(theta/(pi/8)) 86 | 87 | theta = theta - g*(pi/8) 88 | 89 | b = floor(theta/(pi/16)) 90 | print("rgb = ", [r, g, b]) 91 | 92 | def test_it(): 93 | 94 | list = [] 95 | for i in range(2): 96 | for j in range(2): 97 | for k in range(2): 98 | list.append([i, j, k]) 99 | 100 | i = 0 101 | for elem in list: 102 | print("i ============== ", i) 103 | i += 1 104 | print(elem) 105 | theta = rgb_to_theta(elem) 106 | theta_to_rgb(theta) 107 | """ 108 | 109 | def rgb_to_theta(rgb): 110 | 111 | r, g, b = rgb 112 | theta = (pi/2) * ((r/256) + (g/(256**2)) + (b/256**3)) 113 | print("Theta is ", theta) 114 | return theta 115 | 116 | def theta_to_rgb(theta): 117 | 118 | r = floor(theta/((pi/2) * (1/256))) 119 | theta = theta - r*((pi/2) * (1/256)) 120 | print("After R, theta is ", theta) 121 | 122 | g = floor(theta/((pi/2) * (1/256**2))) 123 | theta = theta - g*((pi/2) * (1/256**2)) 124 | print("After G, theta is ", theta) 125 | 126 | b = floor(theta/((pi/2) * (1/256**3))) 127 | 128 | print("rgb = ", [r, g, b]) 129 | 130 | def test_it(): 131 | 132 | list = [] 133 | for i in range(5): 134 | for j in range(5): 135 | for k in range(5): 136 | list.append([i, j, k]) 137 | 138 | i = 0 139 | for elem in list: 140 | print("i ============== ", i) 141 | i += 1 142 | print(elem) 143 | theta = rgb_to_theta(elem) 144 | theta_to_rgb(theta) 145 | 146 | ========================================= 147 | 148 | 149 | # coding: utf-8 150 | # In[40]: 151 | import qiskit as qk 152 | from qiskit import Aer,execute 153 | from math import pi 154 | #pi = 3.14159 155 | 156 | def run(): 157 | 158 | qr =qk.QuantumRegister(3) 159 | cr = qk.ClassicalRegister(3) 160 | 161 | qc= qk.QuantumCircuit(qr,cr) 162 | 163 | #Creating the Hadamard State 164 | qc.h(qr[0]) 165 | qc.h(qr[1]) 166 | 167 | # Circuit for I(theta) starts here 168 | #qc.x(qr[0]) 169 | #qc.x(qr[1]) 170 | 171 | angles = [pi/2, 0, pi/2, 0] 172 | #pi/4=0.7853 173 | qc.cu3(angles[0],0,0,qr[0],qr[2]) 174 | qc.cx(qr[0],qr[1]) 175 | qc.cu3(-angles[0],0,0,qr[1],qr[2]) 176 | qc.cx(qr[0],qr[1]) 177 | qc.cu3(angles[0],0,0,qr[0],qr[2]) 178 | 179 | ### 180 | qc.barrier(qr) 181 | qc.measure(qr,cr) 182 | 183 | # In[41]: 184 | backend_sim = Aer.get_backend('qasm_simulator') 185 | job_sim = execute(qc, backend_sim, shots=10000) 186 | result_sim = job_sim.result() 187 | 188 | # In[42]: 189 | 190 | counts = result_sim.get_counts(qc) 191 | print(counts) 192 | ### 193 | 194 | """ 195 | 196 | #pi/12=0.2617 197 | 198 | qc.x(qr[1]) 199 | 200 | qc.cu3(angles[1],0,0,qr[0],qr[2]) 201 | qc.cx(qr[0],qr[1]) 202 | qc.cu3(-angles[1],0,0,qr[1],qr[2]) 203 | qc.cx(qr[0],qr[1]) 204 | qc.cu3(angles[1],0,0,qr[0],qr[2]) 205 | 206 | #pi/6=0.5234 207 | 208 | qc.x(qr[0]) 209 | qc.x(qr[1]) 210 | 211 | qc.cu3(angles[2],0,0,qr[0],qr[2]) 212 | qc.cx(qr[0],qr[1]) 213 | qc.cu3(-angles[2],0,0,qr[1],qr[2]) 214 | qc.cx(qr[0],qr[1]) 215 | qc.cu3(angles[2],0,0,qr[0],qr[2]) 216 | 217 | #pi/16=0.1963 218 | 219 | qc.x(qr[1]) 220 | 221 | qc.cu3(angles[3],0,0,qr[0],qr[2]) 222 | qc.cx(qr[0],qr[1]) 223 | qc.cu3(-angles[3],0,0,qr[1],qr[2]) 224 | qc.cx(qr[0],qr[1]) 225 | qc.cu3(angles[3],0,0,qr[0],qr[2]) 226 | 227 | qc.barrier(qr) 228 | qc.measure(qr,cr) 229 | 230 | # In[41]: 231 | backend_sim = Aer.get_backend('qasm_simulator') 232 | job_sim = execute(qc, backend_sim, shots=10000) 233 | result_sim = job_sim.result() 234 | 235 | # In[42]: 236 | 237 | counts = result_sim.get_counts(qc) 238 | print(counts) 239 | """ 240 | ====================== 241 | 242 | def probs(results): 243 | 244 | angles = [] 245 | if ("000" in results): 246 | prob = results["000"]/num_shots 247 | # to get the angle back cos^-1(sqrt(probability)) 248 | angles.append(acos(sqrt(4 *prob))) 249 | else: 250 | angles.append(pi/2) 251 | 252 | if ("001" in results): 253 | probs.append(results["001"]/num_shots) 254 | else: 255 | probs.append(0.) 256 | 257 | if ("010" in results): 258 | probs.append(results["010"]/num_shots) 259 | else: 260 | probs.append(0.) 261 | 262 | if ("011" in results): 263 | probs.append(results["011"]/num_shots) 264 | else: 265 | probs.append(0.) 266 | 267 | print(probs) 268 | 269 | ======== 270 | if ("000" in results): 271 | prob = results["000"]/num_shots 272 | # to get the angle back cos^-1(sqrt(4 * probability)) 273 | angles.append(acos(sqrt(4 *prob))) 274 | else: 275 | angles.append(pi/2) 276 | 277 | 278 | #converting from rgb to theta and vice versa in degrees 279 | ==================== 280 | # function to convert an rgb value into an angle, theta 281 | def rgb_to_theta(rgb): 282 | 283 | r, g, b = rgb 284 | # storing the angle in degrees instead of radians 285 | theta = (90) * ((r/256) + (g/(256**2)) + (b/256**3)) 286 | return theta 287 | 288 | # function to convert the angle theta back into an rgb value 289 | def theta_to_rgb(theta): 290 | 291 | # recovering the value of r 292 | r = floor(theta/(90/256)) 293 | # subtracting from theta to get the angle to be in the first region of the quadrant 294 | theta = theta - r*(90/256) 295 | # now that the angle is in the first region, can multiply to get it to the proper region for the g value 296 | theta *= 256 297 | 298 | # recovering the value of g 299 | g = floor(theta/(90/256)) 300 | theta = theta - g*(90/256) 301 | theta *= 256 302 | 303 | b = floor(theta/(90/256)) 304 | 305 | return [r,g,b] 306 | 307 | """ 308 | pixels = np.array([[[255, 0, 0], [255, 0, 0], [255, 0, 0], [255, 0, 0], [0, 255, 0], [0, 255, 0], [0, 255, 0], [0, 255, 0]], 309 | [[255, 0, 0], [255, 0, 0], [255, 0, 0], [255, 0, 0], [0, 255, 0], [0, 255, 0], [0, 255, 0], [0, 255, 0]], 310 | [[255, 0, 0], [255, 0, 0], [255, 0, 0], [255, 0, 0], [0, 255, 0], [0, 255, 0], [0, 255, 0], [0, 255, 0]], 311 | [[255, 0, 0], [255, 0, 0], [255, 0, 0], [255, 0, 0], [0, 255, 0], [0, 255, 0], [0, 255, 0], [0, 255, 0]], 312 | [[0, 0, 255], [0, 0, 255], [0, 0, 255], [0, 0, 255], [255, 255, 0], [255, 255, 0], [255, 255, 0], [255, 255, 0]], 313 | [[0, 0, 255], [0, 0, 255], [0, 0, 255], [0, 0, 255], [255, 255, 0], [255, 255, 0], [255, 255, 0], [255, 255, 0]], 314 | [[0, 0, 255], [0, 0, 255], [0, 0, 255], [0, 0, 255], [255, 255, 0], [255, 255, 0], [255, 255, 0], [255, 255, 0]], 315 | [[0, 0, 255], [0, 0, 255], [0, 0, 255], [0, 0, 255], [255, 255, 0], [255, 255, 0], [255, 255, 0], [255, 255, 0]]]) 316 | """ 317 | 318 | """ 319 | # I can put this into a for loop if I need to. 320 | # probs for 1st pixel 321 | if ("000" in results): 322 | prob["000"] = results["000"]/num_shots 323 | else: 324 | prob["000"] = 0. 325 | 326 | if ("100" in results): 327 | prob["100"] = results["100"]/num_shots 328 | else: 329 | prob["100"] = 0. 330 | 331 | # probs for 2nd pixel 332 | if ("001" in results): 333 | prob["001"] = results["001"]/num_shots 334 | else: 335 | prob["001"] = 0. 336 | 337 | if ("101" in results): 338 | prob["101"] = results["101"]/num_shots 339 | else: 340 | prob["101"] = 0. 341 | 342 | # probs for 3rd pixel 343 | if ("010" in results): 344 | prob["010"] = results["010"]/num_shots 345 | else: 346 | prob["010"] = 0. 347 | 348 | if ("110" in results): 349 | prob["110"] = results["110"]/num_shots 350 | else: 351 | prob["110"] = 0. 352 | 353 | # probs for 4th pixel 354 | if ("011" in results): 355 | prob["011"] = results["011"]/num_shots 356 | else: 357 | prob["011"] = 0. 358 | 359 | if ("111" in results): 360 | prob["111"] = results["111"]/num_shots 361 | else: 362 | prob["111"] = 0. 363 | 364 | 365 | angles = [] 366 | # now need to recover the angles 367 | zero_prob = prob["000"]/(prob["000"] + prob["100"]) 368 | angles.append(acos(sqrt(zero_prob))) 369 | 370 | zero_prob = prob["001"]/(prob["001"] + prob["101"]) 371 | angles.append(acos(sqrt(zero_prob))) 372 | 373 | zero_prob = prob["010"]/(prob["010"] + prob["110"]) 374 | angles.append(acos(sqrt(zero_prob))) 375 | 376 | zero_prob = prob["011"]/(prob["011"] + prob["111"]) 377 | angles.append(acos(sqrt(zero_prob))) 378 | """ 379 | 380 | =========================== 381 | 382 | qc.ccx(qr[0], qr[1], qr[4]) 383 | qc.ccx(qr[2], qr[4], qr[5]) 384 | qc.ccx(qr[3], qr[5], qr[6]) 385 | 386 | qc.cu3(angles[0],0,0,qr[6],qr[7]) 387 | 388 | qc.ccx(qr[3], qr[5], qr[6]) 389 | qc.ccx(qr[2], qr[4], qr[5]) 390 | qc.ccx(qr[0], qr[1], qr[4]) 391 | 392 | =========================== 393 | pixels = np.array([[[250, 5, 5], [5, 250, 5], [5, 5, 250], [250, 250, 5]], 394 | [[250, 5, 250], [5, 250, 250], [100, 50, 5], [5, 100, 50]], 395 | [[100, 100, 100], [100, 150, 200], [200, 100, 150], [150, 200, 150]], 396 | [[75, 180, 105], [180, 105, 75], [105, 180, 75], [128, 128, 128]]]) 397 | 398 | =========================== 399 | 400 | def get_xs(): 401 | 402 | chars = ["0","1"] 403 | vals = [] 404 | 405 | for i in chars: 406 | for j in chars: 407 | for k in chars: 408 | for l in chars: 409 | vals.append(i + j + k + l) 410 | 411 | total = [] 412 | for i in range(16): 413 | 414 | x_vals = [] 415 | word = vals[i] 416 | for j in range(4): 417 | if(word[j] == '0'): 418 | x_vals.append('x') 419 | else: 420 | x_vals.append('_') 421 | 422 | total.append(x_vals) 423 | 424 | for k in range(16): 425 | for q in range(4): 426 | if (x_vals[q] == 'x'): 427 | if (vals[k][q] == '0'): 428 | new_val = [] 429 | for r in range(4): 430 | if (r != q): 431 | new_val.append(vals[k][r]) 432 | else: 433 | new_val.append('1') 434 | vals[k] = new_val 435 | else: 436 | new_val = [] 437 | for r in range(4): 438 | if (r != q): 439 | new_val.append(vals[k][r]) 440 | else: 441 | new_val.append('0') 442 | vals[k] = new_val 443 | 444 | print("================ ", i, " =================") 445 | print(vals) 446 | 447 | print(total) -------------------------------------------------------------------------------- /i_theta.py: -------------------------------------------------------------------------------- 1 | 2 | # coding: utf-8 3 | # In[40]: 4 | import qiskit as qk 5 | from qiskit import Aer,execute 6 | from math import pi, sqrt, acos 7 | from image_testing import r_num, g_num, b_num 8 | 9 | num_shots = 100000 10 | 11 | def probs(results): 12 | 13 | prob = {} 14 | 15 | chars = ["0", "1"] 16 | for c in chars: 17 | for d in chars: 18 | for e in chars: 19 | state = c + d + e 20 | if (state in results): 21 | prob[state] = results[state]/num_shots 22 | else: 23 | prob[state] = 0. 24 | 25 | angles = [] 26 | for c in chars: 27 | for d in chars: 28 | zero = "0" + c + d 29 | one = "1" + c + d 30 | zero_prob = prob[zero]/(prob[zero] + prob[one]) 31 | angles.append(acos(sqrt(zero_prob))) 32 | 33 | return angles 34 | 35 | def probs4(results): 36 | 37 | prob = {} 38 | 39 | chars = ["0", "1"] 40 | for c in chars: 41 | for d in chars: 42 | for e in chars: 43 | for f in chars: 44 | for g in chars: 45 | state = c + "000" + d + e + f + g 46 | if (state in results): 47 | prob[state] = results[state]/num_shots 48 | else: 49 | prob[state] = 0. 50 | 51 | angles = [] 52 | for c in chars: 53 | for d in chars: 54 | for e in chars: 55 | for f in chars: 56 | zero = "0000" + c + d + e + f 57 | one = "1000" + c + d + e + f 58 | zero_prob = prob[zero]/(prob[zero] + prob[one]) 59 | angles.append(acos(sqrt(zero_prob))) 60 | 61 | return angles 62 | 63 | def run(angles): 64 | 65 | qr =qk.QuantumRegister(3) 66 | cr = qk.ClassicalRegister(3) 67 | 68 | qc= qk.QuantumCircuit(qr,cr) 69 | 70 | #Creating the Hadamard State 71 | qc.h(qr[0]) 72 | qc.h(qr[1]) 73 | 74 | # Circuit for I(theta) starts here 75 | qc.x(qr[0]) 76 | qc.x(qr[1]) 77 | 78 | #pi/4=0.7853 79 | qc.cu3(angles[0],0,0,qr[0],qr[2]) 80 | qc.cx(qr[0],qr[1]) 81 | qc.cu3(-angles[0],0,0,qr[1],qr[2]) 82 | qc.cx(qr[0],qr[1]) 83 | qc.cu3(angles[0],0,0,qr[1],qr[2]) 84 | 85 | #pi/12=0.2617 86 | qc.x(qr[0]) 87 | 88 | qc.cu3(angles[1],0,0,qr[0],qr[2]) 89 | qc.cx(qr[0],qr[1]) 90 | qc.cu3(-angles[1],0,0,qr[1],qr[2]) 91 | qc.cx(qr[0],qr[1]) 92 | qc.cu3(angles[1],0,0,qr[1],qr[2]) 93 | 94 | #pi/6=0.5234 95 | qc.x(qr[0]) 96 | qc.x(qr[1]) 97 | 98 | qc.cu3(angles[2],0,0,qr[0],qr[2]) 99 | qc.cx(qr[0],qr[1]) 100 | qc.cu3(-angles[2],0,0,qr[1],qr[2]) 101 | qc.cx(qr[0],qr[1]) 102 | qc.cu3(angles[2],0,0,qr[1],qr[2]) 103 | 104 | #pi/16=0.1963 105 | qc.x(qr[0]) 106 | 107 | qc.cu3(angles[3],0,0,qr[0],qr[2]) 108 | qc.cx(qr[0],qr[1]) 109 | qc.cu3(-angles[3],0,0,qr[1],qr[2]) 110 | qc.cx(qr[0],qr[1]) 111 | qc.cu3(angles[3],0,0,qr[1],qr[2]) 112 | 113 | qc.barrier(qr) 114 | qc.measure(qr,cr) 115 | 116 | # In[41]: 117 | backend_sim = Aer.get_backend('qasm_simulator') 118 | job_sim = execute(qc, backend_sim, shots=num_shots) 119 | result_sim = job_sim.result() 120 | 121 | # In[42]: 122 | counts = result_sim.get_counts(qc) 123 | 124 | new_angles = probs(counts) 125 | 126 | return new_angles 127 | 128 | def run_4(angles): 129 | 130 | # can just pass in the same angles as I did for 2x2. No need to double them. 131 | for i in range(len(angles)): 132 | angles[i] = 2 * angles[i] 133 | 134 | # we are including 3 ancilla qubits 135 | qr =qk.QuantumRegister(8) 136 | cr = qk.ClassicalRegister(8) 137 | 138 | qc= qk.QuantumCircuit(qr,cr) 139 | 140 | #Creating the Hadamard State 141 | qc.h(qr[0]) 142 | qc.h(qr[1]) 143 | qc.h(qr[2]) 144 | qc.h(qr[3]) 145 | 146 | # angle to manipulate the colors by 147 | 148 | for i in range(16): 149 | 150 | qc.x(qr[0]) 151 | 152 | if (i % 4 == 2): 153 | qc.x(qr[1]) 154 | 155 | if (i == 0 or i == 8): 156 | qc.x(qr[1]) 157 | qc.x(qr[2]) 158 | qc.x(qr[3]) 159 | 160 | if (i == 4 or i == 12): 161 | qc.x(qr[1]) 162 | qc.x(qr[2]) 163 | 164 | qc.ccx(qr[0], qr[1], qr[4]) 165 | qc.ccx(qr[2], qr[4], qr[5]) 166 | qc.ccx(qr[3], qr[5], qr[6]) 167 | 168 | qc.cu3(angles[i],0,0,qr[6],qr[7]) 169 | 170 | qc.ccx(qr[3], qr[5], qr[6]) 171 | qc.ccx(qr[2], qr[4], qr[5]) 172 | qc.ccx(qr[0], qr[1], qr[4]) 173 | 174 | """ 175 | ################ 176 | # pixel shifting 177 | 178 | #C3not 179 | qc.ccx(qr[0], qr[1], qr[4]) 180 | qc.ccx(qr[2], qr[4], qr[5]) 181 | 182 | qc.cx(qr[5], qr[3]) 183 | 184 | qc.ccx(qr[2], qr[4], qr[5]) 185 | qc.ccx(qr[0], qr[1], qr[4]) 186 | 187 | #C2not 188 | qc.ccx(qr[0], qr[1], qr[2]) 189 | 190 | #CNOT 191 | qc.cx(qr[0], qr[1]) 192 | 193 | #NOT 194 | qc.x(qr[0]) 195 | 196 | ################ 197 | """ 198 | 199 | qc.barrier(qr) 200 | qc.measure(qr,cr) 201 | 202 | # In[41]: 203 | backend_sim = Aer.get_backend('qasm_simulator') 204 | job_sim = execute(qc, backend_sim, shots=num_shots) 205 | result_sim = job_sim.result() 206 | 207 | # In[42]: 208 | counts = result_sim.get_counts(qc) 209 | 210 | #print(counts) 211 | 212 | new_angles = probs4(counts) 213 | 214 | return new_angles 215 | 216 | 217 | 218 | 219 | """ 220 | def test(): 221 | 222 | for i in range(16): 223 | 224 | angles = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] 225 | angles[i] = pi/2 226 | 227 | run_4(angles) 228 | #print("==============\n", i, "\n==============") 229 | 230 | break 231 | """ 232 | 233 | def get_xs(): 234 | 235 | chars = ["0","1"] 236 | vals = [] 237 | 238 | for i in chars: 239 | for j in chars: 240 | for k in chars: 241 | for l in chars: 242 | for m in chars: 243 | for n in chars: 244 | vals.append(i + j + k + l + m + n) 245 | 246 | total = [] 247 | for i in range(64): 248 | 249 | x_vals = [] 250 | word = vals[i] 251 | for j in range(6): 252 | if(word[j] == '0'): 253 | x_vals.append('x') 254 | else: 255 | x_vals.append('_') 256 | 257 | total.append(x_vals) 258 | 259 | for k in range(64): 260 | for q in range(6): 261 | if (x_vals[q] == 'x'): 262 | if (vals[k][q] == '0'): 263 | new_val = [] 264 | for r in range(6): 265 | if (r != q): 266 | new_val.append(vals[k][r]) 267 | else: 268 | new_val.append('1') 269 | vals[k] = new_val 270 | else: 271 | new_val = [] 272 | for r in range(6): 273 | if (r != q): 274 | new_val.append(vals[k][r]) 275 | else: 276 | new_val.append('0') 277 | vals[k] = new_val 278 | 279 | #print("================ ", i, " =================") 280 | #print(vals) 281 | 282 | print(total) 283 | 284 | -------------------------------------------------------------------------------- /i_theta_saved.py: -------------------------------------------------------------------------------- 1 | 2 | # coding: utf-8 3 | # In[40]: 4 | import qiskit as qk 5 | from qiskit import Aer,execute 6 | from math import pi, sqrt, acos 7 | from image_testing import r_num, g_num, b_num 8 | 9 | num_shots = 100000000 10 | 11 | def probs(results): 12 | 13 | prob = {} 14 | 15 | chars = ["0", "1"] 16 | for c in chars: 17 | for d in chars: 18 | for e in chars: 19 | state = c + d + e 20 | if (state in results): 21 | prob[state] = results[state]/num_shots 22 | else: 23 | prob[state] = 0. 24 | 25 | angles = [] 26 | for c in chars: 27 | for d in chars: 28 | zero = "0" + c + d 29 | one = "1" + c + d 30 | zero_prob = prob[zero]/(prob[zero] + prob[one]) 31 | angles.append(acos(sqrt(zero_prob))) 32 | 33 | return angles 34 | 35 | def probs4(results): 36 | 37 | prob = {} 38 | 39 | chars = ["0", "1"] 40 | for c in chars: 41 | for d in chars: 42 | for e in chars: 43 | for f in chars: 44 | for g in chars: 45 | state = c + "000" + d + e + f + g 46 | if (state in results): 47 | prob[state] = results[state]/num_shots 48 | else: 49 | prob[state] = 0. 50 | 51 | angles = [] 52 | for c in chars: 53 | for d in chars: 54 | for e in chars: 55 | for f in chars: 56 | zero = "0000" + c + d + e + f 57 | one = "1000" + c + d + e + f 58 | zero_prob = prob[zero]/(prob[zero] + prob[one]) 59 | angles.append(acos(sqrt(zero_prob))) 60 | 61 | return angles 62 | 63 | def run(angles): 64 | 65 | qr =qk.QuantumRegister(3) 66 | cr = qk.ClassicalRegister(3) 67 | 68 | qc= qk.QuantumCircuit(qr,cr) 69 | 70 | # angles to rotate by 71 | red = (pi/2) * (1/r_num) 72 | green = (pi/2) * (1/g_num) 73 | blue = (pi/2) * (1/b_num) 74 | # shift by 75 | s = 8 * 2 76 | 77 | #Creating the Hadamard State 78 | qc.h(qr[0]) 79 | qc.h(qr[1]) 80 | 81 | # Circuit for I(theta) starts here 82 | qc.x(qr[0]) 83 | qc.x(qr[1]) 84 | 85 | #pi/4=0.7853 86 | qc.cu3(angles[0],0,0,qr[0],qr[2]) 87 | qc.cx(qr[0],qr[1]) 88 | qc.cu3(-angles[0],0,0,qr[1],qr[2]) 89 | qc.cx(qr[0],qr[1]) 90 | qc.cu3(angles[0],0,0,qr[1],qr[2]) 91 | 92 | #pi/12=0.2617 93 | qc.x(qr[0]) 94 | 95 | qc.cu3(angles[1],0,0,qr[0],qr[2]) 96 | qc.cx(qr[0],qr[1]) 97 | qc.cu3(-angles[1],0,0,qr[1],qr[2]) 98 | qc.cx(qr[0],qr[1]) 99 | qc.cu3(angles[1],0,0,qr[1],qr[2]) 100 | 101 | #pi/6=0.5234 102 | qc.x(qr[0]) 103 | qc.x(qr[1]) 104 | 105 | qc.cu3(angles[2],0,0,qr[0],qr[2]) 106 | qc.cx(qr[0],qr[1]) 107 | qc.cu3(-angles[2],0,0,qr[1],qr[2]) 108 | qc.cx(qr[0],qr[1]) 109 | qc.cu3(angles[2],0,0,qr[1],qr[2]) 110 | 111 | #pi/16=0.1963 112 | qc.x(qr[0]) 113 | 114 | qc.cu3(angles[3],0,0,qr[0],qr[2]) 115 | qc.cx(qr[0],qr[1]) 116 | qc.cu3(-angles[3],0,0,qr[1],qr[2]) 117 | qc.cx(qr[0],qr[1]) 118 | qc.cu3(angles[3],0,0,qr[1],qr[2]) 119 | 120 | qc.u3(s * red,0,0,qr[2]) 121 | 122 | qc.barrier(qr) 123 | qc.measure(qr,cr) 124 | 125 | # In[41]: 126 | backend_sim = Aer.get_backend('qasm_simulator') 127 | job_sim = execute(qc, backend_sim, shots=num_shots) 128 | result_sim = job_sim.result() 129 | 130 | # In[42]: 131 | counts = result_sim.get_counts(qc) 132 | 133 | new_angles = probs(counts) 134 | 135 | return new_angles 136 | 137 | def run_4(angles): 138 | 139 | # can just pass in the same angles as I did for 2x2. No need to double them. 140 | for i in range(len(angles)): 141 | angles[i] = 2 * angles[i] 142 | 143 | # we are including 3 ancilla qubits 144 | qr =qk.QuantumRegister(8) 145 | cr = qk.ClassicalRegister(8) 146 | 147 | qc= qk.QuantumCircuit(qr,cr) 148 | 149 | #Creating the Hadamard State 150 | qc.h(qr[0]) 151 | qc.h(qr[1]) 152 | qc.h(qr[2]) 153 | qc.h(qr[3]) 154 | 155 | # angle to manipulate the colors by 156 | 157 | for i in range(16): 158 | 159 | qc.x(qr[0]) 160 | 161 | if (i % 4 == 2): 162 | qc.x(qr[1]) 163 | 164 | if (i == 0 or i == 8): 165 | qc.x(qr[1]) 166 | qc.x(qr[2]) 167 | qc.x(qr[3]) 168 | 169 | if (i == 4 or i == 12): 170 | qc.x(qr[1]) 171 | qc.x(qr[2]) 172 | 173 | qc.ccx(qr[0], qr[1], qr[4]) 174 | qc.ccx(qr[2], qr[4], qr[5]) 175 | qc.ccx(qr[3], qr[5], qr[6]) 176 | 177 | qc.cu3(angles[i],0,0,qr[6],qr[7]) 178 | 179 | qc.ccx(qr[3], qr[5], qr[6]) 180 | qc.ccx(qr[2], qr[4], qr[5]) 181 | qc.ccx(qr[0], qr[1], qr[4]) 182 | 183 | """ 184 | ################ 185 | # pixel shifting 186 | 187 | #C3not 188 | qc.ccx(qr[0], qr[1], qr[4]) 189 | qc.ccx(qr[2], qr[4], qr[5]) 190 | 191 | qc.cx(qr[5], qr[3]) 192 | 193 | qc.ccx(qr[2], qr[4], qr[5]) 194 | qc.ccx(qr[0], qr[1], qr[4]) 195 | 196 | #C2not 197 | qc.ccx(qr[0], qr[1], qr[2]) 198 | 199 | #CNOT 200 | qc.cx(qr[0], qr[1]) 201 | 202 | #NOT 203 | qc.x(qr[0]) 204 | 205 | ################ 206 | """ 207 | 208 | qc.barrier(qr) 209 | qc.measure(qr,cr) 210 | 211 | # In[41]: 212 | backend_sim = Aer.get_backend('qasm_simulator') 213 | job_sim = execute(qc, backend_sim, shots=num_shots) 214 | result_sim = job_sim.result() 215 | 216 | # In[42]: 217 | counts = result_sim.get_counts(qc) 218 | 219 | #print(counts) 220 | 221 | new_angles = probs4(counts) 222 | 223 | return new_angles 224 | 225 | 226 | 227 | 228 | """ 229 | def test(): 230 | 231 | for i in range(16): 232 | 233 | angles = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] 234 | angles[i] = pi/2 235 | 236 | run_4(angles) 237 | #print("==============\n", i, "\n==============") 238 | 239 | break 240 | """ 241 | 242 | def get_xs(): 243 | 244 | chars = ["0","1"] 245 | vals = [] 246 | 247 | for i in chars: 248 | for j in chars: 249 | for k in chars: 250 | for l in chars: 251 | vals.append(i + j + k + l) 252 | 253 | total = [] 254 | for i in range(16): 255 | 256 | x_vals = [] 257 | word = vals[i] 258 | for j in range(4): 259 | if(word[j] == '0'): 260 | x_vals.append('x') 261 | else: 262 | x_vals.append('_') 263 | 264 | total.append(x_vals) 265 | 266 | for k in range(16): 267 | for q in range(4): 268 | if (x_vals[q] == 'x'): 269 | if (vals[k][q] == '0'): 270 | new_val = [] 271 | for r in range(4): 272 | if (r != q): 273 | new_val.append(vals[k][r]) 274 | else: 275 | new_val.append('1') 276 | vals[k] = new_val 277 | else: 278 | new_val = [] 279 | for r in range(4): 280 | if (r != q): 281 | new_val.append(vals[k][r]) 282 | else: 283 | new_val.append('0') 284 | vals[k] = new_val 285 | 286 | print("================ ", i, " =================") 287 | print(vals) 288 | 289 | print(total) 290 | 291 | -------------------------------------------------------------------------------- /image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/image.png -------------------------------------------------------------------------------- /image_testing.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | import numpy as np 3 | from math import pi, floor 4 | 5 | r_num = 16 6 | g_num = r_num ** 2 7 | b_num = r_num ** 3 8 | 9 | """ 10 | img = Image.new('RGB', (60, 30), color = 'red') 11 | img.save('pil_red.png') 12 | """ 13 | # Create a NumPy array, which has four elements. The top-left should be pure red, the top-right should be pure blue, the bottom-left should be pure green, and the bottom-right should be yellow 14 | def double_size(im): 15 | 16 | rows = len(im) 17 | cols = len(im[0]) 18 | 19 | #half_r = rows/2 20 | #half_c = cols/2 21 | 22 | new_im = np.zeros(((rows * 2, cols * 2, 3))) 23 | 24 | r = im[0] 25 | first = r[0] 26 | second = r[int(cols/2)] 27 | 28 | for i in range(rows): 29 | for j in range(cols): 30 | for k in range(3): 31 | new_im[i][j][k] = first[k] 32 | for j in range(cols, cols * 2): 33 | for k in range(3): 34 | new_im[i][j][k] = second[k] 35 | 36 | r = im[int(rows/2)] 37 | first = r[0] 38 | second = r[int(cols/2)] 39 | 40 | for i in range(rows, rows * 2): 41 | for j in range(cols): 42 | for k in range(3): 43 | new_im[i][j][k] = first[k] 44 | for j in range(cols, cols * 2): 45 | for k in range(3): 46 | new_im[i][j][k] = second[k] 47 | 48 | return new_im 49 | """ 50 | [[[250, 5, 5], [5, 250, 5], [250, 5, 5], [5, 250, 5]] 51 | [[5, 5, 250], [250, 250, 5], [250, 5, 5], [5, 250, 5]] 52 | [[250, 5, 5], [5, 250, 5], [250, 5, 5], [5, 250, 5]] 53 | [[250, 5, 5], [5, 250, 5], [250, 5, 5], [5, 250, 5]]] 54 | """ 55 | def double_size4(im): 56 | 57 | rows = len(im) 58 | cols = len(im[0]) 59 | 60 | new_im = np.zeros(((rows * 2, cols * 2, 3))) 61 | 62 | r = im[0] 63 | first = r[0] 64 | second = r[int(cols/4)] 65 | third = r[int(cols/2)] 66 | fourth = r[int(3 * cols/4)] 67 | 68 | for i in range(int(rows/2)): 69 | for j in range(int(cols/2)): 70 | for k in range(3): 71 | new_im[i][j][k] = first[k] 72 | for j in range(int(cols/2), cols): 73 | for k in range(3): 74 | new_im[i][j][k] = second[k] 75 | for j in range(cols, int(cols * (3/2))): 76 | for k in range(3): 77 | new_im[i][j][k] = third[k] 78 | for j in range(int(cols * (3/2)), cols * 2): 79 | for k in range(3): 80 | new_im[i][j][k] = fourth[k] 81 | 82 | r = im[int(rows/4)] 83 | first = r[0] 84 | second = r[int(cols/4)] 85 | third = r[int(cols/2)] 86 | fourth = r[int(3 * cols/4)] 87 | 88 | for i in range(int(rows/2), rows): 89 | for j in range(int(cols/2)): 90 | for k in range(3): 91 | new_im[i][j][k] = first[k] 92 | for j in range(int(cols/2), cols): 93 | for k in range(3): 94 | new_im[i][j][k] = second[k] 95 | for j in range(cols, int(cols * (3/2))): 96 | for k in range(3): 97 | new_im[i][j][k] = third[k] 98 | for j in range(int(cols * (3/2)), cols * 2): 99 | for k in range(3): 100 | new_im[i][j][k] = fourth[k] 101 | 102 | 103 | r = im[int(rows/2)] 104 | first = r[0] 105 | second = r[int(cols/4)] 106 | third = r[int(cols/2)] 107 | fourth = r[int(3 * cols/4)] 108 | 109 | for i in range(rows, int(rows * (3/2))): 110 | for j in range(int(cols/2)): 111 | for k in range(3): 112 | new_im[i][j][k] = first[k] 113 | for j in range(int(cols/2), cols): 114 | for k in range(3): 115 | new_im[i][j][k] = second[k] 116 | for j in range(cols, int(cols * (3/2))): 117 | for k in range(3): 118 | new_im[i][j][k] = third[k] 119 | for j in range(int(cols * (3/2)), cols * 2): 120 | for k in range(3): 121 | new_im[i][j][k] = fourth[k] 122 | 123 | r = im[int(3 * rows/4)] 124 | first = r[0] 125 | second = r[int(cols/4)] 126 | third = r[int(cols/2)] 127 | fourth = r[int(3 * cols/4)] 128 | 129 | for i in range(int(rows * (3/2)), rows * 2): 130 | for j in range(int(cols/2)): 131 | for k in range(3): 132 | new_im[i][j][k] = first[k] 133 | for j in range(int(cols/2), cols): 134 | for k in range(3): 135 | new_im[i][j][k] = second[k] 136 | for j in range(cols, int(cols * (3/2))): 137 | for k in range(3): 138 | new_im[i][j][k] = third[k] 139 | for j in range(int(cols * (3/2)), cols * 2): 140 | for k in range(3): 141 | new_im[i][j][k] = fourth[k] 142 | 143 | return new_im 144 | 145 | # given an rgb image as a regular python list, converts it into a numpy array image 146 | def make_image(rgbs): 147 | 148 | rows = len(rgbs) 149 | cols = len(rgbs[0]) 150 | 151 | new_im = np.zeros(((rows, cols, 3))) 152 | 153 | # convert to numpy array and scale the image back up 154 | for i in range(rows): 155 | for j in range(cols): 156 | for k in range(3): 157 | new_im[i][j][k] = rgbs[i][j][k] 158 | 159 | new_im = scale_up(new_im) 160 | 161 | return new_im 162 | 163 | def show_image(pixels, name): 164 | 165 | # Create a PIL image from the NumPy array 166 | image = Image.fromarray(pixels.astype('uint8'), 'RGB') 167 | 168 | image_name = 'images/' + name + '.png' 169 | 170 | # Save the image 171 | image.save(image_name) 172 | image.show() 173 | 174 | def scale_up(image): 175 | 176 | rows = len(image) 177 | cols = len(image[0]) 178 | scale = 256/r_num 179 | new_im = np.zeros(((rows, cols, 3))) 180 | 181 | for i in range(rows): 182 | for j in range(rows): 183 | for k in range(3): 184 | new_im[i][j][k] = image[i][j][k] * scale 185 | 186 | return new_im 187 | 188 | # since we're having to use a scaled down version (only 64 or 16 color values), need to scale down image 189 | def scale_down(image): 190 | 191 | rows = len(image) 192 | cols = len(image[0]) 193 | scale = 256/r_num 194 | new_im = np.zeros(((rows, cols, 3))) 195 | 196 | for i in range(rows): 197 | for j in range(rows): 198 | for k in range(3): 199 | new_im[i][j][k] = floor(image[i][j][k] / scale) 200 | 201 | return new_im 202 | 203 | def get_image(): 204 | 205 | pixels = np.array([[[17, 17, 17], [240, 17, 17]], [[17, 240, 17], [17, 17, 240]]]) 206 | scaled = scale_down(pixels) 207 | 208 | """ 209 | # Windows looking symbol 210 | pixels = np.array([[[250, 5, 5], [5, 250, 5]], [[5, 5, 250], [250, 250, 5]]]) 211 | scaled = scale_down(pixels) 212 | """ 213 | 214 | return scaled 215 | 216 | def get_image4(): 217 | 218 | pixels = np.array([[[239, 239, 239], [239, 239, 239], [239, 239, 239], [239, 239, 239]], 219 | [[239, 239, 239], [239, 239, 239], [239, 239, 239], [239, 239, 239]], 220 | [[239, 239, 239], [239, 239, 239], [239, 239, 239], [239, 239, 239]], 221 | [[239, 239, 239], [239, 239, 239], [239, 239, 239], [239, 239, 239]]]) 222 | 223 | """ 224 | # 4test w16 and changed to less extreme vals 225 | pixels = np.array([[[239, 16, 16], [239, 100, 100], [239, 175, 175], [230, 230, 230]], 226 | [[175, 16, 16], [16, 16, 100], [16, 16, 239], [175, 239, 175]], 227 | [[100, 16, 16], [16, 16, 150], [16, 16, 200], [100, 239, 100]], 228 | [[16, 16, 16], [16, 100, 16], [16, 175, 16], [16, 239, 16]]]) 229 | """ 230 | """ 231 | # 4test 232 | pixels = np.array([[[250, 5, 5], [250, 100, 100], [250, 175, 175], [235, 235, 235]], 233 | [[175, 5, 5], [5, 5, 100], [5, 5, 250], [175, 250, 175]], 234 | [[100, 5, 5], [5, 5, 150], [5, 5, 200], [100, 250, 100]], 235 | [[5, 5, 5], [5, 100, 5], [5, 175, 5], [5, 250, 5]]]) 236 | """ 237 | 238 | """ 239 | pixels = np.array([[[250, 5, 5], [200, 5, 5], [150, 5, 5], [100, 5, 5]], 240 | [[200, 5, 5], [5, 5, 100], [5, 5, 250], [150, 5, 5]], 241 | [[150, 5, 5], [5, 5, 150], [5, 5, 200], [200, 5, 5]], 242 | [[100, 5, 5], [150, 5, 5], [200, 5, 5], [250, 5, 5]]]) 243 | """ 244 | 245 | scaled = scale_down(pixels) 246 | 247 | return scaled 248 | 249 | 250 | def rgb_to_theta(rgb): 251 | 252 | r, g, b = rgb 253 | theta = (pi/2) * ((r/r_num) + (g/g_num) + (b/b_num)) 254 | #print("Theta is ", theta) 255 | return theta 256 | 257 | def theta_to_rgb(theta): 258 | 259 | r = floor(theta/(pi/(r_num * 2))) 260 | theta = theta - r*(pi/(r_num * 2)) 261 | 262 | g = floor(theta/(pi/(g_num * 2))) 263 | theta = theta - g*(pi/(g_num * 2)) 264 | 265 | b = floor(theta/(pi/(b_num * 2))) 266 | 267 | return [r,g,b] 268 | 269 | def test_it(): 270 | 271 | list = [] 272 | for i in range(2): 273 | for j in range(2): 274 | for k in range(2): 275 | list.append([i, j, k]) 276 | 277 | i = 0 278 | for elem in list: 279 | print("i ============== ", i) 280 | i += 1 281 | print(elem) 282 | theta = rgb_to_theta(elem) 283 | theta_to_rgb(theta) 284 | 285 | def test_image(): 286 | 287 | im = get_image() 288 | im = scale_up(im) 289 | 290 | for i in range(7): 291 | im = double_size(im) 292 | 293 | show_image(im, "aman_test") 294 | -------------------------------------------------------------------------------- /images/10000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/10000.png -------------------------------------------------------------------------------- /images/100000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/100000.png -------------------------------------------------------------------------------- /images/2x2_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/2x2_black.png -------------------------------------------------------------------------------- /images/2x2_w64_1-000-000-000_All_three_s4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/2x2_w64_1-000-000-000_All_three_s4.png -------------------------------------------------------------------------------- /images/2x2_w64_10-000-000_RED.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/2x2_w64_10-000-000_RED.png -------------------------------------------------------------------------------- /images/2x2_w64_100-000-000_All_THREE.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/2x2_w64_100-000-000_All_THREE.png -------------------------------------------------------------------------------- /images/2x2_w64_100-000-000_All_three_s4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/2x2_w64_100-000-000_All_three_s4.png -------------------------------------------------------------------------------- /images/2x2_w64_100-000-000_BLACK.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/2x2_w64_100-000-000_BLACK.png -------------------------------------------------------------------------------- /images/2x2_w64_100-000-000_RED.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/2x2_w64_100-000-000_RED.png -------------------------------------------------------------------------------- /images/4test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/4test.png -------------------------------------------------------------------------------- /images/4test_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/4test_16.png -------------------------------------------------------------------------------- /images/4test_16_WHITE.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/4test_16_WHITE.png -------------------------------------------------------------------------------- /images/Four_1-000-000-000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/Four_1-000-000-000.png -------------------------------------------------------------------------------- /images/Four_10-000-000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/Four_10-000-000.png -------------------------------------------------------------------------------- /images/Four_100-000-000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/Four_100-000-000.png -------------------------------------------------------------------------------- /images/Four_1000000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/Four_1000000.png -------------------------------------------------------------------------------- /images/Four_5-000-000-000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/Four_5-000-000-000.png -------------------------------------------------------------------------------- /images/Four_w16_1-000-000-000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/Four_w16_1-000-000-000.png -------------------------------------------------------------------------------- /images/Four_w16_1-000-000-000_changed_to_less_extreme_239_and_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/Four_w16_1-000-000-000_changed_to_less_extreme_239_and_16.png -------------------------------------------------------------------------------- /images/Four_w16_100-000-000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/Four_w16_100-000-000.png -------------------------------------------------------------------------------- /images/Four_w16_100-000-000_SHIFTED.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/Four_w16_100-000-000_SHIFTED.png -------------------------------------------------------------------------------- /images/Four_w16_100-000-000_changed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/Four_w16_100-000-000_changed.png -------------------------------------------------------------------------------- /images/aman_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/aman_test.png -------------------------------------------------------------------------------- /images/ijijiijjij.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/ijijiijjij.png -------------------------------------------------------------------------------- /images/test_4x4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/test_4x4.png -------------------------------------------------------------------------------- /images/w64_1-000-000-000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/w64_1-000-000-000.png -------------------------------------------------------------------------------- /images/w64_1-000-000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/w64_1-000-000.png -------------------------------------------------------------------------------- /images/w64_10-000-000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/w64_10-000-000.png -------------------------------------------------------------------------------- /images/w64_100-000-000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/w64_100-000-000.png -------------------------------------------------------------------------------- /images/w64_100-000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/w64_100-000.png -------------------------------------------------------------------------------- /images/w64_10000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/w64_10000.png -------------------------------------------------------------------------------- /images/w64_5-000-000-000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/w64_5-000-000-000.png -------------------------------------------------------------------------------- /images/w64_original.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/w64_original.png -------------------------------------------------------------------------------- /images/~$4_original.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/images/~$4_original.png -------------------------------------------------------------------------------- /main4.py: -------------------------------------------------------------------------------- 1 | import i_theta 2 | import image_testing 3 | from math import pi 4 | 5 | if __name__ == '__main__': 6 | 7 | image = image_testing.get_image4() 8 | 9 | print("The original image was: ", image) 10 | size = len(image) 11 | 12 | angles = [] 13 | # convert all rgb pixel values into angles in [0, pi/2] 14 | for i in range(size): 15 | for j in range(size): 16 | angles.append((image_testing.rgb_to_theta(image[i][j]))) 17 | 18 | print("The angles for the original image: ", angles) 19 | 20 | new_angles = i_theta.run_4(angles) 21 | 22 | print("The returned angles are: ", new_angles) 23 | 24 | im = [] 25 | i = 0 26 | # converting all the recovered angles, back into rgb values 27 | for ang in new_angles: 28 | 29 | rgb = image_testing.theta_to_rgb(ang) 30 | print(rgb) 31 | if (i % 4 == 0): 32 | row = [] 33 | 34 | row.append(rgb) 35 | 36 | if (i % 4 == 3): 37 | im.append(row) 38 | 39 | i += 1 40 | 41 | new_image = image_testing.make_image(im) 42 | 43 | for i in range(6): 44 | new_image = image_testing.double_size4(new_image) 45 | 46 | image_testing.show_image(new_image, "Four_w16_100-000-000_SHIFTED") 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /main_test.py: -------------------------------------------------------------------------------- 1 | import i_theta 2 | import image_testing 3 | from math import pi 4 | 5 | if __name__ == '__main__': 6 | 7 | image = image_testing.get_image() 8 | 9 | print("The original image was: ", image) 10 | size = len(image) 11 | 12 | angles = [] 13 | # convert all rgb pixel values into angles in [0, pi/2] 14 | for i in range(size): 15 | for j in range(size): 16 | angles.append((image_testing.rgb_to_theta(image[i][j]))) 17 | 18 | print("The angles for the original image: ", angles) 19 | 20 | new_angles = i_theta.run(angles) 21 | 22 | print("The returned angles are: ", new_angles) 23 | 24 | im = [] 25 | i = 0 26 | # converting all the recovered angles, back into rgb values 27 | for ang in new_angles: 28 | 29 | rgb = image_testing.theta_to_rgb(ang) 30 | print(rgb) 31 | if (i % 2 == 0): 32 | row = [] 33 | 34 | row.append(rgb) 35 | 36 | if (i % 2 != 0): 37 | im.append(row) 38 | 39 | i += 1 40 | 41 | new_image = image_testing.make_image(im) 42 | 43 | for i in range(7): 44 | new_image = image_testing.double_size(new_image) 45 | 46 | image_testing.show_image(new_image, "ijijiijjij") 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /pil_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mharding15/Quantum-Image-Processor/8d939a577da8435fbffeb3b42c8b517c4ea3707a/pil_red.png -------------------------------------------------------------------------------- /secondTest.md: -------------------------------------------------------------------------------- 1 |

Second Test

2 | 3 | I am doing a test of making the markdown file on github directly. 4 | 5 | This is a test of making a **markdown** file in *github*. 6 | 7 | I am going to add an image below, 8 | 9 | ![First Image](images/100000.png) 10 | 11 | The end. 12 | 13 | -------------------------------------------------------------------------------- /test.md: -------------------------------------------------------------------------------- 1 |

The Title is here

2 | 3 | This is a test of making a **markdown** file in *github*. 4 | 5 | I am going to add an image below, 6 | 7 | ![First Image](images/100000.png) 8 | 9 | The end. -------------------------------------------------------------------------------- /testing_stuff.py: -------------------------------------------------------------------------------- 1 | # Import the Qiskit SDK 2 | from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister 3 | from qiskit import execute, Aer 4 | 5 | num_measurements = 10000 6 | 7 | def run(): 8 | 9 | # Create a Quantum Register with 2 qubits. 10 | q = QuantumRegister(2) 11 | # Create a Classical Register with 2 bits. 12 | c = ClassicalRegister(2) 13 | # Create a Quantum Circuit 14 | qc = QuantumCircuit(q, c) 15 | 16 | # Add a H gate on qubit 0, putting this qubit in superposition. 17 | qc.h(q[0]) 18 | qc.h(q[1]) 19 | 20 | qc.measure(q, c) 21 | 22 | #print("Aer backends: ", Aer.backends()) 23 | 24 | backend_sim = Aer.get_backend('qasm_simulator') 25 | 26 | job_sim = execute(qc, backend_sim, shots=num_measurements) 27 | result_sim = job_sim.result() 28 | 29 | print(result_sim.get_counts(qc)) 30 | --------------------------------------------------------------------------------