Skip to content

loqs.tools.pygstitools

A collection of tools using/for pyGSTi.

Classes

Functions

convert_circuit_to_image

convert_circuit_to_image(circuit: Circuit, gatename_conversion: Mapping[str, str | Sequence[str]], lstick_values: Sequence[str | None] | None = None, include_qubits_in_lsticks: bool = True)

Convert a pyGSTi Circuit to a PNG image.

Requires loqs[visualization] and pdflatex.

Parameters:

Name Type Description Default
circuit Circuit

pyGSTi Circuit to convert. Attainable via circuit.

required
gatename_conversion Mapping[str, str | Sequence[str]] required
lstick_values Sequence[str | None] | None

See convert_circuit_to_quantikz(), by default None

None
include_qubits_in_lsticks bool

See convert_circuit_to_quantikz(), by default True

True

convert_circuit_to_qiskit_draw

convert_circuit_to_qiskit_draw(circuit: Circuit, gatename_conversion: Mapping[str, str] | None = None, placeholder_gate: str = 'Gi') -> str

Convert a pyGSTi Circuit to a Qiskit draw() string.

Requires loqs[visualization].

Parameters:

Name Type Description Default
circuit Circuit

pyGSTi Circuit to convert. Attainable via circuit.

required
gatename_conversion Mapping[str, str] | None

See pygsti.circuits.Circuit.convert_to_openqasm, by default None

None
placeholder_gate str

Gate label to use if not provided in gatename_conversion, by default "Gi"

'Gi'

Returns:

Type Description
str

The output of qiskit.QuantumCircuit.draw()


convert_circuit_to_quantikz

convert_circuit_to_quantikz(circuit: Circuit, gatename_conversion: Mapping[str, str | Sequence[str]], lstick_values: Sequence[str | None] | None = None, include_qubits_in_lsticks: bool = True, full_document: bool = False, compress_layers: bool = True) -> str

Convert a pyGSTi Circuit to a quantikz string.

Parameters:

Name Type Description Default
circuit Circuit

pyGSTi Circuit to convert. Attainable via circuit.

required
gatename_conversion Mapping[str, str | Sequence[str]]

A conversion between gate labels and the corresponding quantikz input. For single qubit gates, this should just be the gate name to appear in gate boxes. Note that "X" gates are replaced with \targ{} automatically. For two-qubit gates, this should be a list of strings, where entries in ["ctrl", "octrl", "targ"] are a control, open control, or target, respectively. Any other entry is just treated as a gate name for a controlled gate. For measurements, this is a string with the format: "meter [<basis>] [reset <ket value>]". Starting with "meter" puts the \meter{} in quantikz. The second argument is an optional basis label that is inserted above the meter symbol. Also optional is reset, which will insert a new line with a ket label that contains the value of <ket value>. If "reset" is provided, the ket value must be provided.

required
lstick_values Sequence[str | None] | None

Strings to include in the starting \lstick{} entries. Entries can be None to skip that line, allowing later entries to be set without setting them all, by default None

None
include_qubits_in_lsticks bool

Whether to include qubit labels (True, the default) or not (False) in the starting \lstick{} entries, by default True

True
full_document bool

Whether to include a document preamble (True) or just the quantikz code (False, default) when generating the final string. The True option is useful if you want a self-contained TeX string that can be compiled, by default False

False

Returns:

Type Description
str

The quantikz string ready for TeX compiling