File Formats

FormatReadWriteModelSolutionsStartMetadata
BQPJSON✅✅✅✅❌✅
MiniZinc❌✅✅❌❌✅
QUBin✅✅✅✅❌✅
Qubist✅✅✅❌❌❌
QUBO✅✅✅❌❌✅
Rudy✅✅✅❌❌✅

Portable Model and Sample Interchange

Downstream decomposition and hybrid workflows should select an interchange carrier based on which model and sample attributes must survive serialization:

CarrierVariable MappingDomainsSensesScale & OffsetSolutions & readsNumeric & Metadata Fidelity
QUBin (.qb / HDF5)Exact 1:n Int or String order preserved:bool, :spin:min, :maxExact scale and offset in dataset type TFull SampleSet (state, value, reads)Preserves HDF5-native dataset types (Float64, Float32, Int64, etc.); JSON-encoded model/solution metadata
BQPJSON (.json v1.0.0)Exported as 1:n variable_ids; restore labels with QUBOTools.map_variables:bool, :spinWire format is :min; :max models are negated on write and restored with QUBOTools.castscale preserved; offset negated when canonicalizing :max to :minstate, value, and reads preserved (expanded on write, merged on read)JSON numbers parsed as Float64 (Model{Int,Float64,Int}); model metadata only (schema-validated synthesis)
Sample Tables (QUBOTools.write_samples / QUBOTools.read_samples)Recorded in file-level model.variables metadata when exported from a Model:bool, :spin:min, :maxRecorded in file-level model metadata when exported from a ModelFull SampleSet (state, value, reads)Imported values parsed as Float64 and reads as Int (SampleSet{Float64,Int}); embedded or sidecar JSON solution metadata
QUBO (.qubo)Exported as 0:n-1 (:dwave) or 1:n (:mqlib); restore with map_variables:bool only:min onlyPreserved in header comments❌Parsed as Float64; comment metadata
Qubist (.qh)Exported as 1:n; restore with map_variables:spin only:min only❌ (scale = 1.0, offset = 0.0)❌Parsed as Float64; no metadata
Rudy (.rudy)Exported as 0:n-1; restore with map_variablesConfigurable (:spin default):min onlyFolded into coefficients and constant term (scale = 1.0 on read)❌Parsed as Float64; timestamp comment only
MiniZinc (.mzn)Write-only (x1..xn):bool, :spin:min, :maxWritten as scale and offset parameters❌Write-only text; comment metadata
  1. QUBin (.qb / HDF5) — Use QUBOTools.write_model / QUBOTools.read_model (or QUBOTools.write_solution / QUBOTools.read_solution for standalone solutions) when full model and SampleSet round-trip fidelity is required:
    • Preserves non-consecutive and permuted Int or String variable orderings directly without external variable remapping.
    • Preserves HDF5-native numeric dataset element types T (Float64, Float32, Int64, Int32, etc.) for coefficients, scale, offset, and sample values—including 64-bit integers beyond Float64 precision such as 2^53 + 1.
    • Non-HDF5-native numeric types (such as BigFloat) are unsupported by HDF5 dataset creation and throw an exception on write. Model and solution metadata dictionaries are serialized as JSON strings and therefore follow JSON type conversions.
  2. BQPJSON (.json) — Use when JSON portability is required across tools:
    • Keep vars = QUBOTools.variables(src_model) (or serialize the ordered variable list alongside the workflow) and apply dst_model = QUBOTools.map_variables(vars, QUBOTools.read_model(path)) on import so permuted or string variable labels match their original 1:n positions.
    • If QUBOTools.sense(src_model) === QUBOTools.Max, write_model canonicalizes coefficients, offset, and sample evaluations to :min; restore the original maximization sense after read_model via QUBOTools.cast((QUBOTools.Min => QUBOTools.Max), dst_model).
    • read_model always constructs a Model{Int,Float64,Int}. IEEE 754 Float64 coefficients, scale, offset, and sample evaluations round-trip in Float64, whereas integer coefficients exceeding Float64 exact integer precision (|c| > 2^53, e.g. 2^53 + 1), Float32 values, or BigFloat values are converted to Float64.
  3. write_samples / read_samples (.csv) — Use when only the sample distribution (SampleSet) is exchanged between subproblem solvers and aggregators:
    • Sample multiplicities (reads), Float64 energies (value), sense, domain, bit_order, and JSON-compatible solution metadata round-trip in SampleSet{Float64,Int}.
    • read_samples always parses sample value cells as Float64 (parse(Float64, cell)) and reads as Int, so Float32 or BigFloat sample energies are converted to Float64 on import.

Defining a Custom File Format

import QUBOTools

function QUBOTools.Format{:super}(; super::Bool = true, kws...)
    settings = Dict{Symbol,Any}()

    settings[:super] = super

    return QUBOTools.Format{:super}(settings)
end

Writing Models

To write a model using SuperFormat, one must implement the

QUBOTools.write_model(io::IO, ::QUBOTools.AbstractModel{V,T,U}, ::QUBOTools.Format{:super}) where {V,T,U}

method for the custom format.

Info

This assumption is valid for text-based and binary formats. If you pretend to write in a format that does not rely on io::IO (such as QUBOTools.qubin_fmt), you should also implement

QUBOTools.write_model(filepath::AbstractString, ::QUBOTools.AbstractModel{V,T,U}, ::QUBOTools.Format{:super}) where {V,T,U}
function QUBOTools.write_model(io::IO, model::QUBOTools.AbstractModel, fmt::QUBOTools.Format{:super})
    if fmt[:super]
        println(io, "Format Type: SUPER")

        _write_super_model(io, model)
    else
        println(io, "Format Type: Regular")

        _write_regular_model(io, model)
    end

    return nothing
end

Reading Models

function QUBOTools.read_model(io::IO, fmt::QUBOTools.Format{:super})
    header = readline(io)

    if fmt[:super]
        @assert("SUPER" in header, "Invalid header: '$header' is not SUPER!")

        return _read_super_model(io)
    else
        return _read_regular_model(io)
    end
end
Info

QUBOTools.read_model must return a QUBOTools.Model instance.