API Reference

Fallback dispatch

When extending QUBOTools, one might want to implement a method for QUBOTools.backend.

For MathOptInterface/JuMP integrations, including ToQUBO workflows that expose an MOI.ModelLike object, the supported public materialization path is:

qt_model = QUBOTools.Model(moi_model)

Use backend for wrapper types that already own or can return a QUBOTools.AbstractModel; use QUBOTools.Model(moi_model) when the source is an MOI model that needs to be converted into QUBOTools' sparse in-memory representation.

QUBOTools.backend — Function
backend(model)::AbstractModel
backend(model::AbstractModel)::AbstractModel

Accesses the model's backend. Implementing this function allows one to profit from fallback implementations of other methods.

source

Variable System

QUBOTools.index — Function
index(model::AbstractModel{V}, v::V) where {V}

Given a variable, returns the corresponding index.

source
QUBOTools.indices — Function
indices(model)

Returns a sorted vector $[1, \dots, n]$ that matches the variable indices, where $n$ is the model's dimension.

source
QUBOTools.hasindex — Function
hasindex(model::AbstractModel, i::Integer)::Bool

Given an index, returns whether it is valid for rhe model.

source
QUBOTools.variable — Function
variable(model::AbstractModel, i::Integer)

Given an index, returns the corresponding variable.

source
QUBOTools.hasvariable — Function
hasvariable(model::AbstractModel{V}, v::V)::Bool where {V}

Given a variable, tells if it belongs to the model.

source

Objective & Domain Frames

QUBOTools.BoolDomain — Constant
BoolDomain

Represents the boolean domain $\mathbb{B} = \lbrace{0, 1}\rbrace$.

Properties

\[x \in \mathbb{B}, n \in \mathbb{N} \implies x^{n} = x\]

source
QUBOTools.SpinDomain — Constant
SpinDomain

Represents the spin domain $\mathbb{S} = \lbrace{-1, 1}\rbrace$.

Properties

\[s \in \mathbb{S}, n \in \mathbb{Z} \implies s^{2n} = 1, s^{2n + 1} = s\]

source
QUBOTools.Sense — Type
Sense

Enum representing the minimization and maximization objective senses, Min and Max.

source
QUBOTools.cast — Function

Recasting the sense of a model preserves its meaning but the linear terms, quadratic terms and constant offset of a model will have its signs reversed, so does the overall objective function.

\[\begin{array}{ll} \min_{s} \alpha [f(s) + \beta] &\equiv \max_{s} -\alpha [f(s) + \beta] \\ &\equiv \max_{s} \alpha [-f(s) - \beta] \\ \end{array}\]

Warn

Casting to the same (sense, domain) frame is a no-op. That means that no copying will take place automatically, and therefore copy should be called explicitly when necessary.

source

Errors

Models

QUBOTools.Model — Type
Model{V,T,U,F<:AbstractForm{T}} <: AbstractModel{V,T,U}

Reference AbstractModel implementation. It is intended to be the stardard in-memory representation for QUBO models.

Sparse Constructors

Model{V,T,U}(variables, L::SparseVector, Q::SparseMatrixCSC; kws...)
Model{V,T,U}(
    variables,
    linear_indices,
    linear_values,
    quadratic_rows,
    quadratic_cols,
    quadratic_values;
    kws...,
)

These constructors build the model's sparse normal form directly. The vector variables defines the public variable-index mapping: variables[i] maps to index i, and all variables must be unique. COO indices are 1-based positions in that vector. Unlike dictionary and set constructors, which sort variables with varlt, sparse constructors preserve the caller-supplied variable order.

Quadratic inputs are normalized to strict upper-triangular storage. Entries with i > j are stored as (j, i), diagonal entries are accumulated into the linear form, duplicate coordinates are summed by Julia's sparse constructors, and resulting explicit zeros are removed with dropzeros!. Pass upper-triangular quadratic data, or pre-halve mirrored off-diagonal entries; a full symmetric matrix contributes both (i, j) and (j, i) and therefore doubles each off-diagonal coefficient in the stored normal form.

scale and offset are stored as the model's normal-form scale and offset; the coefficient inputs are not pre-scaled. Objective evaluation uses scale * (linear + quadratic + offset).

MathOptInterface/JuMP Integration

Both V and T parameters exist to support MathOptInterface/JuMP integration. This is made possible by choosing V to match MOI.VariableIndex and T as in Optimizer{T}.

source

Model Forms

QUBOTools.AbstractForm — Type
AbstractForm{T}

A form is a $7$-tuple $(n, \ell, Q, \alpha, \beta) \times (\textrm{sense}, \textrm{domain})$ representing a QUBO / Ising model.

  • $n$, the dimension, is the number of variables.
  • $\mathbf{\ell}$, the linear form, represents a vector storing the linear terms.
  • $\mathbf{Q}$, the quadratic form, represents an upper triangular matrix containing the quadratic interactions.
  • $\alpha$ is the scale factor, defaults to $1$.
  • $\beta$ is the offset factor, defaults to $0$.

The inner data structures used to represent each of these elements may vary.

source
QUBOTools.AbstractLinearForm — Type
AbstractLinearForm{T}

Linear form subtypes will create a wrapper around data structures for representing the linear terms $\mathbf{\ell}'\mathbf{x}$ of the QUBO model.

source
QUBOTools.AbstractQuadraticForm — Type
AbstractQuadraticForm{T}

Quadratic form subtypes will create a wrapper around data structures for representing the quadratic terms $\mathbf{x}'\mathbf{Q}\,\mathbf{x}$ of the QUBO model.

source
QUBOTools.form — Function
form(src [, formtype::Type{<:AbstractForm{T}}]; sense, domain) where {T}
form(src [, formtype::Union{Symbol,Type}, T::Type = Float64]; sense, domain)

Returns the QUBO form stored within src, casting it to the corresponding (sense, domain) frame and, if necessary, converting the coefficients to type T.

The underlying data structure is given by formtype. Current options include :dict, :dense and :sparse.

For more informaion, see QUBOTools.Form and QUBOTools.AbstractForm.

source
QUBOTools.fix_variables — Function
fix_variables(Φ::AbstractForm, fix::AbstractDict{<:Integer})

Fixes variables in Φ to the values supplied by fix. Keys are original form indices in 1:dimension(Φ), not model variable labels.

For boolean forms, fixed values must belong to $\mathbb{B} = \{0, 1\}$. For spin forms, fixed values must belong to $\mathbb{S} = \{-1, 1\}$.

Returns (Φ_reduced, offset_delta, index_map), where offset_delta is the unscaled amount added to offset(Φ) and index_map maps each surviving original variable index to its dense index in Φ_reduced. Surviving indices retain their original order, including isolated variables. The storage types, scale, objective sense and domain are preserved.

For every valid reduced state y, with x = lift_state(y, fix, index_map, dimension(Φ)), the energy identity is value(x, Φ) ≈ value(y, Φ_reduced) (up to floating-point roundoff). The reduced offset is already offset(Φ) + offset_delta: do not add the delta again to the reduced energy. The corresponding full-energy change in the constant term is scale(Φ) * offset_delta.

An empty fix preserves all variables; fixing every variable returns a zero-dimensional form containing the full constant energy. Out-of-range indices or values outside the form's domain throw ArgumentError. See the conditioning example for label mapping.

source
QUBOTools.lift_state — Function
lift_state(state_reduced, fix, index_map, n)

Reconstructs a full length-n state from a reduced state, fixed variable values, and the index_map returned by QUBOTools.fix_variables. The map direction is original index → reduced index. Fixed indices and map keys must partition 1:n, and map values must be a bijection onto the reduced state positions; invalid dimensions or mappings throw ArgumentError. This function checks reconstruction structure, not domain membership: reuse the validated fix and a reduced state valid for the reduced form.

source

Underlying Data Structures

QUBOTools.formtype — Function
formtype(spec::Type)
formtype(spec::Symbol)

Returns a form type according to the given specification.

formtype(src)

Returns the form type of a form or model.

source
QUBOTools.DictForm — Type
DictForm{T}

This QUBO form is built using dictionaries for both the linear and quadratic terms.

source
QUBOTools.DenseForm — Type
DenseForm{T}

This QUBO form is built using a vector for the linear terms and a matrix for storing the quadratic terms.

source
QUBOTools.SparseForm — Type
SparseForm{T}

This QUBO form is built using a sparse vector for the linear terms and a sparse matrix for the quadratic ones.

source

Solutions

QUBOTools.AbstractSample — Type
AbstractSample

A sample is a triple $(\psi, \lambda, r)$ where $\psi \in \mathbb{U}^{n} \sim \mathbb{B}^{n}$ is the sampled vector, $\lambda \in \mathbb{R}$ is the associated energy value and $r \in \mathbb{N}$ is the number of reads, i. e., the multiplicity of the sample.

source
QUBOTools.sample — Function
sample(model, i::Integer)

Returns the $i$-th sample on the model's current solution, if available.

source
QUBOTools.hassample — Function
hassample(solution::AbstractSolution, i::Integer)

Tells if the $i$-th sample is available on the solution.

source
QUBOTools.SampleSet — Type
SampleSet{T,U}(
    data::Vector{Sample{T,U}},
    metadata::Union{Dict{String,Any},Nothing} = nothing;
    sense::Union{Sense,Symbol}   = :min,
    domain::Union{Domain,Symbol} = :bool,
) where {T,U}

Reference implementation of QUBOTools.AbstractSolution.

It was inspired by D-Wave's SampleSet[dwave], with a few tweaks. For example, samples are automatically sorted upon instantiation and repeated samples are merged by adding up their reads field. Also, the solution frame is stored, allowing for queries and cast operations.

source
QUBOTools.sampleset_table — Function
sampleset_table(sampleset::AbstractSolution; bit_order = :native, include_probability = true)

Return a row table for sampleset as a Vector{NamedTuple} with stable columns. The default columns are rank, state, reads, value, and probability; probability is omitted when include_probability = false.

The returned vector is compatible with the Tables.jl row-table convention without making Tables.jl a package dependency.

source
QUBOTools.state — Function
state(sample::AbstractSample{T,U}) where {T,U<:Integer}

Returns a vector containing the assingment of each variable in a sample.

state(model, i::Integer) where {U<:Integer}

Returns a vector corresponding to the bitstring of the $i$-th sample on the model's current solution, if available.

source
QUBOTools.value — Function
value(model)::T where {T}

value(model, i::Integer)::T where {T}
value(solution::AbstractSolution{T,U}, i::Integer)::T where {T,U}

value(model, state::AbstractVector{U}) where {U<:Integer}
value(solution::AbstractSolution{T,U}, state::AbstractVector{U})::T where {T,U<:Integer}

value(Q::Dict{Tuple{Int,Int},T}, ψ::Vector{U}, α::T = one(T), β::T = zero(T)) where {T}
value(h::Dict{Int,T}, J::Dict{Tuple{Int,Int},T}, ψ::Vector{U}, α::T = one(T), β::T = zero(T)) where {T}
source
QUBOTools.reads — Function
reads(model)
reads(solution::AbstractSolution)

Returns the total amount of reads from each sample, combined.

reads(model, i::Integer)
reads(solution::AbstractSolution, i::Integer)

Returns the sampling frequency of the $i$-th sample on the model's current solution, if available.

source
QUBOTools.ObjectiveBreakdown — Type
ObjectiveBreakdown

Structured objective evaluation for a state.

Fields:

  • state: state vector in the evaluated model or form domain;
  • raw_value: linear plus quadratic value before scale and offset;
  • scaled_value: scale * raw_value;
  • offset_adjusted_value: scale * (raw_value + offset), matching value;
  • scale, offset, sense, and domain: frame data used for evaluation.
source
QUBOTools.objective_breakdown — Function
objective_breakdown(model_or_form, state; variables = nothing)
objective_breakdown(model, sample)
objective_breakdown(model, i::Integer)

Return a structured objective-value breakdown for state.

The breakdown separates the raw quadratic value, the scaled value, and the offset-adjusted value used by value. When variables is provided for a model and vector state, the vector is interpreted in that variable order and projected to the model's variable order before evaluation. The sample and integer overloads evaluate state data without a surrounding solution frame, so the state is assumed to already be in the model domain; use annotate_objectives! or verify_objective_values when evaluating samples from a SampleSet whose frame may differ from the model. The integer overload interprets i as the index of a sample in solution(model).

source
QUBOTools.annotate_objectives! — Function
annotate_objectives!(sampleset, model; label = :objective, variables = nothing)

Compute objective breakdown rows for each sample and store them under metadata(sampleset)["objectives"][label]. Stored rows record the evaluated state, after any solution-domain cast or variable projection needed to evaluate against model.

source
QUBOTools.objective_value_mismatches — Function
objective_value_mismatches(model, sampleset; atol = 0, rtol = sqrt(eps(Float64)))

Return detailed records for samples whose stored values do not match model evaluation within tolerance.

source
QUBOTools.verify_objective_values — Function
verify_objective_values(model, sampleset; kws...)

Return true when every stored sample value matches model evaluation within the given tolerance.

source

Solution Errors

Data Access

QUBOTools.linear_terms — Function
linear_terms(model::AbstractModel{V,T,U}) where {V,T,U}

Returns an iterator for the linear nonzero terms of a model as Int => T pairs.

source
QUBOTools.quadratic_terms — Function
quadratic_terms(model::AbstractModel{V,T,U}) where {V,T,U}

Returns an iterator for the quadratic nonzero terms of a model as Tuple{Int,Int} => T pairs.

Info

For every key pair $(i, j)$ we have that $i < j$.

source
QUBOTools.scale — Function
scale(model::AbstractModel)
scale(model::AbstractForm)

Returns the scaling factor of a model.

source
QUBOTools.offset — Function
offset(model::AbstractModel)
offset(model::AbstractForm)

Returns the constant offset factor of a model.

source
QUBOTools.data — Function
data(form)
data(sol::AbstractSolution)

Retrieves the raw data behind solution and form wrappers.

source
QUBOTools.metadata — Function
metadata(model::AbstractModel)
metadata(sol::AbstractSolution)

Retrieves metadata from a model or solution as a JSON-compatible Dict{String,Any}.

source
QUBOTools.start — Function
start(model::AbstractModel{V,T,U}; domain = domain(model))::Dict{Int,U} where {V,T,U}

Returns a dictionary containing a warm-start value for each variable index.

source
QUBOTools.attach! — Function
attach!(model::AbstractModel{V,T,U}, sol::AbstractSolution{T,U}) where {V,T,U}

Attaches solution to model, replacing existing data and solution metadata. It automatically casts the solution to the model frame upon attachment.

source

File Formats & I/O

QUBOTools.Format — Type
Format{F}

Concrete format descriptor for format F, storing validated format-specific settings.

source
QUBOTools.format — Function
format(::AbstractString)::AbstractFormat
format(::Symbol)::AbstractFormat
format(::Symbol, ::Symbol)::AbstractFormat

Given the file path, tries to infer the type associated to a QUBO model format.

source
QUBOTools.version — Function
version(fmt::AbstractFormat)

Returns the version of a format protocol as a VersionNumber or nothing.

source
QUBOTools.infer_format — Function
infer_format(hints::Vector{Symbol})::Format
infer_format(; path::AbstractString)

Infer a QUBOTools file format from ordered hint symbols or from the suffixes of path.

source
QUBOTools.read_model — Function
read_model(::AbstractString)
read_model(::AbstractString, ::AbstractFormat)
read_model(::IO, ::AbstractFormat)
source
QUBOTools.write_model — Function
write_model(::AbstractString, ::AbstractModel)
write_model(::AbstractString, ::AbstractModel, ::AbstractFormat)
write_model(::IO, ::AbstractModel, ::AbstractFormat)
source
QUBOTools.read_solution — Function
read_solution(::AbstractString)
read_solution(::AbstractString, ::AbstractFormat)
read_solution(::IO, ::AbstractFormat)
source
QUBOTools.write_solution — Function
write_solution(::AbstractString, ::AbstractSolution)
write_solution(::AbstractString, ::AbstractSolution, ::AbstractFormat)
write_solution(::IO, ::AbstractSolution, ::AbstractFormat)
source
QUBOTools.read_samples — Function
read_samples(path::AbstractString; metadata_path = nothing, bit_order = :native)

Read a CSV distribution written by write_samples and return a SampleSet. Duplicate states with matching values are merged by the SampleSet constructor. The probability column, when present, is treated as derived data; reads remains authoritative. Imported values use Float64 and reads use Int.

When embedded or sidecar metadata records bit_order, that recorded order is used to recover the native state order; the bit_order keyword is used only for metadata-less input. Sidecar metadata written by write_samples must be supplied with metadata_path to recover the recorded frame and solution metadata. read_samples returns a SampleSet and does not reconstruct model context from the optional metadata model block.

source
QUBOTools.write_samples — Function
write_samples(path::AbstractString, sampleset::AbstractSolution; format = :csv,
    metadata_path = nothing, bit_order = :native, include_probability = true)

Write a SampleSet-like solution as a stable tabular distribution file.

Only format = :csv is currently supported. By default, JSON metadata is embedded in a leading CSV comment so read_samples can recover the solution frame and metadata. If metadata_path is provided, the JSON metadata is written to that sidecar path instead and must be passed to read_samples to recover the recorded frame and metadata. When model context is provided, model scale, offset, and variable names are recorded in the JSON metadata.

source

Format & I/O Errors

Model Metrics

QUBOTools.density — Function
density(model)::Float64

Computes the density $\rho$ of non-zero terms in a model, according to the expression[qplib]

\[\rho = \frac{n_{\ell} + 2 n_{q}}{n^{2}}\]

where $n_{\ell}$ is the number of non-zero linear terms, $n_{q}$ the number of quadratic ones and $n$ the number of variables.

If the model is empty, returns NaN.

source
QUBOTools.linear_density — Function
linear_density(model)::Float64

Computes the linear density $\rho_{\ell}$, given by

\[\rho_{\ell} = \frac{n_{\ell}}{n}\]

where $n_{\ell}$ is the number of non-zero linear terms and $n$ the number of variables.

source
QUBOTools.quadratic_density — Function
quadratic_density(model)::Float64

Computes the quadratic density $\rho_{q}$, given by

\[\rho_{q} = \frac{2 n_{q}}{n (n - 1)}\]

where $n_{q}$ is the number of non-zero quadratic terms and $n$ the number of variables.

source
QUBOTools.coercive_fields — Function
coercive_fields(model_or_form)

Return the vector of unscaled Ising coercive local fields $h_i$ in variable index order $1:\mathrm{dimension}(x)$ under $s_i = 2 x_i - 1 \in \{-1, +1\}$:

  • for domain(x) === BoolDomain (:bool),

    \[h_i = \frac{1}{2} L_i + \frac{1}{4} \sum_{j \neq i} Q_{i, j};\]

  • for domain(x) === SpinDomain (:spin), $h_i = L_i$.

This quantity is invariant under cast(BoolDomain => SpinDomain, x).

source
QUBOTools.coercive_field_ratios — Function
coercive_field_ratios(model_or_form; norm::Real = 2)::Vector{Float64}

Return the per-variable ratios $|h_i| / \|J_{i, \cdot}\|_p$ in variable index order $1:\mathrm{dimension}(x)$, where $h_i$ is the Ising local field (coercive_fields), $J_{i, j}$ are the unscaled spin couplings ($\frac{1}{4} Q_{i, j}$ on :bool, $Q_{i, j}$ on :spin), and $p = \mathrm{norm} > 0$.

For an isolated variable with $\|J_{i, \cdot}\|_p = 0$, returns 0.0 when $h_i = 0$ and Inf when $|h_i| > 0$.

source
QUBOTools.coercive_field_ratio — Function
coercive_field_ratio(model_or_form; norm::Real = 2)::Float64

Return the mean ratio $|h_i| / \|J_{i, \cdot}\|_p$ across all variables with non-zero incident spin couplings ($\|J_{i, \cdot}\|_p > 0$), or NaN when no variable has non-zero incident quadratic couplings.

source
QUBOTools.zero_field_fraction — Function
zero_field_fraction(model_or_form; atol::Real = 0.0)::Float64

Return the fraction of variables in model_or_form satisfying $|h_i| \le \mathrm{atol}$, or NaN when dimension(model_or_form) == 0.

source
QUBOTools.trivial_dominance_fraction — Function
trivial_dominance_fraction(model_or_form; atol::Real = 0.0)::Float64

Return the fraction of variables in model_or_form whose Ising local field strictly dominates all incident spin couplings,

\[|h_i| > \sum_{j \neq i} |J_{i, j}| + \mathrm{atol},\]

so that variable $i$ is trivially fixed in any ground state regardless of the orientation of its neighbors. Returns NaN when dimension(model_or_form) == 0.

source
QUBOTools.is_gauge_invariant — Function
is_gauge_invariant(model_or_form; atol::Real = 0.0)::Bool

Return true when all Ising coercive local fields satisfy $|h_i| \le \mathrm{atol}$ for $i \in 1:\mathrm{dimension}(x)$, i.e. when the objective is invariant under global $\mathbb{Z}_2$ spin inversion $\mathbf{s} \mapsto -\mathbf{s}$ ($\mathbf{x} \mapsto \mathbf{1} - \mathbf{x}$).

source
QUBOTools.gauge_invariant_qubo — Function
gauge_invariant_qubo(model_or_form; keep_offset::Bool = true)

Return a copy of model_or_form projected onto its zero-field $\mathbb{Z}_2$ gauge-invariant subspace ($h_i = 0$ for all $i$):

  • in BoolDomain (:bool), replaces linear coefficients with $L_i \leftarrow -\frac{1}{2} \sum_{j \neq i} Q_{i, j}$ (and sets $\beta \leftarrow 0$ when keep_offset = false);
  • in SpinDomain (:spin), zeroes all linear coefficients $L_i \leftarrow 0$ (and sets $\beta \leftarrow -\sum_{i < j} J_{i, j}$ when keep_offset = false, so $E(-\mathbf{1}) = E(+\mathbf{1}) = 0$, commuting with cast(BoolDomain => SpinDomain, x)).

When projecting a Model, returns a new model with an empty solution set because the objective function is modified when non-zero local fields are removed.

source
QUBOTools.is_integer_scaled — Function
is_integer_scaled(model_or_form)::Bool

Return true when all stored linear coefficients, quadratic coefficients, and offset(model_or_form) are finite integers (isfinite(v) && isinteger(v)).

source
QUBOTools.integerize_scale — Function
integerize_scale(model_or_form; max_decimals::Integer = 9, atol::Real = 1e-12)

Return an owned copy of model_or_form in which the minimal irreducible multiplier $m = 2^a 5^b$ ($0 \le a, b \le \mathrm{max\_decimals}$ for floating-point coefficients, or the least common denominator for Rational coefficients) is factored into scale(model_or_form) / m so that all stored linear coefficients, quadratic coefficients, and offset become exact integers.

For floating-point forms:

  • Pure dyadic multipliers ($b = 0, m = 2^a$) require exact binary integer products (v * m == round(v * m)), preserving sub-ulp near-tie perturbations.
  • Decimal multipliers ($b \ge 1$) accept non-zero products within relative tolerance atol * abs(round(v * m)) (and < 0.5) provided at least one rounded integer numerator is not divisible by $5$ (and at least one is odd when $a \ge 1$), eliminating IEEE-754 decimal representation noise (such as 0.1 + 0.2 != 0.3 or -1.7999999999999998) while preserving exact $\mathbb{Z}_2$ gauge invariance.
  • If model_or_form is already integer-scaled, has zero/non-finite scale, or no multiplier within max_decimals produces representable exact integers, returns an owned copy with unchanged coefficients and scale.
source
QUBOTools.topology — Function
topology(model)
topology(form::AbstractForm)

Returns a Graphs.jl-compatible graph representing the quadratic interactions between variables in the model. The returned Graphs.SimpleGraph{Int} contains every vertex in 1:dimension(model) (or 1:dimension(form)), including isolated variables. Vertex indices match form indices; use variable to recover model labels.

source
QUBOTools.geometry — Function
geometry

Returns a $n \times N$ matrix describing the placement of the $n$ variable sites in $N$-dimensional space.

source

System Specification

QUBOTools.architecture — Function
architecture(::Any)

It should be defined to provide automatic architecture recognition when writing QUBO Solver interfaces.

Example

struct Solver
    ...
end

struct SolverArchitecture <: AbstractArchitecture
    ...
end

architecture(::Solver) = SolverArchitecture()
source
QUBOTools.AbstractDevice — Type
AbstractDevice{A<:AbstractArchitecture,V,T,U} <: AbstractModel{V,T,U}

A device instance is meant to represent an specific hardware or software device. It is the concrete implementation of an architecture. For example, the topology of a device must be contained within the ideal topology of its architecture.

source
QUBOTools.layout — Function
layout(::Any)
layout(::Any, ::G) where {G<:AbstractGraph}

Returns the layout of a model, device architecture, i.e., a description of the geometrical placement of each site as long as the network of their connections.

source

Problem Synthesis

QUBOTools.SherringtonKirkpatrick — Type
SherringtonKirkpatrick{T}(n::Integer, μ::Real = zero(T), σ::Real = one(T);
    normalize::Bool = false, gauge_invariant::Bool = true)

Generates a Sherrington-Kirkpatrick model in $n$ variables with Gaussian couplings $J_{i, j} \sim \mathcal{N}(\mu, \sigma^2)$ (scaled by $1 / \sqrt{n}$ when normalize = true and $n > 0$).

When gauge_invariant = true (default), generates the zero-field $\mathbb{Z}_2$ gauge-invariant QUBO with $L_i = -\frac{1}{2} \sum_{j \neq i} Q_{i, j}$ and offset $\beta = \sum_{i < j} J_{i, j}$ so that $h_i = 0$ for all $i$. When gauge_invariant = false, omits the linear and constant terms so the QUBO has $L_i = 0$ and $\beta = 0$, inducing coercive local fields $h_i = \frac{1}{4} \sum_{j \neq i} Q_{i, j}$.

source
QUBOTools.Wishart — Type
Wishart{T}(n::Integer, m::Integer)

Represents the Wishart model on $n$ variables whose $\mathbf{W}$ matrix has $m$ columns.

When true, the discretize keyword limits the entries of the $\mathbf{R}$ matrix to $\pm 1$. The precision, on the other hand, is the amount of digits to round each entry $R_{i,j}$ after sampling from a normal distribution $\mathcal{N}(0, 1)$.

source

Solution Metrics

Timing

QUBOTools.total_time — Function
total_time(sol::AbstractSolution)

Retrieves the total time spent during the whole solution gathering process, as experienced by the user.

source
QUBOTools.effective_time — Function
effective_time(sol::AbstractSolution)

Retrieves the time spent by the algorithm in the strict sense, that is, excluding time spent with data access, precompilation and other activities. That said, it is assumed that $t_{\text{effective}} \le t_{\text{total}}$.

source

Solution Quality

QUBOTools.success_rate — Function
success_rate(sol::AbstractSolution{T}, λ::Real; trial_unit::Symbol = :read) where {T}
success_rate(solutions::AbstractVector{<:AbstractSolution}, λ::Real; trial_unit::Symbol = :run)

Return the empirical success rate for target objective value $\lambda$ under the declared trial_unit (:read for read-multiplicity fraction within a batch, or :run for run-level attainment).

source

Time-to-Target (TTT)

QUBOTools.TimeToTargetEstimate — Type
TimeToTargetEstimate

Structured time-to-target (TTT) estimate preserving trial units, cost boundary, empirical vs. known probability provenance, and both operational (integer-restart) and continuous-relaxation repeat counts.

Fields:

  • ttt::Float64: time-to-target under the selected repetition_mode;
  • operational_ttt::Float64: executable restart cost trial_time * operational_repetitions, charging at least one trial when p > 0;
  • continuous_ttt::Float64: continuous relaxation trial_time * continuous_repetitions;
  • repetitions::Float64: repetition count under the selected repetition_mode;
  • operational_repetitions::Float64: integer repeat count $\max(1, \lceil \log(1 - s) / \log(1 - p) \rceil)$ (1.0 at $p = 1$, Inf at $p = 0$);
  • continuous_repetitions::Float64: continuous relaxation $\log(1 - s) / \log(1 - p)$ (0.0 at $p = 1$, Inf at $p = 0$);
  • trial_time::Float64: duration per trial in seconds;
  • batch_time::Float64: total duration of the evaluated batch or campaign in seconds;
  • target_probability::Float64: target success probability $s \in (0, 1)$;
  • success_probability::Float64: per-trial success probability $p \in [0, 1]$;
  • trials::Union{Int,Nothing}: finite trial count when probability_source === :empirical, or nothing when :known;
  • successes::Union{Int,Nothing}: observed successful trials when probability_source === :empirical, or nothing when :known;
  • trial_unit::Symbol: :read, :run, or :trial;
  • cost_boundary::Symbol: :effective, :total, :complete, or :unspecified;
  • probability_source::Symbol: :known or :empirical;
  • repetition_mode::Symbol: :integer, :continuous_floor_one, or :continuous;
  • status::Symbol: :known_interior_probability, :known_unit_probability, :known_zero_probability, :empirical_interior_probability, :empirical_all_succeeded, or :empirical_zero_successes.
source
QUBOTools.time_to_target_estimate — Function
time_to_target_estimate(sol::AbstractSolution, λ::Real, s::Real = 0.99;
    trial_unit = nothing, cost_boundary = :effective, trial_time = nothing,
    batch_time = nothing, repetition_mode = :integer)
time_to_target_estimate(solutions::AbstractVector{<:AbstractSolution}, λ::Real, s::Real = 0.99;
    trial_unit = :run, cost_boundary = :effective, trial_time = nothing,
    batch_time = nothing, repetition_mode = :integer)
time_to_target_estimate(trial_time::Real, p::Real, s::Real = 0.99;
    cost_boundary = :unspecified, repetition_mode = :integer, trial_unit = :trial)
time_to_target_estimate(trial_time::Real; successes::Integer, trials::Integer,
    s::Real = 0.99, cost_boundary = :unspecified, repetition_mode = :integer,
    trial_unit = :trial, batch_time = nothing)

Compute a structured TimeToTargetEstimate with matching probability and time units and explicit endpoint semantics:

  • trial_unit = :read treats each read in sol as an independent trial (trials = reads(sol) and trial_time = batch_time / trials unless trial_time is supplied). Solutions marked in metadata as correlated, selected, repaired, or best-only are rejected for :read.
  • trial_unit = :run treats a single SampleSet as one solver run (trials = 1, trial_time = batch_time), or a vector of SampleSets as length(solutions) independent runs.
  • cost_boundary selects :effective (strictly metadata["time"]["effective"]), :total (strictly metadata["time"]["total"]), or :complete (caller-supplied trial_time/batch_time or metadata["time"]["complete"]) without silently substituting one boundary for another.
source
QUBOTools.time_to_target — Function
time_to_target(sol::AbstractSolution, λ::Real, s::Real = 0.99;
    trial_unit = nothing, cost_boundary = :effective, trial_time = nothing,
    batch_time = nothing, repetition_mode = :continuous_floor_one)
time_to_target(solutions::AbstractVector{<:AbstractSolution}, λ::Real, s::Real = 0.99;
    trial_unit = :run, cost_boundary = :effective, trial_time = nothing,
    batch_time = nothing, repetition_mode = :continuous_floor_one)
time_to_target(t::Real, p::Real, s::Real = 0.99;
    repetition_mode = :continuous_floor_one)

Compute the scalar time-to-target (TTT) for threshold $\lambda$ and target success probability $s \in (0, 1)$ (default 0.99).

When called with a SampleSet, pass trial_unit = :read (independent reads) or trial_unit = :run (single solver run) so the trial duration and success probability share the same unit. Calling time_to_target(sol, λ, s) without trial_unit is deprecated because it mixes whole-batch timing with per-read success probability.

For a known per-trial success probability $p$ and positive trial cost $t$:

  • $p = 0$ returns Inf;
  • $p = 1$ charges one trial (t) under :integer and :continuous_floor_one (or 0.0 only when repetition_mode = :continuous is explicitly requested);
  • $0 < p < 1$ uses $\max(1, \log(1 - s) / \log(1 - p))$ for :continuous_floor_one and $\max(1, \lceil \log(1 - s) / \log(1 - p) \rceil)$ for :integer.
source

Hamming Distance

QUBOTools.hamming_distance — Function
hamming_distance(x::Vector{U}, y::Vector{U}) where {U}
hamming_distance(x::Sample{T,U}, y::Sample{T,U}) where {T,U}
source
QUBOTools.field_alignment — Function
field_alignment(model_or_form, state_or_sample_or_solution; atol::Real = 0.0, variables = nothing)::Float64
field_alignment(model::AbstractModel, i::Integer; atol::Real = 0.0, variables = nothing)::Float64
field_alignment(model::AbstractModel; atol::Real = 0.0)::Float64

Return the fraction of active-field variables ($|h_i| > \mathrm{atol}$) whose spin $s_i \in \{-1, +1\}$ aligns with the single-variable optimum of the local field objective $\alpha h_i s_i$ (where $\alpha = \mathrm{scale}(x)$):

  • for sense(x) === Min, spin $s_i$ is aligned when $\alpha h_i s_i < 0$;
  • for sense(x) === Max, spin $s_i$ is aligned when $\alpha h_i s_i > 0$.

For an AbstractSolution, returns the read-weighted average alignment across all samples. Returns NaN when there are no active-field variables (e.g., gauge-invariant or empty models), when scale(x) == 0, or when the solution is empty or has zero total reads.

source

Run Reports

QUBOTools.report — Function
report(model::AbstractModel; solution = QUBOTools.solution(model), λ = nothing,
    s::Real = 0.99, trial_unit = nothing, cost_boundary = :effective,
    trial_time = nothing, batch_time = nothing, repetition_mode = :integer,
    penalties = nothing, reformulation = nothing, feasibility = nothing,
    include_samples::Bool = false, bit_order = :native,
    include_probability::Bool = true)::Dict{String,Any}

Build a consolidated, JSON-serializable run-report dictionary (format = "QUBOTools.report", version = 1) aggregating:

  • "model": dimension, variable labels, sense, domain, scale, offset, linear/quadratic term counts, density, linear_density, quadratic_density, per-degree and combined coefficient statistics (count, min, max, min_abs, max_abs, mean, mean_abs, std, dynamic_range), Ising coercive-field diagnostics ("coercive_fields"), and model metadata;
  • "solution": presence flag, sample count, total reads, frame, solution metadata, QUBOTools.samples table metadata, timing (effective_time, total_time), energy summary, best sample with objective_breakdown and field_alignment, objective verification status (objective_values_verified, objective_mismatch_count), threshold metrics (success_rate and time_to_target_estimate when λ and trial_unit are supplied), and optional sample table rows (include_samples = true);
  • "penalties": optional penalty dictionary, automatically extracted from reformulation["applied_penalties"] or metadata(model)["penalties"] when not passed explicitly;
  • "reformulation": optional schema-v1 reformulation metadata dictionary (or metadata(model)["toqubo"]["reformulation"] when present);
  • "feasibility": optional constraint-feasibility summary dictionary or struct.

Works for models both with and without attached solutions, replacing non-finite floating-point values (NaN, ±Inf) with nothing (null in JSON) so the output is always valid RFC 8259 JSON.

source
QUBOTools.write_report — Function
write_report(path::AbstractString, model::AbstractModel; indent::Integer = 2, kws...)
write_report(io::IO, model::AbstractModel; indent::Integer = 2, kws...)

Write the consolidated run report produced by report as a JSON document to path or io. All keyword arguments accepted by report are forwarded.

source

Visualization

QUBOTools.AbstractVisualization — Type
AbstractVisualization

Represents a conceptual visualization built from a set of data structures. Its realization may combine multiple plot recipes as well.

Examples

Model Density Heatmap

julia> using Plots

julia> p = QUBOTools.ModelDensityPlot(model)

julia> plot(p)

Solution Energy vs. Frequency

julia> using Plots

julia> s = QUBOTools.solution(model)

julia> p = QUBOTools.EnergyFrequencyPlot(s)

julia> plot(p)

or simply,

julia> using Plots

julia> p = QUBOTools.EnergyFrequencyPlot(model)

julia> plot(p)
source