Attributes
API
QUBODrivers.SamplerAttribute — Type
SamplerAttributeAbstract supertype for optimizer attributes declared by QUBODrivers samplers.
Attributes generated by QUBODrivers.@setup, such as NumberOfReads, subtype SamplerAttribute and can be used with MOI.get, MOI.set, and MOI.supports.
QUBODrivers.RawSamplerAttribute — Type
RawSamplerAttribute{key}QUBODrivers raw optimizer attribute identified by a string-like key.
RawSamplerAttribute("num_reads") is the QUBODrivers counterpart of MOI.RawOptimizerAttribute("num_reads"). Generated samplers route MOI raw attributes through this type so solver-specific attributes can share the same storage and validation as typed sampler attributes.
QUBODrivers.@raw_attr_str — Macro
@raw_attr_str("key")Create a RawSamplerAttribute type for dispatch.
This macro is useful when extending validation for a particular raw attribute:
function MOI.set(sampler::Optimizer, attr::QUBODrivers.@raw_attr_str("seed"), value)
QUBODrivers.set_raw_attr!(sampler, attr, value)
return nothing
endQUBODrivers.get_raw_attr — Function
get_raw_attr(sampler, attr)Return a raw sampler attribute value.
Generated optimizers first look in the sampler's attribute storage and then fall back to default_raw_attr. Most users access this through MOI.get(sampler, MOI.RawOptimizerAttribute(name)) or a typed attribute.
QUBODrivers.set_raw_attr! — Function
set_raw_attr!(sampler, attr, value)Store a raw sampler attribute value.
Generated optimizers use this hook from MOI.set. Sampler implementations can specialize it, or specialize MOI.set for a RawSamplerAttribute, to validate backend-specific options before storing them.
QUBODrivers.default_raw_attr — Function
default_raw_attr(sampler, attr)Return the default value for a raw sampler attribute.
Methods are generated by QUBODrivers.@setup for declared attributes. Sampler implementations may add methods to customize defaults for additional raw attributes.
An advanced example
module SuperSampler
import QUBODrivers
import QUBODrivers: QUBOTools
import MathOptInterface as MOI
QUBODrivers.@setup Optimizer begin
name = "Super Sampler"
version = v"1.0.2"
attributes = begin
NumberOfReads["num_reads"]::Integer = 100_000
SuperAttribute["super_attr"]::String = "super"
end
end
function MOI.set(sampler::Optimizer, attr::raw_attr"", value)
if !(value isa Integer)
error("'num_reads' must be an integer")
else
QUBODrivers.set_raw_attr!(sampler, attr, value)
end
return nothing
end
function MOI.set(sampler::Optimizer, attr::raw_attr"super_attr", value)
if !(value isa AbstractString)
error("'super_attr' must be a string")
elseif !(value ∈ ("super", "ultra", "mega"))
error("'super_attr' must be one of the following: 'super', 'ultra', 'mega'")
else
QUBODrivers.set_raw_attr!(sampler, attr, value)
end
return nothing
end
end # SuperSampler module