Exemplo n.º 1
0
def test_quantum_walk():
    init_machine = InitQMachine()
    machine = init_machine.m_machine
    x = machine.cAlloc()

    data = [3, 6, 6, 9, 10, 15, 11, 6]
    #data=[3]
    measure_qubits = pq.QVec()
    grover_cir = pq.quantum_walk_alg(data, x == 6, machine, measure_qubits, 2)
    result = pq.prob_run_dict(grover_cir, measure_qubits)
    print(result)
Exemplo n.º 2
0
    def test_grover1(self):
        init_machine = InitQMachine()
        machine = init_machine.m_machine
        x = machine.cAlloc()

        data = [8, 7, 6, 0, 6, 3, 6, 4, 21, 15, 11, 11, 3, 9, 7]
        measure_qubits = pq.QVec()
        grover_cir = pq.Grover(data, x == 6, machine, measure_qubits, 1)

        # print(grover_cir)
        # draw_qprog(grover_cir, 'pic', filename='D:/cir_grover_1.jpg', verbose=True)
        result = pq.prob_run_dict(grover_cir, measure_qubits)
def cal_circuit(thetas):
    pq.init(pq.QMachineType.CPU)
    qubitlist = pq.qAlloc_many(1)
    prog = pq.QProg()
    for theta, qubit in zip(thetas, qubitlist):
        prog.insert(pq.H(qubit))
        prog.insert(pq.RY(qubit, theta))
    result = pq.prob_run_dict(prog, qubitlist)
    states = []
    probabilities = []
    for key, val in result.items():
        states.append(int(key, 2))
        probabilities.append(val)
    states = np.array(states, 'float')
    probabilities = np.array(probabilities)
    expectation = np.sum(states * probabilities)
    pq.finalize()
    return np.array([expectation])