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.
GroverAlgorithm.build_circuit_matrix_packed — Method
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.
GroverAlgorithm.build_circuit_matrix_serial — Method
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.
GroverAlgorithm.get_involved_qubits — Function
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.
GroverAlgorithm.get_latex_commands — Function
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.).
GroverAlgorithm.to_quantikz — Method
to_quantikz(circuit::QuantumCircuit; layout::Symbol=:packed) -> StringGenerates 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:
- Iterates through all gates in the
circuit. - Builds an internal representation of columns for each qubit.
- Uses initial state labels from
circuit.initial_statesfor qubit labels. - Joins the commands with
&separators and wraps them in LaTeX boilerplate.
Returns
- A
Stringcontaining the full LaTeX source code.
GroverAlgorithm.to_tikz_picture — Method
to_tikz_picture(circuit::QuantumCircuit; layout::Symbol=:packed) -> TikzPictureConvert 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.