Exemplo n.º 1
0
def test_run_and_measure_qubits(forest: ForestConnection):
    # The forest fixture (argument) to this test is to ensure this is
    # skipped when a forest web api key is unavailable. You could also
    # pass it to the constructor of WavefunctionSimulator() but it is not
    # necessary.
    wfnsim = WavefunctionSimulator()
    bell = Program(H(0), CNOT(0, 1))
    bitstrings = wfnsim.run_and_measure(bell, qubits=[0, 100], trials=1000)
    assert np.all(bitstrings[:, 1] == 0)
    assert 0.4 < np.mean(bitstrings[:, 0]) < 0.6
Exemplo n.º 2
0
def test_run_and_measure(forest: ForestConnection):
    # The forest fixture (argument) to this test is to ensure this is
    # skipped when a forest web api key is unavailable. You could also
    # pass it to the constructor of WavefunctionSimulator() but it is not
    # necessary.
    wfnsim = WavefunctionSimulator()
    bell = Program(H(0), CNOT(0, 1))
    bitstrings = wfnsim.run_and_measure(bell, trials=1000)
    parity = np.sum(bitstrings, axis=1) % 2
    assert np.all(parity == 0)
Exemplo n.º 3
0
def test_run_and_measure_qubits(client_configuration: QCSClientConfiguration):
    wfnsim = WavefunctionSimulator(client_configuration=client_configuration)
    bell = Program(H(0), CNOT(0, 1))
    bitstrings = wfnsim.run_and_measure(bell, qubits=[0, 100], trials=1000)
    assert np.all(bitstrings[:, 1] == 0)
    assert 0.4 < np.mean(bitstrings[:, 0]) < 0.6
Exemplo n.º 4
0
def test_run_and_measure(client_configuration: QCSClientConfiguration):
    wfnsim = WavefunctionSimulator(client_configuration=client_configuration)
    bell = Program(H(0), CNOT(0, 1))
    bitstrings = wfnsim.run_and_measure(bell, trials=1000)
    parity = np.sum(bitstrings, axis=1) % 2
    assert np.all(parity == 0)
        l += 1
        p = Program()
        ro = p.declare('ro', 'BIT', 2)
        wf1 = WavefunctionSimulator()
        p += u_2_definition
        p += ch_definition
        p += norm_definition
        p += H(0)
        p += NM(np.sqrt(2))(0)
        p += U2(j)(0)
        p += H(1)
        p += PHASE(i, 1)
        p += CH(0, 1)

        result_c.append(wf1.wavefunction(p).get_outcome_probs())
        results = wf1.run_and_measure(p, trials=tr)
        #print(results)
        p = 0
        for k in results:
            if k[1] == 0:
                p += 1
        result_a.append(p)
        result_b.append([i, j])
        p = None
        wf1 = None

for i in range(0, len(result_a)):
    print(result_b[i])
    print(result_a[i] / tr)
    print(result_c[i])
from pyquil import Program
from pyquil.api import WavefunctionSimulator
from pyquil.gates import *

wavefunction_simulator = WavefunctionSimulator()
program = Program()
program = program + X(0)
program = program + H(0)
program = program + H(1)
program = program + CNOT(1, 0)
program = program + H(0)
result = wavefunction_simulator.run_and_measure(program, trials=10)
print(result)