示例#1
0
def compiletoquil(myprogram):
    devices = get_devices(as_dict=True)
    agave = devices['8Q-Agave']
    compiler = CompilerConnection(agave)

    print('\n# Original pyQuil program,\n\n', myprogram)

    job_id = compiler.compile_async(myprogram)
    job = compiler.wait_for_job(job_id)

    print('\n# Compiled quil code,\n\n', job.compiled_quil())
    print('# gate volume', job.gate_volume())
    print('# gate depth', job.gate_depth())
    print('# topological swaps', job.topological_swaps())
    print('# program fidelity', job.program_fidelity())
    print('# multiqubit gate depth', job.multiqubit_gate_depth())
    print('\n# End of compiling info\n')

    return  #myprogram, job.compiled_quil()
示例#2
0
X 1
X 0
X 1
X 0
X 1
X 0
X 1
X 0
X 1
X 0
X 1
X 0
X 1
X 0
X 1
X 0
X 1
X 0
X 1
X 0
X 1
PRAGMA END_PRESERVE_BLOCK
#   and read out the results
MEASURE 0 [0]
MEASURE 1 [1]""")
    job_id = compiler.compile_async(p)
    job = compiler.wait_for_job(job_id)
    print(job.compiled_quil())
    data_qpu = qpu.run(p, trials=1024)
    print(distribution(data_qpu))
def main():
    qvm = QVMConnection()
    agave = get_devices(as_dict=True)['8Q-Agave']
    qvm_noisy = QVMConnection(agave)
    print(
        "Timestamp, Singlet (Wavefunction), Triplet (Wavefunction), Singlet (QVM), Triplet (QVM),"
        "Singlet (Noise), Triplet (Noise), 00 (Noise), 11 (Noise),"
        "Singlet (Compiled on QVM), Triplet (Compiled on QVM), 00 (Compiled on QVM), 11 (Compiled on QVM),"
    )

    # Truncate file with compiled code
    open(FILENAME, "w").close()
    # Rotation
    for t in range(0, 50):  # ns
        p = create_singlet_state()
        add_switch_to_singlet_triplet_basis_gate_to_program(p)
        w_larmor = 0.46  # 4.6e8 1/s as determined in the experiment
        p.inst(PHASE(w_larmor * t, 0))
        p.inst(("SWITCH_TO_SINGLET_TRIPLET_BASIS", 0, 1))
        wavefunction = qvm.wavefunction(p)
        probs = wavefunction.get_outcome_probs()

        p.measure(0, 0)
        p.measure(1, 1)
        # Run on a perfect QVM (no noise)
        data = qvm.run(p, trials=1000)

        # simulate physical noise on QVM
        data_noisy = qvm_noisy.run(p, trials=1000)
        noisy_data_distr = distribution(data_noisy)

        agave = get_devices(as_dict=True)['8Q-Agave']
        compiler = CompilerConnection(agave)
        job_id = compiler.compile_async(p)
        # wait_for_job has print statement
        # using this workaround to suppress it
        import sys, os
        _old_stdout = sys.stdout
        with open(os.devnull, 'w') as fp:
            sys.stdout = fp
            job = compiler.wait_for_job(
                job_id)  # This is the only line that matters
        sys.stdout = _old_stdout

        # Run code compiled for 8Q-Agave on a noisy QVM
        # Per example on https://github.com/rigetticomputing/pyquil/blob/master/examples/run_quil.py
        p_compiled = Program(job.compiled_quil())
        with open(FILENAME, "a") as fp:
            fp.write("Timestep: %s\n" % t)
            fp.write("%s" % job.compiled_quil())
            fp.write("\n")
        data_compiled = qvm_noisy.run(p_compiled, trials=1000)
        compiled_data_distr = distribution(data_compiled)

        print("%s, %s, %s, %s, %s, %s, %s, %s ,%s, %s, %s, %s, %s" % (
            t,
            probs['01'],
            probs['10'],
            distribution(data).get((0, 1), 0),
            distribution(data).get((1, 0), 0),
            noisy_data_distr.get((0, 1), 0),
            noisy_data_distr.get((1, 0), 0),
            noisy_data_distr.get((0, 0), 0),
            noisy_data_distr.get((1, 1), 0),
            compiled_data_distr.get((0, 1), 0),
            compiled_data_distr.get((1, 0), 0),
            compiled_data_distr.get((0, 0), 0),
            compiled_data_distr.get((1, 1), 0),
        ))