Home Reference Source
private class | source

_Circ2Tikz

The Circ2Tikz class takes a circuit (list of lists of CircuitItem objects) and turns them into Latex/TikZ code.

It uses the settings dictionary for gate offsets, sizes, spacing, ...

Constructor Summary

Public Constructor
public

constructor(settings: Object, num_lines: number)

Member Summary

Public Members
public
public
public

pos: *

public

Method Summary

Public Methods
public

to_tikz(line: number, circuit: Array<CircuitItem[]>, end: number): string

Generate the TikZ code for one line of the circuit up to a certain gate.

Private Methods
private

_cz_gate(lines: number[]): *

Return the TikZ code for an n-controlled Z-gate.

private

_gate_height(gate: *): number

Return the height to use for this gate.

private

Return the string representation of the gate.

private

_gate_offset(gate: *): number

Return the offset to use after placing this gate and, if no pre_offset is defined, the same offset is used in front of the gate.

private

Return the offset to use before placing this gate.

private

_gate_width(gate: *): number

Return the gate width, using the settings (if available).

private

_line(p1: number, p2: number, line: number): string

Connects p1 and p2, where p1 and p2 are either to qubit line indices, in which case the two most recent gates are connected, or two gate indices, in which case line denotes the line number and the two gates are connected on the given line.

private

_op(line: number, op: number, offset: number): string

Returns the gate name for placing a gate on a line.

private

_phase(line: number, pos: number): string

Places a phase / control circle on a qubit line at a given position.

private

_regular_gate(gate: BasicGate, lines: number[], ctrl_lines: number[]): string

Draw a regular gate.

private

_sqrtswap_gate(lines: number[], ctrl_lines: number[], daggered: boolean): *

Return the TikZ code for a Square-root Swap-gate.

private

_swap_gate(lines: number[], ctrl_lines: number[]): *

Return the TikZ code for a Swap-gate.

private

_x_gate(lines: number[], ctrl_lines: number[]): *

Return the TikZ code for a NOT-gate.

Public Constructors

public constructor(settings: Object, num_lines: number) source

Params:

NameTypeAttributeDescription
settings Object

Dictionary of settings to use for the TikZ image.

num_lines number

Number of qubit lines to use for the entire circuit.

Public Members

public is_quantum: * source

public op_count: * source

public pos: * source

public settings: * source

Public Methods

public to_tikz(line: number, circuit: Array<CircuitItem[]>, end: number): string source

Generate the TikZ code for one line of the circuit up to a certain gate.

It modifies the circuit to include only the gates which have not been drawn. It automatically switches to other lines if the gates on those lines have to be drawn earlier.

Params:

NameTypeAttributeDescription
line number

Line to generate the TikZ code for.

circuit Array<CircuitItem[]>

The circuit to draw.

end number

Gate index to stop at (for recursion).

Return:

string

TikZ code representing the current qubit line and, if it was necessary to draw other lines, those lines as well.

Private Methods

private _cz_gate(lines: number[]): * source

Return the TikZ code for an n-controlled Z-gate.

Params:

NameTypeAttributeDescription
lines number[]

List of all qubits involved.

Return:

*

private _gate_height(gate: *): number source

Return the height to use for this gate.

Params:

NameTypeAttributeDescription
gate *

Return:

number

Height of the gate. (settings['gates'][gate_class_name]['height'])

private _gate_name(gate: BasicGate): string source

Return the string representation of the gate. Tries to use gate.tex_str and, if that is not available, uses str(gate) instead.

Params:

NameTypeAttributeDescription
gate BasicGate

Gate object of which to get the name / latex representation.

Return:

string

Latex gate name.

private _gate_offset(gate: *): number source

Return the offset to use after placing this gate and, if no pre_offset is defined, the same offset is used in front of the gate.

Params:

NameTypeAttributeDescription
gate *

Return:

number

Offset. (settings['gates'][gate_class_name]['offset'])

private _gate_pre_offset(gate: *): number source

Return the offset to use before placing this gate.

Params:

NameTypeAttributeDescription
gate *

Return:

number

Offset to use before the gate. (settings['gates'][gate_class_name]['pre_offset'])

private _gate_width(gate: *): number source

Return the gate width, using the settings (if available).

Params:

NameTypeAttributeDescription
gate *

Return:

number

Width of the gate. (settings['gates'][gate_class_name]['width'])

private _line(p1: number, p2: number, line: number): string source

Connects p1 and p2, where p1 and p2 are either to qubit line indices, in which case the two most recent gates are connected, or two gate indices, in which case line denotes the line number and the two gates are connected on the given line.

Params:

NameTypeAttributeDescription
p1 number

Index of the first object to connect.

p2 number

Index of the second object to connect.

line number

(int or null) Line index - if provided, p1 and p2 are gate indices.

Return:

string

Latex code to draw this / these line(s).

private _op(line: number, op: number, offset: number): string source

Returns the gate name for placing a gate on a line.

Params:

NameTypeAttributeDescription
line number

Line number.

op number
  • nullable: true

Operation number or, by default, uses the current op count.

offset number

Return:

string

Gate name.

private _phase(line: number, pos: number): string source

Places a phase / control circle on a qubit line at a given position.

Params:

NameTypeAttributeDescription
line number

Qubit line at which to place the circle.

pos number

Position at which to place the circle.

Return:

string

Latex string representing a control circle at the given position.

private _regular_gate(gate: BasicGate, lines: number[], ctrl_lines: number[]): string source

Draw a regular gate.

Params:

NameTypeAttributeDescription
gate BasicGate

Gate to draw.

lines number[]

Lines the gate acts on.

ctrl_lines number[]

Control lines.

Return:

string

Latex string drawing a regular gate at the given location

private _sqrtswap_gate(lines: number[], ctrl_lines: number[], daggered: boolean): * source

Return the TikZ code for a Square-root Swap-gate.

Params:

NameTypeAttributeDescription
lines number[]

List of length 2 denoting the target qubit of the Swap gate.

ctrl_lines number[]

List of qubit lines which act as controls.

daggered boolean

Show the daggered one if true.

Return:

*

private _swap_gate(lines: number[], ctrl_lines: number[]): * source

Return the TikZ code for a Swap-gate.

Params:

NameTypeAttributeDescription
lines number[]

List of length 2 denoting the target qubit of the Swap gate.

ctrl_lines number[]

List of qubit lines which act as controls.

Return:

*

private _x_gate(lines: number[], ctrl_lines: number[]): * source

Return the TikZ code for a NOT-gate.

Params:

NameTypeAttributeDescription
lines number[]

List of length 1 denoting the target qubit of the NOT / X gate.

ctrl_lines number[]

List of qubit lines which act as controls.

Return:

*