diff --git a/src/QUBODrivers.jl b/src/QUBODrivers.jl index 317fe96..baac227 100644 --- a/src/QUBODrivers.jl +++ b/src/QUBODrivers.jl @@ -22,7 +22,6 @@ export MOI, Sample, SampleSet, Spin, ↓, ↑ include("interface/sampler.jl") include("interface/attributes.jl") -include("library/sampler/attributes.jl") include("library/sampler/wrappers/moi.jl") include("library/sampler/wrappers/qubotools.jl") diff --git a/src/interface/sampler.jl b/src/interface/sampler.jl index efaf469..525986f 100644 --- a/src/interface/sampler.jl +++ b/src/interface/sampler.jl @@ -10,8 +10,6 @@ function sample end function sample(::S) where {S<:AbstractSampler} error("`QUBODrivers.sample` is not implemented for '$S'") - - return nothing end @doc raw""" diff --git a/src/library/drivers/IdentitySampler.jl b/src/library/drivers/IdentitySampler.jl index cc445c4..6580475 100644 --- a/src/library/drivers/IdentitySampler.jl +++ b/src/library/drivers/IdentitySampler.jl @@ -26,8 +26,6 @@ function sample_state(sampler::Optimizer{T}, n::Integer) where {T} v = QUBOTools.variable(sampler, i) error("Warm-start value for '$v' is missing") - - return nothing end end diff --git a/src/library/sampler/attributes.jl b/src/library/sampler/attributes.jl deleted file mode 100644 index a2471df..0000000 --- a/src/library/sampler/attributes.jl +++ /dev/null @@ -1,8 +0,0 @@ -const MOI_ATTRIBUTE = Union{ - MOI.Name, - MOI.Silent, - MOI.TimeLimitSec, - MOI.NumberOfThreads, - MOI.VariablePrimalStart, -} - diff --git a/src/library/sampler/wrappers/moi.jl b/src/library/sampler/wrappers/moi.jl index 73cb37b..67cbd59 100644 --- a/src/library/sampler/wrappers/moi.jl +++ b/src/library/sampler/wrappers/moi.jl @@ -6,27 +6,16 @@ MOI.supports_constraint( ) = false # ~ They are also binary -MOI.supports_constraint( - ::AbstractSampler, - ::Type{VI}, - ::Type{MOI.ZeroOne}, -) = true +MOI.supports_constraint(::AbstractSampler, ::Type{VI}, ::Type{MOI.ZeroOne}) = true -MOI.supports_constraint( - ::AbstractSampler, - ::Type{VI}, - ::Type{Spin}, -) = true +MOI.supports_constraint(::AbstractSampler, ::Type{VI}, ::Type{Spin}) = true # ~ Objective Function Support -MOI.supports( - ::AbstractSampler, - ::MOI.ObjectiveFunction{<:Any} -) = false +MOI.supports(::AbstractSampler, ::MOI.ObjectiveFunction{<:Any}) = false MOI.supports( ::AbstractSampler{T}, - ::MOI.ObjectiveFunction{<:Union{SQF{T}, SAF{T}, VI}} + ::MOI.ObjectiveFunction{<:Union{SQF{T},SAF{T},VI}}, ) where {T} = true # By default, all samplers are their own raw solvers. @@ -144,12 +133,8 @@ function MOI.get(sampler::AbstractSampler{T}, vp::MOI.VariablePrimal, vi::VI) wh if isempty(ω) error("Invalid result index '$i'; There are no solutions") - - return nothing elseif !(1 <= i <= m) error("Invalid result index '$i'; There are $(m) solutions") - - return nothing end j = QUBOTools.index(sampler, vi) @@ -161,49 +146,3 @@ end function MOI.get(sampler::AbstractSampler, ::MOI.NumberOfVariables) return QUBOTools.dimension(sampler) end - -# ~*~ File IO: Base API ~*~ # -# function Base.write( -# filename::AbstractString, -# sampler::AbstractSampler, -# fmt::QUBOTools.AbstractFormat = QUBOTools.infer_format(filename), -# ) -# return QUBOTools.write_model(filename, sampler, fmt) -# end - -# function Base.read!( -# filename::AbstractString, -# sampler::AbstractSampler, -# fmt::QUBOTools.AbstractFormat = QUBOTools.infer_format(filename), -# ) -# sampler.source = QUBOTools.read_model(filename, fmt) -# sampler.target = QUBOTools.format(sampler, sampler.source) - -# return sampler -# end - -function warm_start(sampler::AbstractSampler, i::Integer) - v = QUBOTools.variable_inv(sampler, i) - x = MOI.get(sampler, MOI.VariablePrimalStart(), v) - - if isnothing(x) - return nothing - else - return QUBOTools.cast( - source_domain(sampler) => target_domain(sampler), - round(Int, x), - ) - end -end - -function warm_start(sampler::AbstractSampler{T}) where {T} - n = MOI.get(sampler, MOI.NumberOfVariables()) - s = sizehint!(Dict{Int,Int}(), n) - - for i = 1:n - x = warm_start(sampler, i) - isnothing(x) || (s[i] = x) - end - - return s -end diff --git a/src/library/setup/error.jl b/src/library/setup/error.jl index 7075e28..bb7e6f5 100644 --- a/src/library/setup/error.jl +++ b/src/library/setup/error.jl @@ -10,6 +10,4 @@ end function setup_error(msg::AbstractString) throw(DriverSetupError(msg)) - - return nothing end diff --git a/src/library/setup/parse.jl b/src/library/setup/parse.jl index 6cf5b25..8e4a01b 100644 --- a/src/library/setup/parse.jl +++ b/src/library/setup/parse.jl @@ -4,8 +4,6 @@ end function __setup_parse(args...) setup_error("Macro takes 1 or 2 arguments, not '$(length(args))'") - - return nothing end function __setup_parse(expr) @@ -17,16 +15,12 @@ function __setup_parse(expr) setup_error( "Single argument must be either an identifier or a `begin ... end` block", ) - - return nothing end end function __setup_parse(id, block) if !(id isa Symbol) || !Base.isidentifier(id) setup_error("First argument must be a valid identifier") - - return nothing end if !(block isa Expr && block.head === :block) @@ -55,32 +49,24 @@ function __setup_parse_block(block; id = :Optimizer) if key === :name if !isnothing(name) setup_error("Duplicate entries for 'name'") - - return nothing end name = value elseif key === :version if !isnothing(version) setup_error("Duplicate entries for 'version'") - - return nothing end version = value elseif key === :attributes if !isnothing(attributes) setup_error("Duplicate entries for 'attributes' block") - - return nothing end if !(value isa Expr && value.head === :block) setup_error( "Sampler attributes must be placed inside a `begin ... end` block", ) - - return nothing end attributes = _AttrSpec[] @@ -96,25 +82,17 @@ function __setup_parse_block(block; id = :Optimizer) setup_error( "Sampler configuration keys must be either 'name', 'version' or 'attributes', not '$key'", ) - - return nothing end else setup_error("Sampler configuration keys must be a valid identifiers") - - return nothing end else setup_error("Sampler configuration must be provided by `key = value` pairs") - - return nothing end end if isnothing(name) setup_error("'name' entry is missing") - - return nothing end if isnothing(version) @@ -149,16 +127,12 @@ function __setup_parse_attr(stmt) if attr isa Symbol # ~ MOI attribute only if !(Base.isidentifier(attr)) setup_error("Attribute identifier '$attr' is not valid") - - return nothing end opt_attr = attr elseif attr isa String # ~ Raw attribute only if isempty(attr) setup_error("Raw attribute key can't be an empty string") - - return nothing end raw_attr = attr @@ -168,8 +142,6 @@ function __setup_parse_attr(stmt) if attr isa Symbol if !(Base.isidentifier(attr)) setup_error("Attribute identifier '$attr' is not a valid one") - - return nothing end opt_attr = attr @@ -181,18 +153,12 @@ function __setup_parse_attr(stmt) if opt_attr isa Symbol && raw_attr isa String if !(Base.isidentifier(opt_attr)) setup_error("Attribute identifier '$opt_attr' is not a valid one") - - return nothing end else setup_error("Invalid attribute identifier '$name($raw)'") - - return nothing end else setup_error("Invalid attribute identifier '$attr'") - - return nothing end elseif attr isa Expr && (attr.head === :ref || attr.head === :call) opt_attr, raw_attr = attr.args @@ -200,18 +166,12 @@ function __setup_parse_attr(stmt) if opt_attr isa Symbol && raw_attr isa String if !(Base.isidentifier(opt_attr)) setup_error("Attribute identifier '$opt_attr' is not a valid one") - - return nothing end else setup_error("Invalid attribute identifier '$name[$raw_attr]'") - - return nothing end else setup_error("Invalid attribute signature '$attr'") - - return nothing end if !isnothing(raw_attr) diff --git a/src/library/setup/quote.jl b/src/library/setup/quote.jl index daeb4ae..bb4886e 100644 --- a/src/library/setup/quote.jl +++ b/src/library/setup/quote.jl @@ -236,27 +236,19 @@ function __setup_quote_moi_attrs(spec::_SamplerSpec) function MOI.set(sampler::$(Optimizer){T}, ::MOI.VariablePrimalStart, vi::VI, value) where {T} if !(isnothing(value) || value isa Real) error("Value for 'MOI.VariablePrimalStart' must be an integer, or 'nothing'") - - return nothing end if !isnothing(value) if !(value isa Real && isinteger(value)) error("Value for 'MOI.VariablePrimalStart' must be an integer, or 'nothing'") - - return nothing end X = QUBOTools.domain(sampler) if X === QUBOTools.BoolDomain && !(value == zero(value) || value == one(value)) error("Integer value for 'MOI.VariablePrimalStart' must be either '0' or '1'") - - return nothing elseif X === QUBOTools.SpinDomain && !(value == -one(value) || value == one(value)) error("Integer value for 'MOI.VariablePrimalStart' must be either '-1' or '1'") - - return nothing end end