Skip to content

Commit

Permalink
Add attributes to access inner models
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromxavier committed Sep 19, 2024
1 parent ef079aa commit 6b74e59
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/attributes/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const CI = MOI.ConstraintIndex
import PseudoBooleanOptimization as PBO
import QUBOTools

import ..ToQUBO: Optimizer
import ..ToQUBO: Optimizer, PreQUBOModel, QUBOModel
import ..Encoding
import ..Virtual

Expand All @@ -20,6 +20,28 @@ abstract type CompilerAttribute <: MOI.AbstractOptimizerAttribute end

MOI.supports(::Optimizer, ::A) where {A<:CompilerAttribute} = true

@doc raw"""
SourceModel()
"""
struct SourceModel <: CompilerAttribute end

MOI.is_set_by_optimize(::SourceModel) = true

function MOI.get(model::Optimizer{T}, ::SourceModel)::PreQUBOModel{T} where {T}
return model.source_model
end

@doc raw"""
TargetModel()
"""
struct TargetModel <: CompilerAttribute end

MOI.is_set_by_optimize(::TargetModel) = true

function MOI.get(model::Optimizer{T}, ::TargetModel)::QUBOModel{T} where {T}
return model.target_model
end

@doc raw"""
CompilationTime()
"""
Expand Down
3 changes: 3 additions & 0 deletions test/integration/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ function test_interface_moi()
@test MOI.get(model, MOI.RawOptimizerAttribute("num_reads")) == 1_001

# ToQUBO Attributes
@test MOI.get(model, Attributes.SourceModel()) isa ToQUBO.PreQUBOModel{Float64}
@test MOI.get(model, Attributes.TargetModel()) isa ToQUBO.QUBOModel{Float64}

@test MOI.get(model, Attributes.Architecture()) isa QUBOTools.GenericArchitecture
MOI.set(model, Attributes.Architecture(), SuperArchitecture(true))
@test MOI.get(model, Attributes.Architecture()) isa SuperArchitecture
Expand Down

0 comments on commit 6b74e59

Please sign in to comment.