AbstractQuantumState
Here we define a struct which represents initial quantum states. By using these definitions, it reflected not only in QuantumCircuit calculation but also in quantikz picture. Available states are common to ITensorMPS.jl.
Documents
GroverAlgorithm.AbstractInitialState — Type
AbstractInitialStateAbstract type for quantum initial states in a quantum circuit. Provides common interfaces for both ITensors MPS initialization and quantikz visualization.
GroverAlgorithm.BasisState — Type
BasisState(label::String)Represents a computational basis state for quantum circuit initialization.
Fields
label::String: The state label conforming to ITensors' op-defined state names. Common values include "0", "1", "+", "-", "Up", "Dn", etc.
Example
BasisState("0") # |0⟩ state
BasisState("+") # |+⟩ state (equal superposition)GroverAlgorithm.NamedState — Type
NamedState(name::String, latex::String)Represents a quantum state with arbitrary name and LaTeX label for visualization.
Fields
name::String: The state name for ITensors initialization (must be a valid ITensors state).latex::String: The LaTeX representation for quantikz visualization.
Example
NamedState("0", "\psi_0") # Initialized as |0⟩ but displayed as |ψ₀⟩GroverAlgorithm.ProductState — Type
ProductState(labels::Vector{String})Represents a product state where each qubit is individually specified.
Fields
labels::Vector{String}: Vector of state labels, one for each qubit. Each label should conform to ITensors' op-defined state names.
Usage
ProductState is typically used as a single element in the initial_states vector to specify all qubits at once. To specify different states per qubit individually, use a vector of BasisState or NamedState instances instead.
Examples
# Use ProductState as a single element for all qubits:
initial = AbstractInitialState[ProductState(["0", "1", "+"])]
circuit = QuantumCircuit(3, AbstractQuantumGate[], initial)
# To specify per-qubit states individually, use BasisState:
initial = AbstractInitialState[BasisState("0"), BasisState("1"), BasisState("+")]
circuit = QuantumCircuit(3, AbstractQuantumGate[], initial)GroverAlgorithm.to_itensor_state — Method
to_itensor_state(state::AbstractInitialState, nqubits::Int) -> Vector{String}Convert an initial state specification to a vector of state strings for ITensors MPS initialization.
Arguments
state::AbstractInitialState: The initial state specification.nqubits::Int: The total number of qubits in the circuit.
Returns
Vector{String}: A vector of state strings suitable forMPS(sites, states).
Throws
ArgumentError: If the state specification is incompatible with the number of qubits.
Example
to_itensor_state(BasisState("0"), 3) # ["0", "0", "0"]
to_itensor_state(ProductState(["0", "1"]), 2) # ["0", "1"]GroverAlgorithm.to_latex_label — Method
to_latex_label(state::AbstractInitialState, qubit_idx::Int) -> StringGenerate a LaTeX label for the specified qubit in quantikz visualization.
Arguments
state::AbstractInitialState: The initial state specification.qubit_idx::Int: The index of the qubit (1-based).
Returns
String: A LaTeX string for use in\lstick{}.
Example
to_latex_label(BasisState("0"), 1) # "\ket{0}"
to_latex_label(NamedState("0", "\psi"), 1) # "\ket{\psi}"