quairkit.core.latex

Source file for transforming OperatorInfo to string representing quantikz.

Quantikz is a LaTeX package for typesetting quantum circuit diagrams. See https://ctan.org/pkg/quantikz for more details.

quairkit.core.latex.code_to_str(code, begin_code=None)

Translate the given quantikz code into complete LaTeX commands

Parameters:
code : Dict[int, List[str]]

The quantikz code to translate, where the key i is the i-th line of the code, and the value is the list of gate commands on that line.

begin_code : Dict[int, str] | None

a dictionary or a string representing the beginning code for each line. Defaults to empty.

Returns:

The complete LaTeX code for the given quantikz code, connected by & and \

Return type:

str

class quairkit.core.latex.OperatorListDrawer(style, decimals)

Latex plot for a list of operators in QuAIRKit

Parameters:
style : str

the plot style of the circuit, can be ‘standard’, ‘compact’ or ‘detailed’.

Note

The LaTeX package used is [quantikz](https://ctan.org/pkg/quantikz).

fill_all()

Fill empty &s for all lines covered by the current codes

clone()

Clone the current drawer

property code : dict[int, list[str]]

The dictionary of the current circuit code

Note

Empty lines are filled with ‘{}’

add_end(rstick_str=None)

Add end sticks to the circuit

Parameters:
rstick_str : Dict[int, str] | None

The string to add to the right stick at idx, such as ket{0}

plot(dpi=300, print_code=True, begin_code=None)

Plot the given quantikz code using LaTeX

Parameters:
dpi : int

The DPI to use for the resulting image. Defaults to 300.

print_code : bool

Whether to print the code to the console. Defaults to True.

begin_code : Dict[int, str] | None

a dictionary or a string representing the beginning code for each line. Defaults to empty.

Returns:

The image object of the plot

Return type:

Image

append(info)

Append an operator to the current circuit code

Parameters:
info : OperatorInfoType

The information of the operator to append

draw_layer(list_info, name, depth=1)

Give the drawer for a layer, i.e., a list of operators

Parameters:
list_info : List[OperatorInfoType]

The list of operators to draw

name : str

The name of the layer.

depth : int

The depth of the layer. Defaults to 1.

Note

if name is given, the layer name will be added to the code by - command ‘gate’ with layer name if the style is ‘compact’; - command ‘gate’ with matrix if the style is ‘detailed’ and matrix is given. - command ‘gategroup’ with name above if the style is ‘standard’;