def timeBenchmarks(): """ Runs Benchmarks for Grover's algorithm for both the Circuit-Builder implementation and the Pre-defined Circuit implementation. It also plots a graph for comparison. """ max_qbits = 8 # the limit of sparse matrices qbits = np.arange(2, max_qbits + 1, 1) times = np.zeros((3, len(qbits))) for q in qbits: t1 = time.time() Presentation.Grover_Circuit(q, [3], plot_results=False) t2 = time.time() times[0, q - 2] = t2 - t1 t1 = time.time() Presentation.LazyGroverDemo(q, [3], plot_results=False) t2 = time.time() times[1, q - 2] = t2 - t1 t1 = time.time() g = Grover() g.run_circuit(q, 1, 'm') t2 = time.time() times[2, q - 2] = t2 - t1 plt.plot(qbits, times[0], label='Sparse') plt.plot(qbits, times[1], label='Lazy') plt.plot(qbits, times[2], label='Numpy') plt.title( "Runtime of Grover's Algorithm over Number of Qubits in the system") plt.xlabel("Number of Qubits") plt.ylabel("Runtime (s)") plt.yscale("log") plt.legend() plt.show()
def actual_builder(algorithm): """ Function which builds the circuit as prompted by the user. """ if algorithm == 'g': size = int(input("\nPlease enter the size of the desired circuit\n")) state = int(input("\nPlease enter the desired state\n")) if state < 2**size: Presentation.LazyGroverDemo(size, [state]) else: print( "\nSomething went wrong. \nThe desired state might be out of bounds" ) actual_builder('grover') elif algorithm == 'BV': mystery_string = str( input( "\nPlease enter a mystery bitstring (i.e. a bunch of 1s and 0s)" )) Presentation.Ber_Vaz(mystery_string) print("Your mystery string was:", mystery_string) print("Does it match the qubits in the register?")