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?")
Пример #2
0
    """
    t1 = time.time()
    Presentation.Grover_Circuit(5, [3])
    t2 = time.time()
    
    t3 = time.time()
    Presentation.LazyGroverDemo(5, [3])
    t4 = time.time()
    
    print(f'Time taken for sparse implementation: {t2-t1}')
    print(f'Time taken for lazy implementation: {t4-t3}')
    """
    """
    # Measuring the time it takes to apply Grover's Algorithm to circuits of different size.
    times = []
    for i in range(2,9):
        t1 = time.time()
        Presentation.Grover_Circuit(i, [3])
        t2 = time.time()
        times.append(t2-t1)
    plt.scatter([i for i in range(2,9)], times)
    plt.title("Runtime of Grover's Algorithm Compared to Number of Qubits")
    plt.xlabel("Number of Qubits")
    plt.ylabel("Runtime (s)")
    print(times)
    """
    #print('Bernstein-Vazirani Algorithm Example:')
    Presentation.Ber_Vaz('1011')
    #print('QFT example:')
    #Presentation.qft_example()