File Formats
| Format | Read | Write | Model | Solutions | Start | Metadata |
|---|---|---|---|---|---|---|
| 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:
| Carrier | Variable Mapping | Domains | Senses | Scale & Offset | Solutions & reads | Numeric & Metadata Fidelity |
|---|---|---|---|---|---|---|
QUBin (.qb / HDF5) | Exact 1:n Int or String order preserved | :bool, :spin | :min, :max | Exact scale and offset in dataset type T | Full 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, :spin | Wire format is :min; :max models are negated on write and restored with QUBOTools.cast | scale preserved; offset negated when canonicalizing :max to :min | state, 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, :max | Recorded in file-level model metadata when exported from a Model | Full 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 only | Preserved 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_variables | Configurable (:spin default) | :min only | Folded 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, :max | Written as scale and offset parameters | ❌ | Write-only text; comment metadata |
Recommended Carrier Contracts and Numeric Boundaries
QUBin(.qb/ HDF5) — UseQUBOTools.write_model/QUBOTools.read_model(orQUBOTools.write_solution/QUBOTools.read_solutionfor standalone solutions) when full model andSampleSetround-trip fidelity is required:- Preserves non-consecutive and permuted
IntorStringvariable orderings directly without external variable remapping. - Preserves HDF5-native numeric dataset element types
T(Float64,Float32,Int64,Int32, etc.) for coefficients,scale,offset, and samplevalues—including 64-bit integers beyondFloat64precision such as2^53 + 1. - Non-HDF5-native numeric types (such as
BigFloat) are unsupported by HDF5 dataset creation and throw an exception on write. Model and solutionmetadatadictionaries are serialized as JSON strings and therefore follow JSON type conversions.
- Preserves non-consecutive and permuted
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 applydst_model = QUBOTools.map_variables(vars, QUBOTools.read_model(path))on import so permuted or string variable labels match their original1:npositions. - If
QUBOTools.sense(src_model) === QUBOTools.Max,write_modelcanonicalizes coefficients,offset, and sampleevaluations to:min; restore the original maximization sense afterread_modelviaQUBOTools.cast((QUBOTools.Min => QUBOTools.Max), dst_model). read_modelalways constructs aModel{Int,Float64,Int}. IEEE 754Float64coefficients,scale,offset, and sampleevaluations round-trip inFloat64, whereas integer coefficients exceedingFloat64exact integer precision (|c| > 2^53, e.g.2^53 + 1),Float32values, orBigFloatvalues are converted toFloat64.
- Keep
write_samples/read_samples(.csv) — Use when only the sample distribution (SampleSet) is exchanged between subproblem solvers and aggregators:- Sample multiplicities (
reads),Float64energies (value),sense,domain,bit_order, and JSON-compatible solutionmetadataround-trip inSampleSet{Float64,Int}. read_samplesalways parses samplevaluecells asFloat64(parse(Float64, cell)) andreadsasInt, soFloat32orBigFloatsample energies are converted toFloat64on import.
- Sample multiplicities (
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)
endWriting 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.
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
endReading 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
endQUBOTools.read_model must return a QUBOTools.Model instance.