Basis Types
ParametricDFT.AbstractSparseBasis — Type
AbstractSparseBasisAbstract base type for sparse basis representations. All concrete basis types should inherit from this and implement the required interface:
Required methods:
forward_transform(basis, image)- transform image to frequency domaininverse_transform(basis, freq_domain)- inverse transformimage_size(basis)- return supported image dimensionsnum_parameters(basis)- return total parameter countbasis_hash(basis)- return unique hash for basis identification
ParametricDFT.EntangledQFTBasis — Type
EntangledQFTBasis <: AbstractSparseBasisEntangled Quantum Fourier Transform basis with XY correlation.
This basis extends the standard QFT by adding entanglement gates E_k between corresponding row and column qubits. Each entanglement gate has the same form as the M gate in QFT:
E_k = diag(1, 1, 1, e^(i*phi_k))acting on qubits (x{n-k}, y{n-k}), where phi_k is a learnable phase parameter.
Fields
m::Int: Number of qubits for row dimension (image height = 2^m)n::Int: Number of qubits for column dimension (image width = 2^n)tensors::Vector: Circuit parameters (unitary matrices + entanglement gates)optcode::AbstractEinsum: Optimized einsum code for forward transforminverse_code::AbstractEinsum: Optimized einsum code for inverse transformn_entangle::Int: Number of entanglement gates (= min(m, n))entangle_phases::Vector{Float64}: Phase parameters for entanglement gates
Example
# Create default entangled QFT basis for 64×64 images
basis = EntangledQFTBasis(6, 6)
# Create with custom initial entanglement phases
phases = rand(6) * 2π
basis = EntangledQFTBasis(6, 6; entangle_phases=phases)
# Transform an image
freq = forward_transform(basis, image)
# Inverse transform
reconstructed = inverse_transform(basis, freq)ParametricDFT.EntangledQFTBasis — Method
EntangledQFTBasis(m::Int, n::Int, tensors::Vector, n_entangle::Int; entangle_position=:back)Construct an EntangledQFTBasis with custom trained tensors.
Arguments
m::Int: Number of qubits for rowsn::Int: Number of qubits for columnstensors::Vector: Pre-trained circuit parametersn_entangle::Int: Number of entanglement gatesentangle_position::Symbol: Where entanglement gates are placed (:front, :middle, :back)
Returns
EntangledQFTBasis: Basis with custom parameters
ParametricDFT.EntangledQFTBasis — Method
EntangledQFTBasis(m::Int, n::Int; entangle_phases=nothing, entangle_position=:back)Construct an EntangledQFTBasis with default or custom entanglement phases.
Arguments
m::Int: Number of qubits for rows (image height = 2^m)n::Int: Number of qubits for columns (image width = 2^n)entangle_phases::Union{Nothing, Vector{<:Real}}: Initial phases for entanglement gates. If nothing, defaults to zeros (equivalent to standard QFT initially).entangle_position::Symbol: Where to place entanglement gates (:front, :middle, :back)
Returns
EntangledQFTBasis: Basis with entangled QFT circuit parameters
ParametricDFT.MERABasis — Type
MERABasis <: AbstractSparseBasisMulti-scale Entanglement Renormalization Ansatz (MERA) basis with 2D separable topology.
This basis uses m row qubits and n column qubits with hierarchical MERA structures:
- Row MERA: disentangler + isometry layers on row qubits (2*(m-1) gates for m >= 2)
- Column MERA: disentangler + isometry layers on column qubits (2*(n-1) gates for n >= 2)
Fields
m::Int: Number of row qubits (row dimension = 2^m)n::Int: Number of column qubits (col dimension = 2^n)tensors::Vector: Circuit parameters (Hadamard gates + MERA gate tensors)optcode::AbstractEinsum: Optimized einsum code for forward transforminverse_code::AbstractEinsum: Optimized einsum code for inverse transformn_row_gates::Int: Number of row MERA phase gatesn_col_gates::Int: Number of column MERA phase gatesphases::Vector{Float64}: Phase parameters for MERA gates
Example
# Create default MERA basis for 4×4 images (m=2, n=2)
basis = MERABasis(2, 2)
# Create with custom initial phases (4 gates total: 2 row + 2 col)
phases = rand(4) * 2π
basis = MERABasis(2, 2; phases=phases)
# Transform an image
freq = forward_transform(basis, image)
# Inverse transform
reconstructed = inverse_transform(basis, freq)ParametricDFT.MERABasis — Method
MERABasis(m::Int, n::Int, tensors::Vector, n_row_gates::Int, n_col_gates::Int)Construct a MERABasis with custom trained tensors.
Arguments
m::Int: Number of row qubitsn::Int: Number of column qubitstensors::Vector: Pre-trained circuit parametersn_row_gates::Int: Number of row MERA gatesn_col_gates::Int: Number of column MERA gates
Returns
MERABasis: Basis with custom parameters
ParametricDFT.MERABasis — Method
MERABasis(m::Int, n::Int; phases=nothing)Construct a MERABasis with default or custom phases.
Arguments
m::Int: Number of row qubits (row dimension = 2^m)n::Int: Number of column qubits (col dimension = 2^n)phases::Union{Nothing, Vector{<:Real}}: Initial phases for MERA gates. If nothing, defaults to zeros. Length must be nrowgates + ncolgates.
Returns
MERABasis: Basis with MERA circuit parameters
ParametricDFT.QFTBasis — Type
QFTBasis <: AbstractSparseBasisQuantum Fourier Transform basis using tensor network representation.
Fields
m::Int: Number of qubits for row dimension (image height = 2^m)n::Int: Number of qubits for column dimension (image width = 2^n)tensors::Vector: Circuit parameters (unitary matrices)optcode::AbstractEinsum: Optimized einsum code for forward transforminverse_code::AbstractEinsum: Optimized einsum code for inverse transform
Example
# Create default QFT basis for 64×64 images
basis = QFTBasis(6, 6)
# Transform an image
freq = forward_transform(basis, image)
# Inverse transform
reconstructed = inverse_transform(basis, freq)ParametricDFT.QFTBasis — Method
QFTBasis(m::Int, n::Int, tensors::Vector)Construct a QFTBasis with custom trained tensors.
Arguments
m::Int: Number of qubits for rowsn::Int: Number of qubits for columnstensors::Vector: Pre-trained circuit parameters
Returns
QFTBasis: Basis with custom parameters
ParametricDFT.QFTBasis — Method
QFTBasis(m::Int, n::Int)Construct a QFTBasis with default QFT circuit parameters.
Arguments
m::Int: Number of qubits for rows (image height = 2^m)n::Int: Number of qubits for columns (image width = 2^n)
Returns
QFTBasis: Basis with standard QFT circuit parameters
ParametricDFT.TEBDBasis — Type
TEBDBasis <: AbstractSparseBasisTime-Evolving Block Decimation (TEBD) basis with 2D ring topology.
This basis uses m row qubits and n column qubits with two separate rings:
- Row ring: (x1,x2), (x2,x3), ..., (x{m-1},xm), (x_m,x1) for m gates
- Column ring: (y1,y2), (y2,y3), ..., (y{n-1},yn), (y_n,y1) for n gates
Fields
m::Int: Number of row qubits (row dimension = 2^m)n::Int: Number of column qubits (col dimension = 2^n)tensors::Vector: Circuit parameters (TEBD gate tensors)optcode::AbstractEinsum: Optimized einsum code for forward transforminverse_code::AbstractEinsum: Optimized einsum code for inverse transformn_row_gates::Int: Number of row ring phase gates (= m)n_col_gates::Int: Number of column ring phase gates (= n)phases::Vector{Float64}: Phase parameters for TEBD gates
Example
# Create default TEBD basis for 8×8 images (m=3, n=3)
basis = TEBDBasis(3, 3)
# Create with custom initial phases (6 gates total: 3 row ring + 3 col ring)
phases = rand(6) * 2π
basis = TEBDBasis(3, 3; phases=phases)
# Transform an image
freq = forward_transform(basis, image)
# Inverse transform
reconstructed = inverse_transform(basis, freq)ParametricDFT.TEBDBasis — Method
TEBDBasis(m::Int, n::Int, tensors::Vector, n_row_gates::Int, n_col_gates::Int)Construct a TEBDBasis with custom trained tensors.
Arguments
m::Int: Number of row qubitsn::Int: Number of column qubitstensors::Vector: Pre-trained circuit parametersn_row_gates::Int: Number of row ring gatesn_col_gates::Int: Number of column ring gates
Returns
TEBDBasis: Basis with custom parameters
ParametricDFT.TEBDBasis — Method
TEBDBasis(m::Int, n::Int; phases=nothing)Construct a TEBDBasis with default or custom phases.
Arguments
m::Int: Number of row qubits (row dimension = 2^m)n::Int: Number of column qubits (col dimension = 2^n)phases::Union{Nothing, Vector{<:Real}}: Initial phases for TEBD gates. If nothing, defaults to zeros. Length must be m+n for ring topology.
Returns
TEBDBasis: Basis with TEBD circuit parameters
Base.:(==) — Method
Base.:(==)(a::EntangledQFTBasis, b::EntangledQFTBasis)Check equality of two EntangledQFTBasis objects.
Base.:(==) — Method
Base.:(==)(a::MERABasis, b::MERABasis)Check equality of two MERABasis objects.
Base.:(==) — Method
Base.:(==)(a::QFTBasis, b::QFTBasis)Check equality of two QFTBasis objects.
Base.:(==) — Method
Base.:(==)(a::TEBDBasis, b::TEBDBasis)Check equality of two TEBDBasis objects.
ParametricDFT.basis_hash — Method
basis_hash(basis::EntangledQFTBasis)Compute a unique hash identifying this basis configuration and parameters.
Returns
String: SHA-256 hash of the basis parameters
ParametricDFT.basis_hash — Method
basis_hash(basis::MERABasis)Compute a unique hash identifying this basis configuration and parameters.
Returns
String: SHA-256 hash of the basis parameters
ParametricDFT.basis_hash — Method
basis_hash(basis::QFTBasis)Compute a unique hash identifying this basis configuration and parameters.
Returns
String: SHA-256 hash of the basis parameters
ParametricDFT.basis_hash — Method
basis_hash(basis::TEBDBasis)Compute a unique hash identifying this basis configuration and parameters.
Returns
String: SHA-256 hash of the basis parameters
ParametricDFT.forward_transform — Method
forward_transform(basis::EntangledQFTBasis, image::AbstractMatrix)Apply forward entangled QFT transform to convert image to frequency domain.
Arguments
basis::EntangledQFTBasis: The basis to use for transformationimage::AbstractMatrix: Input image (must be size 2^m × 2^n)
Returns
- Frequency domain representation (Complex matrix of same size)
ParametricDFT.forward_transform — Method
forward_transform(basis::MERABasis, image::AbstractMatrix)Apply forward MERA transform to an image.
Arguments
basis::MERABasis: The basis to use for transformationimage::AbstractMatrix: Input image (must be 2^m × 2^n)
Returns
- Transformed representation as matrix (same shape as input)
ParametricDFT.forward_transform — Method
forward_transform(basis::MERABasis, data::AbstractVector)Apply forward MERA transform to a vector.
Arguments
basis::MERABasis: The basis to use for transformationdata::AbstractVector: Input vector (must have length 2^(m+n))
Returns
- Transformed representation (Complex vector of same length)
ParametricDFT.forward_transform — Method
forward_transform(basis::QFTBasis, image::AbstractMatrix)Apply forward transform to convert image to frequency domain.
Arguments
basis::QFTBasis: The basis to use for transformationimage::AbstractMatrix: Input image (must be size 2^m × 2^n)
Returns
- Frequency domain representation (Complex matrix of same size)
ParametricDFT.forward_transform — Method
forward_transform(basis::TEBDBasis, image::AbstractMatrix)Apply forward TEBD transform to an image.
Arguments
basis::TEBDBasis: The basis to use for transformationimage::AbstractMatrix: Input image (must be 2^m × 2^n)
Returns
- Transformed representation as matrix (same shape as input)
ParametricDFT.forward_transform — Method
forward_transform(basis::TEBDBasis, data::AbstractVector)Apply forward TEBD transform to a vector.
Arguments
basis::TEBDBasis: The basis to use for transformationdata::AbstractVector: Input vector (must have length 2^(m+n))
Returns
- Transformed representation (Complex vector of same length)
ParametricDFT.get_entangle_phases — Method
get_entangle_phases(basis::EntangledQFTBasis)Get the current entanglement phase parameters.
Returns
Vector{Float64}: Phase parameters phi_k for each entanglement gate
ParametricDFT.get_phases — Method
get_phases(basis::MERABasis)Get the current phase parameters.
Returns
Vector{Float64}: Phase parameters for each MERA gate
ParametricDFT.get_phases — Method
get_phases(basis::TEBDBasis)Get the current phase parameters.
Returns
Vector{Float64}: Phase parameters for each TEBD gate
ParametricDFT.image_size — Method
image_size(basis::EntangledQFTBasis)Return the supported image dimensions for this basis.
Returns
Tuple{Int,Int}: (height, width) = (2^m, 2^n)
ParametricDFT.image_size — Method
image_size(basis::MERABasis)Return the supported image dimensions for this basis.
Returns
Tuple{Int,Int}: (height, width) = (2^m, 2^n)
ParametricDFT.image_size — Method
image_size(basis::QFTBasis)Return the supported image dimensions for this basis.
Returns
Tuple{Int,Int}: (height, width) = (2^m, 2^n)
ParametricDFT.image_size — Method
image_size(basis::TEBDBasis)Return the supported image dimensions for this basis.
Returns
Tuple{Int,Int}: (height, width) = (2^m, 2^n)
ParametricDFT.inverse_transform — Method
inverse_transform(basis::EntangledQFTBasis, freq_domain::AbstractMatrix)Apply inverse entangled QFT transform to convert frequency domain back to image.
Arguments
basis::EntangledQFTBasis: The basis to use for transformationfreq_domain::AbstractMatrix: Frequency domain data (size 2^m × 2^n)
Returns
- Reconstructed image (Complex matrix of same size)
ParametricDFT.inverse_transform — Method
inverse_transform(basis::MERABasis, freq_domain::AbstractMatrix)Apply inverse MERA transform to a matrix.
Arguments
basis::MERABasis: The basis to use for transformationfreq_domain::AbstractMatrix: Frequency domain data (must be 2^m × 2^n)
Returns
- Reconstructed data as matrix (same shape as input)
ParametricDFT.inverse_transform — Method
inverse_transform(basis::MERABasis, freq_domain::AbstractVector)Apply inverse MERA transform to convert back to original domain.
Arguments
basis::MERABasis: The basis to use for transformationfreq_domain::AbstractVector: Frequency domain data (length 2^(m+n))
Returns
- Reconstructed data (Complex vector of same length)
ParametricDFT.inverse_transform — Method
inverse_transform(basis::QFTBasis, freq_domain::AbstractMatrix)Apply inverse transform to convert frequency domain back to image.
Arguments
basis::QFTBasis: The basis to use for transformationfreq_domain::AbstractMatrix: Frequency domain data (size 2^m × 2^n)
Returns
- Reconstructed image (Complex matrix of same size)
ParametricDFT.inverse_transform — Method
inverse_transform(basis::TEBDBasis, freq_domain::AbstractMatrix)Apply inverse TEBD transform to a matrix.
Arguments
basis::TEBDBasis: The basis to use for transformationfreq_domain::AbstractMatrix: Frequency domain data (must be 2^m × 2^n)
Returns
- Reconstructed data as matrix (same shape as input)
ParametricDFT.inverse_transform — Method
inverse_transform(basis::TEBDBasis, freq_domain::AbstractVector)Apply inverse TEBD transform to convert back to original domain.
Arguments
basis::TEBDBasis: The basis to use for transformationfreq_domain::AbstractVector: Frequency domain data (length 2^(m+n))
Returns
- Reconstructed data (Complex vector of same length)
ParametricDFT.num_entangle_parameters — Method
num_entangle_parameters(basis::EntangledQFTBasis)Return the number of entanglement phase parameters.
Returns
Int: Number of entanglement gates (= min(m, n))
ParametricDFT.num_gates — Method
num_gates(basis::MERABasis)Return the total number of MERA gates.
Returns
Int: Number of gates (= nrowgates + ncolgates)
ParametricDFT.num_gates — Method
num_gates(basis::TEBDBasis)Return the total number of TEBD gates.
Returns
Int: Number of gates (= m + n for ring topology)
ParametricDFT.num_parameters — Method
num_parameters(basis::EntangledQFTBasis)Return the total number of learnable parameters in the basis.
For EntangledQFTBasis:
- Standard QFT parameters (Hadamard gates + M gates)
- Additional n entanglement gate phases (one per qubit pair)
Returns
Int: Total parameter count
ParametricDFT.num_parameters — Method
num_parameters(basis::MERABasis)Return the total number of learnable parameters in the basis.
Returns
Int: Total parameter count
ParametricDFT.num_parameters — Method
num_parameters(basis::QFTBasis)Return the total number of learnable parameters in the basis.
For QFT basis:
- n Hadamard gates: 4n parameters each (2×2 unitary)
- n(n-1)/2 controlled-phase gates: 4 parameters each (diagonal 2×2)
Returns
Int: Total parameter count
ParametricDFT.num_parameters — Method
num_parameters(basis::TEBDBasis)Return the total number of learnable parameters in the basis.
Returns
Int: Total parameter count
ParametricDFT._build_manual_qft — Method
_build_manual_qft(n_qubits, qubit_offset, total_qubits)Build a manual QFT gate chain (without using EasyBuild.qftcircuit) that returns individual gate operations. This is needed for the :middle entangleposition mode where entanglement gates are interleaved with QFT Hadamard gates.
The standard QFT for n qubits consists of:
- For qubit j = 1, ..., n:
- H(j)
- For target k = j+1, ..., n: ctrl(k → j, phase=2π/2^(k-j+1))
Arguments
n_qubits::Int: Number of qubits in this QFT blockqubit_offset::Int: Offset to add to qubit indices (0 for row, m for col)total_qubits::Int: Total number of qubits in the full circuit
Returns
Vector{AbstractBlock}: Individual gate operations in order
ParametricDFT.entangled_qft_code — Method
entangled_qft_code(m::Int, n::Int; entangle_phases=nothing, inverse=false, entangle_position=:back)Generate an optimized tensor network representation of the entangled QFT circuit.
The entangled QFT extends the standard 2D QFT by adding entanglement gates Ek between corresponding row and column qubits. Each entanglement gate Ek is a controlled-phase gate with the same structure as the M gate in QFT:
Full gate form (4×4 matrix): Ek = diag(1, 1, 1, e^(i*phik))
Tensor network form (2×2 matrix): Ektensor = [1 0; 0 e^(i*phi_k)]
The gate acts on qubits (x{n-k}, y{n-k}), where phi_k is a learnable phase parameter. In the tensor network, these are represented as 2×2 matrices.
For a square 2^n × 2^n image (m = n), we add exactly n entanglement gates, one for each pair of corresponding row/column qubits.
Arguments
m::Int: Number of qubits for row indices (image height = 2^m)n::Int: Number of qubits for column indices (image width = 2^n)entangle_phases::Union{Nothing, Vector{<:Real}}: Initial phases for entanglement gates. If nothing, defaults to zeros (equivalent to standard QFT). Length must equal min(m, n).inverse::Bool: If true, generate inverse transform codeentangle_position::Symbol: Where to place entanglement gates. One of::back(default): QFTrow ⊗ QFTcol → Entangle:front: Entangle → QFTrow ⊗ QFTcol:middle: Row and column QFT interleaved, with Ek placed after the row H(j) but BEFORE the column H(j). This produces a distinct result because Ek (a diagonal controlled-phase gate) does not commute with Hadamard gates.
Returns
optcode::AbstractEinsum: Optimized einsum contraction codetensors::Vector: Circuit parameters (unitary matrices + entanglement gates)n_entangle::Int: Number of entanglement gates added
Example
# Create entangled QFT for 64×64 images with default (zero) phases
optcode, tensors, n_entangle = entangled_qft_code(6, 6)
# Create with custom initial phases
phases = rand(6) * 2π
optcode, tensors, n_entangle = entangled_qft_code(6, 6; entangle_phases=phases)
# Create with entanglement at front
optcode, tensors, n_entangle = entangled_qft_code(6, 6; entangle_position=:front)
# Create with entanglement interleaved in middle
optcode, tensors, n_entangle = entangled_qft_code(6, 6; entangle_position=:middle)ParametricDFT.entanglement_gate — Method
entanglement_gate(phi::Real)Create the tensor network representation of a 2-qubit controlled-phase gate E with learnable phase phi.
Full gate form (4×4 matrix in computational basis): E = diag(1, 1, 1, e^(i*phi))
This applies phase e^(i*phi) only when both qubits are in state |1⟩.
Tensor network form (2×2 matrix): E_tensor = [1 0; 0 e^(i*phi)]
In the einsum tensor network decomposition, controlled-phase gates are represented as 2×2 matrices acting on the bond indices connecting the control and target qubits. This function returns the tensor form, not the full 4×4 gate matrix.
This gate has the same structure as the M gate in the QFT circuit, but with a learnable phase parameter instead of the fixed QFT phases (2π/2^k).
Arguments
phi::Real: Phase parameter (in radians)
Returns
Matrix{ComplexF64}: 2×2 matrix in tensor network form
ParametricDFT.extract_entangle_phases — Method
extract_entangle_phases(tensors, entangle_indices::Vector{Int})Extract the phase parameters from entanglement gate tensors.
Arguments
tensors::Vector: Circuit tensorsentangle_indices::Vector{Int}: Indices of entanglement gates
Returns
Vector{Float64}: Phase parameters phi_k for each entanglement gate
ParametricDFT.ft_mat — Method
ft_mat(tensors::Vector, code::AbstractEinsum, m::Int, n::Int, pic::Matrix)Apply 2D DFT to an image using the trained circuit parameters.
Arguments
tensors::Vector: Circuit tensors (unitary matrices)code::AbstractEinsum: Optimized einsum codem::Int: Number of qubits for row dimensionn::Int: Number of qubits for column dimensionpic::Matrix: Input image (size 2^m × 2^n)
Returns
- Transformed image in frequency domain (size 2^m × 2^n)
ParametricDFT.get_entangle_tensor_indices — Method
get_entangle_tensor_indices(tensors, n_entangle::Int)Identify which tensors in the circuit correspond to entanglement gates. Returns the indices of the entanglement gate tensors (the last n_entangle controlled-phase gates).
In the tensor network representation from yao2einsum, controlled-phase gates have the form [1, 1; 1, e^(i*phi)] (not diagonal). The entanglement gates are the last n_entangle such tensors after sorting (Hadamards first, then phase gates).
After training, tensors may drift slightly from the exact pattern, so we use tolerance-based magnitude checks.
Arguments
tensors::Vector: Circuit tensorsn_entangle::Int: Number of entanglement gates
Returns
Vector{Int}: Indices of entanglement gate tensors
ParametricDFT.ift_mat — Method
ift_mat(tensors::Vector, code::AbstractEinsum, m::Int, n::Int, pic::Matrix)Apply inverse 2D DFT using the inverse QFT circuit with trained parameters.
Arguments
tensors::Vector: Circuit tensors (unitary matrices) from inverse QFT (use qft_code(m, n; inverse=true))code::AbstractEinsum: Optimized einsum code from inverse QFTm::Int: Number of qubits for row dimensionn::Int: Number of qubits for column dimensionpic::Matrix: Input in frequency domain (size 2^m × 2^n)
Returns
- Transformed image in spatial domain (size 2^m × 2^n)
ParametricDFT.qft_code — Method
qft_code(m::Int, n::Int; inverse=false)Generate an optimized tensor network representation of the QFT circuit.
Arguments
m::Int: Number of qubits for row indicesn::Int: Number of qubits for column indicesinverse::Bool: If true, generate inverse transform code
Returns
optcode::AbstractEinsum: Optimized einsum contraction codetensors::Vector: Initial circuit parameters (unitary matrices)
ParametricDFT.extract_tebd_phases — Method
extract_tebd_phases(tensors, gate_indices::Vector{Int})Extract the phase parameters from TEBD gate tensors.
Arguments
tensors::Vector: Circuit tensorsgate_indices::Vector{Int}: Indices of TEBD gates
Returns
Vector{Float64}: Phase parameters for each TEBD gate
ParametricDFT.get_tebd_gate_indices — Method
get_tebd_gate_indices(tensors, n_gates::Int)Identify which tensors correspond to TEBD gates.
Arguments
tensors::Vector: Circuit tensorsn_gates::Int: Number of TEBD gates
Returns
Vector{Int}: Indices of TEBD gate tensors
ParametricDFT.n_col_gates — Method
n_col_gates(n::Int)Calculate number of column ring phase gates for n column qubits.
ParametricDFT.n_row_gates — Method
n_row_gates(m::Int)Calculate number of row ring phase gates for m row qubits.
ParametricDFT.n_total_gates — Method
n_total_gates(m::Int, n::Int)Calculate total number of phase gates for m×n TEBD circuit.
ParametricDFT.tebd_code — Method
tebd_code(m::Int, n::Int; phases=nothing, inverse=false)Generate an optimized tensor network representation of a 2D TEBD circuit with ring topology.
The TEBD circuit consists of:
- Hadamard layer: H gates on all m+n qubits (creates frequency basis)
- Two separate rings of controlled-phase gates:
- Row ring: (1,2), (2,3), ..., (m-1,m), (m,1) for m gates on row qubits
- Column ring: (m+1,m+2), (m+2,m+3), ..., (m+n-1,m+n), (m+n,m+1) for n gates on column qubits
This creates a 2D separable transform with periodic boundary conditions (ring topology).
Arguments
m::Int: Number of row qubits (row dimension = 2^m)n::Int: Number of column qubits (column dimension = 2^n)phases::Union{Nothing, Vector{<:Real}}: Initial phases for TEBD gates. If nothing, defaults to zeros. Length must equal m+n for ring topology.inverse::Bool: If true, generate inverse transform code
Returns
optcode::AbstractEinsum: Optimized einsum contraction codetensors::Vector: Circuit parameters (Hadamard gates + TEBD gate tensors)n_row_gates::Int: Number of row ring phase gates (= m)n_col_gates::Int: Number of column ring phase gates (= n)
Example
# Create 2D TEBD circuit for 3×3 (m=3 row qubits, n=3 col qubits)
optcode, tensors, n_row, n_col = tebd_code(3, 3)
# Create with custom initial phases (6 gates total: 3 row ring + 3 col ring)
phases = rand(6) * 2π
optcode, tensors, n_row, n_col = tebd_code(3, 3; phases=phases)ParametricDFT._mera_single_dim — Method
_mera_single_dim(n_qubits::Int, qubit_offset::Int, total_qubits::Int, phases::Vector{<:Real})Build MERA layers (disentanglers + isometries) for one dimension.
The MERA structure has k = log2(nqubits) layers. Each layer l has stride s = 2^(l-1) and npairs = n_qubits / (2*s) pairs of gates.
Arguments
n_qubits::Int: Number of qubits in this dimension (must be power of 2 and >= 2)qubit_offset::Int: Offset to add to qubit indices (0-based)total_qubits::Int: Total number of qubits in the full circuitphases::Vector{<:Real}: Phase parameters for all gates in this dimension
Returns
ChainBlock: Yao chain block containing all MERA gates for this dimension
ParametricDFT._n_mera_gates — Method
_n_mera_gates(n_qubits::Int)Calculate the number of phase gates for one dimension of a MERA circuit.
Arguments
n_qubits::Int: Number of qubits in this dimension (must be >= 2)
Returns
Int: Number of phase gates = 2 * (n_qubits - 1)
ParametricDFT.extract_mera_phases — Method
extract_mera_phases(tensors, gate_indices::Vector{Int})Extract the phase parameters from MERA gate tensors.
Arguments
tensors::Vector: Circuit tensorsgate_indices::Vector{Int}: Indices of MERA gates
Returns
Vector{Float64}: Phase parameters for each MERA gate
ParametricDFT.get_mera_gate_indices — Method
get_mera_gate_indices(tensors, n_gates::Int)Identify which tensors correspond to MERA gates.
Arguments
tensors::Vector: Circuit tensorsn_gates::Int: Number of MERA gates
Returns
Vector{Int}: Indices of MERA gate tensors
ParametricDFT.mera_code — Method
mera_code(m::Int, n::Int; phases=nothing, inverse=false)Generate an optimized tensor network representation of a 2D MERA circuit.
The MERA circuit consists of:
- Hadamard layer: H gates on all m+n qubits (creates frequency basis)
- Row MERA: hierarchical disentangler + isometry layers on row qubits 1:m
- Column MERA: hierarchical disentangler + isometry layers on col qubits m+1:m+n
Arguments
m::Int: Number of row qubits (must be power of 2 if >= 2, or 1)n::Int: Number of column qubits (must be power of 2 if >= 2, or 1)phases::Union{Nothing, Vector{<:Real}}: Initial phases for MERA gates. If nothing, defaults to zeros. Length must equal nrowgates + ncolgates.inverse::Bool: If true, generate inverse transform code
Returns
optcode::AbstractEinsum: Optimized einsum contraction codetensors::Vector: Circuit parameters (Hadamard gates + MERA gate tensors)n_row_gates::Int: Number of row phase gatesn_col_gates::Int: Number of column phase gates
Example
# Create 2D MERA circuit for 4×4 (m=4 row qubits, n=4 col qubits)
optcode, tensors, n_row, n_col = mera_code(4, 4)
# Create with custom initial phases (6+6=12 gates total)
phases = rand(12) * 2π
optcode, tensors, n_row, n_col = mera_code(4, 4; phases=phases)