def test_render_latex():
    # TODO: Double check this circuit is correct
    circ = qf.addition_circuit(['a[0]', 'a[1]', 'a[2]', 'a[3]'],
                               ['b[0]', 'b[1]', 'b[2]', 'b[3]'],
                               ['cin', 'cout'])
    order = ['cin', 'a[0]', 'b[0]', 'a[1]', 'b[1]', 'a[2]', 'b[2]', 'a[3]',
             'b[3]', 'cout']
    # order = ['cin', 'a0', 'a1', 'a2', 'a3', 'b0', 'b1', 'b2', 'b3','cout']

    latex = qf.circuit_to_latex(circ, order)

    qf.render_latex(latex)
Exemple #2
0
def test_pyquil_to_latex():
    prog = pyquil.Program(BELL_STATE_MEASURE)
    circ = qf.forest.pyquil_to_circuit(prog)
    latex = qf.circuit_to_latex(circ)
    img = qf.render_latex(latex)
    assert img is not None
    sys.exit()

if shutil.which('pdftocairo') is None:
    print('Failed: External dependency `pdftocairo` not found. '
          'Install `poppler`.')
    sys.exit()

# Display Bell state preparation
qf.circuit_to_image(qf.ghz_circuit([0, 1])).show()

# 4-qubit GHZ state preparation
qf.circuit_to_image(qf.ghz_circuit([0, 1, 2, 3])).show()

# 4-qubit ripple add
circ = qf.addition_circuit(['a[0]', 'a[1]', 'a[2]', 'a[3]'],
                           ['b[0]', 'b[1]', 'b[2]', 'b[3]'],
                           ['cin', 'cout'])
order = ['cin', 'a[0]', 'b[0]', 'a[1]', 'b[1]', 'a[2]', 'b[2]', 'a[3]',
         'b[3]', 'cout']
latex = qf.circuit_to_latex(circ, order)
img = qf.render_latex(latex)
img.show()

# Visualize pyquil protoquil programs
prog = Program()
prog = prog.inst(Z(0))
prog = prog.inst(CNOT(0, 1))
prog = prog.inst(CZ(0, 1))
prog = prog.inst(CCNOT(0, 1, 2))
qf.forest.pyquil_to_image(prog).show()