Exemplo n.º 1
0
def to_latex(circuit, settings=None):
    """
    Translates a given pyquil Program to a TikZ picture in a Latex document.

    :param Program circuit: The circuit to be drawn, represented as a pyquil program.
    :param dict settings: An optional dictionary with settings for drawing the circuit. See `get_default_settings`
     in `latex_config` for more information about what settings should contain.
    :return: LaTeX document string which can be compiled.
    :rtype: string
    """
    if settings is None:
        settings = get_default_settings()
    text = header(settings)
    text += body(circuit, settings)
    text += footer()
    return text
Exemplo n.º 2
0
def test_to_latex():
    """A test to give full coverage of latex_generation and latex_config."""
    qubits = range(3)
    p = Program()
    p.inst(X(qubits[0]), Y(qubits[0]), CZ(qubits[0], qubits[2]),
           SWAP(qubits[0], qubits[1]), MEASURE(qubits[0], None),
           CNOT(qubits[2], qubits[0]))
    _ = to_latex(p)

    # Modify settings to access non-standard control paths.
    settings = get_default_settings()
    settings['gates']['AllocateQubitGate']['draw_id'] = True
    settings['gate_shadow'] = None
    _ = to_latex(p, settings)

    settings['control']['shadow'] = True
    _ = to_latex(p, settings)