QuantikzPicture

Here we define methods which converts QuantumCircuit object into quantikz picture. It returns object in TikzPicture.jl. Please refer its document to save pictures.

Documents

GroverAlgorithm.add_gate_column!Function
add_gate_column!(qubit_lines::Vector{Vector{String}}, gate::AbstractQuantumGate, nqubits::Int)

Adds a single "time slice" (column) of the given gate to all qubit lines in the circuit.

  • qubit_lines: A vector of string vectors, where each sub-vector represents the sequence of LaTeX commands for a specific qubit.
  • gate: The quantum gate object to be converted and added.
  • nqubits: Total number of qubits in the circuit.

the function determines the type of the gate and appends the appropriate LaTeX command to the corresponding qubit lines:

  • For the qubit(s) acted upon by the gate, appropriate LaTeX commands (like \gate, \ctrl, \targ) are appended.
  • For all other qubits, a wire command (\qw) is appended to maintain column alignment across the circuit.
source
GroverAlgorithm.build_circuit_matrix_packedMethod
build_circuit_matrix_packed(circuit::QuantumCircuit) -> Vector{Vector{String}}

Builds the circuit representation using the packed layout. Gates that don't interfere with each other are placed in the same column.

source
GroverAlgorithm.build_circuit_matrix_serialMethod
build_circuit_matrix_serial(circuit::QuantumCircuit) -> Vector{Vector{String}}

Builds the circuit representation using the serial layout (original behavior). Each gate occupies its own column.

source
GroverAlgorithm.get_involved_qubitsFunction
get_involved_qubits(gate::AbstractQuantumGate) -> (Int, Int)

Returns the range of qubits that a gate visually occupies (min, max). For gates like CNOT, this includes all qubits between control and target, as the control line visually crosses intermediate qubits.

source
GroverAlgorithm.get_latex_commandsFunction
get_latex_commands(gate::AbstractQuantumGate, nqubits::Int) -> Vector{String}

Returns a vector of LaTeX commands for all qubits for the given gate. The vector has length nqubits, where each element is the LaTeX command for that qubit line (e.g., "\gate{H}", "\ctrl{2}", "\qw", etc.).

source
GroverAlgorithm.to_quantikzMethod
to_quantikz(circuit::QuantumCircuit; layout::Symbol=:packed) -> String

Generates a complete LaTeX string wrapped in a quantikz environment.

Arguments

  • circuit::QuantumCircuit: The quantum circuit to visualize.
  • layout::Symbol: Layout mode for the circuit.
    • :serial (or :horizontal): One gate per column (original behavior).
    • :packed (or :parallel, :vertical): Pack non-overlapping gates in the same column (default).

This function:

  1. Iterates through all gates in the circuit.
  2. Builds an internal representation of columns for each qubit.
  3. Uses initial state labels from circuit.initial_states for qubit labels.
  4. Joins the commands with & separators and wraps them in LaTeX boilerplate.

Returns

  • A String containing the full LaTeX source code.
source
GroverAlgorithm.to_tikz_pictureMethod
to_tikz_picture(circuit::QuantumCircuit; layout::Symbol=:packed) -> TikzPicture

Convert a QuantumCircuit object into a TikzPicture that represents the quantum circuit diagram using the quantikz LaTeX package.

Arguments

  • circuit::QuantumCircuit: The quantum circuit to visualize.
  • layout::Symbol: Layout mode for the circuit.
    • :serial (or :horizontal): One gate per column (original behavior).
    • :packed (or :parallel, :vertical): Pack non-overlapping gates in the same column (default).

The function processes each gate in the circuit and constructs the corresponding LaTeX code for each qubit line, using initial state labels from circuit.initial_states, ensuring proper alignment and formatting for multi-qubit gates. The resulting TikzPicture can be rendered in LaTeX documents to visualize the quantum circuit.

source