-
Notifications
You must be signed in to change notification settings - Fork 0
Add QUBODrivers 0.6 benchmark conformance #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,88 +55,156 @@ function __init__() | |
| return nothing | ||
| end | ||
|
|
||
| QUBODrivers.@setup Optimizer begin | ||
| name = "MQLib" | ||
| version = __VERSION__ | ||
| attributes = begin | ||
| RandomSeed["seed"]::Union{Integer,Nothing} = nothing | ||
| QUBODrivers.@setup Optimizer begin | ||
| name = "MQLib" | ||
| version = __VERSION__ | ||
| attributes = begin | ||
| RandomSeed["seed"]::Union{Integer,Nothing} = nothing | ||
| NumberOfReads["num_reads"]::Integer = 1 | ||
| Heuristic["heuristic"]::Union{String,Nothing} = nothing | ||
| end | ||
| end | ||
|
|
||
| function QUBODrivers.sample(sampler::Optimizer{T}) where {T} | ||
| n, L, Q, α, β = QUBOTools.qubo(sampler, :dict; sense = :max, domain = :bool) | ||
|
|
||
| num_reads = MOI.get(sampler, MQLib.NumberOfReads()) | ||
| silent = MOI.get(sampler, MOI.Silent()) | ||
| heuristic = MOI.get(sampler, MQLib.Heuristic()) | ||
| random_seed = MOI.get(sampler, MQLib.RandomSeed()) | ||
| time_limit_sec = MOI.get(sampler, MOI.TimeLimitSec()) | ||
|
|
||
| if num_reads <= 0 | ||
| error("Number of reads must be a positive integer") | ||
| end | ||
|
|
||
| if !isnothing(heuristic) && !haskey(_HEURISTICS, heuristic) | ||
| error("Invalid QUBO Heuristic code '$heuristic'") | ||
| end | ||
|
|
||
| end | ||
| end | ||
|
|
||
| QUBODrivers.honors_final_reads(::Type{<:Optimizer}) = true | ||
| QUBODrivers.enforces_time_limit(::Type{<:Optimizer}) = true | ||
|
|
||
| function QUBODrivers.sample(sampler::Optimizer{T}) where {T} | ||
| n, L, Q, α, β = QUBOTools.qubo(sampler, :dict; sense = :max, domain = :bool) | ||
|
|
||
| num_reads = MOI.get(sampler, MQLib.NumberOfReads()) | ||
| final_num_reads = _mqlib_final_number_of_reads(sampler, num_reads) | ||
| silent = MOI.get(sampler, MOI.Silent()) | ||
| heuristic = MOI.get(sampler, MQLib.Heuristic()) | ||
| random_seed = MOI.get(sampler, MQLib.RandomSeed()) | ||
| metadata_seed = random_seed | ||
| time_limit_sec = MOI.get(sampler, MOI.TimeLimitSec()) | ||
|
|
||
| if num_reads <= 0 | ||
| error("Number of reads must be a positive integer") | ||
| end | ||
|
|
||
| if isnothing(final_num_reads) || final_num_reads <= 0 | ||
| error("Final number of reads must be a positive integer") | ||
| end | ||
|
|
||
| if !isnothing(heuristic) && !haskey(_HEURISTICS, heuristic) | ||
| error("Invalid QUBO Heuristic code '$heuristic'") | ||
| end | ||
|
|
||
| if !isnothing(random_seed) | ||
| random_seed %= 65_536 | ||
| end | ||
|
|
||
| run_time_limit = if isnothing(time_limit_sec) | ||
| 1.0 / num_reads | ||
| else | ||
| time_limit_sec / num_reads | ||
| end | ||
|
|
||
| metadata = Dict{String,Any}( | ||
| "time" => Dict{String,Any}(), | ||
| "origin" => Dict{String,Any}( | ||
| "name" => "MQLib", | ||
| "version" => __VERSION__, | ||
| "heuristic" => heuristic, | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| run_time_limit = if isnothing(time_limit_sec) | ||
| 1.0 / final_num_reads | ||
| else | ||
| time_limit_sec / final_num_reads | ||
| end | ||
|
|
||
| samples, effective_time = if _mqlib_can_use_c_api(heuristic) | ||
| _sample_with_c_api( | ||
| T, | ||
| n, | ||
| L, | ||
| Q, | ||
| α, | ||
| β; | ||
| num_reads, | ||
| silent, | ||
| heuristic, | ||
| random_seed, | ||
| run_time_limit, | ||
| α, | ||
| β; | ||
| num_reads = final_num_reads, | ||
| silent, | ||
| heuristic, | ||
| random_seed, | ||
| run_time_limit, | ||
| ) | ||
| else | ||
| _sample_with_executable( | ||
| T, | ||
| n, | ||
| L, | ||
| Q, | ||
| α, | ||
| β; | ||
| num_reads, | ||
| silent, | ||
| heuristic, | ||
| random_seed, | ||
| run_time_limit, | ||
| ) | ||
| end | ||
|
|
||
| metadata["time"]["effective"] = effective_time | ||
|
|
||
| return QUBOTools.SampleSet{T}(samples, metadata; sense = :max, domain = :bool) | ||
| end | ||
|
|
||
| function _sample_with_executable( | ||
| α, | ||
| β; | ||
| num_reads = final_num_reads, | ||
| silent, | ||
| heuristic, | ||
| random_seed, | ||
| run_time_limit, | ||
| ) | ||
| end | ||
|
|
||
| metadata = _mqlib_metadata( | ||
| heuristic; | ||
| final_num_reads, | ||
| sample_count = length(samples), | ||
| effective_time, | ||
| random_seed = metadata_seed, | ||
| ) | ||
|
|
||
| return QUBOTools.SampleSet{T}(samples, metadata; sense = :max, domain = :bool) | ||
| end | ||
|
|
||
| function _mqlib_final_number_of_reads(sampler::Optimizer, num_reads::Integer) | ||
| if isdefined(QUBODrivers, :final_number_of_reads) | ||
| return QUBODrivers.final_number_of_reads(sampler) | ||
| else | ||
| return num_reads | ||
| end | ||
| end | ||
|
|
||
| function _mqlib_metadata( | ||
| heuristic::Union{String,Nothing}; | ||
| final_num_reads::Integer, | ||
| sample_count::Integer, | ||
| effective_time::Real, | ||
| random_seed::Union{Integer,Nothing}, | ||
| ) | ||
| if isdefined(QUBODrivers, :_sampler_metadata) | ||
| metadata = QUBODrivers._sampler_metadata( | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blocking: with the currently allowed registered
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 1768fc2. |
||
| origin = "MQLib.jl", | ||
| algorithm_name = _mqlib_algorithm_name(heuristic), | ||
| backend_name = "MQLib", | ||
| backend_version = __VERSION__, | ||
| execution_mode = _mqlib_execution_mode(heuristic), | ||
| optimizer_evaluations = final_num_reads, | ||
| number_of_reads = final_num_reads, | ||
| final_number_of_reads = sample_count, | ||
| status = "locally_solved", | ||
| termination_status = MOI.LOCALLY_SOLVED, | ||
| ) | ||
| metadata["seeds"] = _mqlib_seed_metadata(random_seed) | ||
| metadata["time"] = Dict{String,Any}("effective" => effective_time) | ||
|
|
||
| return metadata | ||
| else | ||
| return Dict{String,Any}( | ||
| "time" => Dict{String,Any}("effective" => effective_time), | ||
| "seeds" => _mqlib_seed_metadata(random_seed), | ||
| "origin" => Dict{String,Any}( | ||
| "name" => "MQLib", | ||
| "version" => __VERSION__, | ||
| "heuristic" => heuristic, | ||
| ), | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| function _mqlib_seed_metadata(random_seed::Union{Integer,Nothing}) | ||
| seeds = Dict{String,Any}() | ||
| if !isnothing(random_seed) | ||
| seeds["sampler"] = random_seed | ||
| end | ||
|
|
||
| return seeds | ||
| end | ||
|
|
||
| function _mqlib_algorithm_name(heuristic::Union{String,Nothing}) | ||
| return something(heuristic, "Hyper-Heuristic") | ||
| end | ||
|
|
||
| function _mqlib_execution_mode(heuristic::Union{String,Nothing}) | ||
| return isnothing(heuristic) ? "hyperheuristic" : "heuristic" | ||
| end | ||
|
|
||
| function _sample_with_executable( | ||
| ::Type{T}, | ||
| n::Integer, | ||
| L, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nonblocking: This says QUBODrivers 0.6, but the PR now requires
QUBODrivers = "0.6.1". Please update the entry to name 0.6.1 so the release notes do not imply v0.6.0 remains acceptable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in c419e68. The changelog now names QUBODrivers 0.6.1 to match the compat bound. Verified with a compat/changelog assertion,
Pkg.test, native C ABI smoke, andgit diff --check.