Basis Types

ParametricDFT.AbstractSparseBasisType
AbstractSparseBasis

Abstract 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 domain
  • inverse_transform(basis, freq_domain) - inverse transform
  • image_size(basis) - return supported image dimensions
  • num_parameters(basis) - return total parameter count
  • basis_hash(basis) - return unique hash for basis identification
source
ParametricDFT.EntangledQFTBasisType
EntangledQFTBasis <: AbstractSparseBasis

Entangled 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 transform
  • inverse_code::AbstractEinsum: Optimized einsum code for inverse transform
  • n_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)
source
ParametricDFT.EntangledQFTBasisMethod
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 rows
  • n::Int: Number of qubits for columns
  • tensors::Vector: Pre-trained circuit parameters
  • n_entangle::Int: Number of entanglement gates
  • entangle_position::Symbol: Where entanglement gates are placed (:front, :middle, :back)

Returns

  • EntangledQFTBasis: Basis with custom parameters
source
ParametricDFT.EntangledQFTBasisMethod
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
source
ParametricDFT.MERABasisType
MERABasis <: AbstractSparseBasis

Multi-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 transform
  • inverse_code::AbstractEinsum: Optimized einsum code for inverse transform
  • n_row_gates::Int: Number of row MERA phase gates
  • n_col_gates::Int: Number of column MERA phase gates
  • phases::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)
source
ParametricDFT.MERABasisMethod
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 qubits
  • n::Int: Number of column qubits
  • tensors::Vector: Pre-trained circuit parameters
  • n_row_gates::Int: Number of row MERA gates
  • n_col_gates::Int: Number of column MERA gates

Returns

  • MERABasis: Basis with custom parameters
source
ParametricDFT.MERABasisMethod
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
source
ParametricDFT.QFTBasisType
QFTBasis <: AbstractSparseBasis

Quantum 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 transform
  • inverse_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)
source
ParametricDFT.QFTBasisMethod
QFTBasis(m::Int, n::Int, tensors::Vector)

Construct a QFTBasis with custom trained tensors.

Arguments

  • m::Int: Number of qubits for rows
  • n::Int: Number of qubits for columns
  • tensors::Vector: Pre-trained circuit parameters

Returns

  • QFTBasis: Basis with custom parameters
source
ParametricDFT.QFTBasisMethod
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
source
ParametricDFT.TEBDBasisType
TEBDBasis <: AbstractSparseBasis

Time-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 transform
  • inverse_code::AbstractEinsum: Optimized einsum code for inverse transform
  • n_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)
source
ParametricDFT.TEBDBasisMethod
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 qubits
  • n::Int: Number of column qubits
  • tensors::Vector: Pre-trained circuit parameters
  • n_row_gates::Int: Number of row ring gates
  • n_col_gates::Int: Number of column ring gates

Returns

  • TEBDBasis: Basis with custom parameters
source
ParametricDFT.TEBDBasisMethod
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
source
Base.:(==)Method
Base.:(==)(a::EntangledQFTBasis, b::EntangledQFTBasis)

Check equality of two EntangledQFTBasis objects.

source
Base.:(==)Method
Base.:(==)(a::MERABasis, b::MERABasis)

Check equality of two MERABasis objects.

source
Base.:(==)Method
Base.:(==)(a::QFTBasis, b::QFTBasis)

Check equality of two QFTBasis objects.

source
Base.:(==)Method
Base.:(==)(a::TEBDBasis, b::TEBDBasis)

Check equality of two TEBDBasis objects.

source
Base.showMethod
Base.show(io::IO, basis::EntangledQFTBasis)

Pretty print the EntangledQFTBasis.

source
Base.showMethod
Base.show(io::IO, basis::MERABasis)

Pretty print the MERABasis.

source
Base.showMethod
Base.show(io::IO, basis::QFTBasis)

Pretty print the QFTBasis.

source
Base.showMethod
Base.show(io::IO, basis::TEBDBasis)

Pretty print the TEBDBasis.

source
ParametricDFT.basis_hashMethod
basis_hash(basis::EntangledQFTBasis)

Compute a unique hash identifying this basis configuration and parameters.

Returns

  • String: SHA-256 hash of the basis parameters
source
ParametricDFT.basis_hashMethod
basis_hash(basis::MERABasis)

Compute a unique hash identifying this basis configuration and parameters.

Returns

  • String: SHA-256 hash of the basis parameters
source
ParametricDFT.basis_hashMethod
basis_hash(basis::QFTBasis)

Compute a unique hash identifying this basis configuration and parameters.

Returns

  • String: SHA-256 hash of the basis parameters
source
ParametricDFT.basis_hashMethod
basis_hash(basis::TEBDBasis)

Compute a unique hash identifying this basis configuration and parameters.

Returns

  • String: SHA-256 hash of the basis parameters
source
ParametricDFT.forward_transformMethod
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 transformation
  • image::AbstractMatrix: Input image (must be size 2^m × 2^n)

Returns

  • Frequency domain representation (Complex matrix of same size)
source
ParametricDFT.forward_transformMethod
forward_transform(basis::MERABasis, image::AbstractMatrix)

Apply forward MERA transform to an image.

Arguments

  • basis::MERABasis: The basis to use for transformation
  • image::AbstractMatrix: Input image (must be 2^m × 2^n)

Returns

  • Transformed representation as matrix (same shape as input)
source
ParametricDFT.forward_transformMethod
forward_transform(basis::MERABasis, data::AbstractVector)

Apply forward MERA transform to a vector.

Arguments

  • basis::MERABasis: The basis to use for transformation
  • data::AbstractVector: Input vector (must have length 2^(m+n))

Returns

  • Transformed representation (Complex vector of same length)
source
ParametricDFT.forward_transformMethod
forward_transform(basis::QFTBasis, image::AbstractMatrix)

Apply forward transform to convert image to frequency domain.

Arguments

  • basis::QFTBasis: The basis to use for transformation
  • image::AbstractMatrix: Input image (must be size 2^m × 2^n)

Returns

  • Frequency domain representation (Complex matrix of same size)
source
ParametricDFT.forward_transformMethod
forward_transform(basis::TEBDBasis, image::AbstractMatrix)

Apply forward TEBD transform to an image.

Arguments

  • basis::TEBDBasis: The basis to use for transformation
  • image::AbstractMatrix: Input image (must be 2^m × 2^n)

Returns

  • Transformed representation as matrix (same shape as input)
source
ParametricDFT.forward_transformMethod
forward_transform(basis::TEBDBasis, data::AbstractVector)

Apply forward TEBD transform to a vector.

Arguments

  • basis::TEBDBasis: The basis to use for transformation
  • data::AbstractVector: Input vector (must have length 2^(m+n))

Returns

  • Transformed representation (Complex vector of same length)
source
ParametricDFT.get_entangle_phasesMethod
get_entangle_phases(basis::EntangledQFTBasis)

Get the current entanglement phase parameters.

Returns

  • Vector{Float64}: Phase parameters phi_k for each entanglement gate
source
ParametricDFT.get_phasesMethod
get_phases(basis::MERABasis)

Get the current phase parameters.

Returns

  • Vector{Float64}: Phase parameters for each MERA gate
source
ParametricDFT.get_phasesMethod
get_phases(basis::TEBDBasis)

Get the current phase parameters.

Returns

  • Vector{Float64}: Phase parameters for each TEBD gate
source
ParametricDFT.image_sizeMethod
image_size(basis::EntangledQFTBasis)

Return the supported image dimensions for this basis.

Returns

  • Tuple{Int,Int}: (height, width) = (2^m, 2^n)
source
ParametricDFT.image_sizeMethod
image_size(basis::MERABasis)

Return the supported image dimensions for this basis.

Returns

  • Tuple{Int,Int}: (height, width) = (2^m, 2^n)
source
ParametricDFT.image_sizeMethod
image_size(basis::QFTBasis)

Return the supported image dimensions for this basis.

Returns

  • Tuple{Int,Int}: (height, width) = (2^m, 2^n)
source
ParametricDFT.image_sizeMethod
image_size(basis::TEBDBasis)

Return the supported image dimensions for this basis.

Returns

  • Tuple{Int,Int}: (height, width) = (2^m, 2^n)
source
ParametricDFT.inverse_transformMethod
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 transformation
  • freq_domain::AbstractMatrix: Frequency domain data (size 2^m × 2^n)

Returns

  • Reconstructed image (Complex matrix of same size)
source
ParametricDFT.inverse_transformMethod
inverse_transform(basis::MERABasis, freq_domain::AbstractMatrix)

Apply inverse MERA transform to a matrix.

Arguments

  • basis::MERABasis: The basis to use for transformation
  • freq_domain::AbstractMatrix: Frequency domain data (must be 2^m × 2^n)

Returns

  • Reconstructed data as matrix (same shape as input)
source
ParametricDFT.inverse_transformMethod
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 transformation
  • freq_domain::AbstractVector: Frequency domain data (length 2^(m+n))

Returns

  • Reconstructed data (Complex vector of same length)
source
ParametricDFT.inverse_transformMethod
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 transformation
  • freq_domain::AbstractMatrix: Frequency domain data (size 2^m × 2^n)

Returns

  • Reconstructed image (Complex matrix of same size)
source
ParametricDFT.inverse_transformMethod
inverse_transform(basis::TEBDBasis, freq_domain::AbstractMatrix)

Apply inverse TEBD transform to a matrix.

Arguments

  • basis::TEBDBasis: The basis to use for transformation
  • freq_domain::AbstractMatrix: Frequency domain data (must be 2^m × 2^n)

Returns

  • Reconstructed data as matrix (same shape as input)
source
ParametricDFT.inverse_transformMethod
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 transformation
  • freq_domain::AbstractVector: Frequency domain data (length 2^(m+n))

Returns

  • Reconstructed data (Complex vector of same length)
source
ParametricDFT.num_gatesMethod
num_gates(basis::MERABasis)

Return the total number of MERA gates.

Returns

  • Int: Number of gates (= nrowgates + ncolgates)
source
ParametricDFT.num_gatesMethod
num_gates(basis::TEBDBasis)

Return the total number of TEBD gates.

Returns

  • Int: Number of gates (= m + n for ring topology)
source
ParametricDFT.num_parametersMethod
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
source
ParametricDFT.num_parametersMethod
num_parameters(basis::MERABasis)

Return the total number of learnable parameters in the basis.

Returns

  • Int: Total parameter count
source
ParametricDFT.num_parametersMethod
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
source
ParametricDFT.num_parametersMethod
num_parameters(basis::TEBDBasis)

Return the total number of learnable parameters in the basis.

Returns

  • Int: Total parameter count
source
ParametricDFT._build_manual_qftMethod
_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 block
  • qubit_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
source
ParametricDFT.entangled_qft_codeMethod
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 code
  • entangle_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 code
  • tensors::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)
source
ParametricDFT.entanglement_gateMethod
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
source
ParametricDFT.extract_entangle_phasesMethod
extract_entangle_phases(tensors, entangle_indices::Vector{Int})

Extract the phase parameters from entanglement gate tensors.

Arguments

  • tensors::Vector: Circuit tensors
  • entangle_indices::Vector{Int}: Indices of entanglement gates

Returns

  • Vector{Float64}: Phase parameters phi_k for each entanglement gate
source
ParametricDFT.ft_matMethod
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 code
  • m::Int: Number of qubits for row dimension
  • n::Int: Number of qubits for column dimension
  • pic::Matrix: Input image (size 2^m × 2^n)

Returns

  • Transformed image in frequency domain (size 2^m × 2^n)
source
ParametricDFT.get_entangle_tensor_indicesMethod
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 tensors
  • n_entangle::Int: Number of entanglement gates

Returns

  • Vector{Int}: Indices of entanglement gate tensors
source
ParametricDFT.ift_matMethod
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 QFT
  • m::Int: Number of qubits for row dimension
  • n::Int: Number of qubits for column dimension
  • pic::Matrix: Input in frequency domain (size 2^m × 2^n)

Returns

  • Transformed image in spatial domain (size 2^m × 2^n)
source
ParametricDFT.qft_codeMethod
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 indices
  • n::Int: Number of qubits for column indices
  • inverse::Bool: If true, generate inverse transform code

Returns

  • optcode::AbstractEinsum: Optimized einsum contraction code
  • tensors::Vector: Initial circuit parameters (unitary matrices)
source
ParametricDFT.extract_tebd_phasesMethod
extract_tebd_phases(tensors, gate_indices::Vector{Int})

Extract the phase parameters from TEBD gate tensors.

Arguments

  • tensors::Vector: Circuit tensors
  • gate_indices::Vector{Int}: Indices of TEBD gates

Returns

  • Vector{Float64}: Phase parameters for each TEBD gate
source
ParametricDFT.get_tebd_gate_indicesMethod
get_tebd_gate_indices(tensors, n_gates::Int)

Identify which tensors correspond to TEBD gates.

Arguments

  • tensors::Vector: Circuit tensors
  • n_gates::Int: Number of TEBD gates

Returns

  • Vector{Int}: Indices of TEBD gate tensors
source
ParametricDFT.tebd_codeMethod
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:

  1. Hadamard layer: H gates on all m+n qubits (creates frequency basis)
  2. 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 code
  • tensors::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)
source
ParametricDFT._mera_single_dimMethod
_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 circuit
  • phases::Vector{<:Real}: Phase parameters for all gates in this dimension

Returns

  • ChainBlock: Yao chain block containing all MERA gates for this dimension
source
ParametricDFT._n_mera_gatesMethod
_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)
source
ParametricDFT.extract_mera_phasesMethod
extract_mera_phases(tensors, gate_indices::Vector{Int})

Extract the phase parameters from MERA gate tensors.

Arguments

  • tensors::Vector: Circuit tensors
  • gate_indices::Vector{Int}: Indices of MERA gates

Returns

  • Vector{Float64}: Phase parameters for each MERA gate
source
ParametricDFT.get_mera_gate_indicesMethod
get_mera_gate_indices(tensors, n_gates::Int)

Identify which tensors correspond to MERA gates.

Arguments

  • tensors::Vector: Circuit tensors
  • n_gates::Int: Number of MERA gates

Returns

  • Vector{Int}: Indices of MERA gate tensors
source
ParametricDFT.mera_codeMethod
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:

  1. Hadamard layer: H gates on all m+n qubits (creates frequency basis)
  2. Row MERA: hierarchical disentangler + isometry layers on row qubits 1:m
  3. 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 code
  • tensors::Vector: Circuit parameters (Hadamard gates + MERA gate tensors)
  • n_row_gates::Int: Number of row phase gates
  • n_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)
source