diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 3feee67..bd9595e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -13,10 +13,10 @@ jobs: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@latest with: - version: '1.6' + version: '1.10' - name: Install dependencies - run: julia --project=docs/ -e 'using Pkg; Pkg.instantiate()' + run: julia --project=docs/ -e 'using Pkg; Pkg.develop(path=@__DIR__); Pkg.instantiate()' - name: Build and deploy env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token - run: julia --project=docs/ docs/make.jl \ No newline at end of file + run: julia --project=docs/ docs/make.jl diff --git a/.github/workflows/multidocs.yml b/.github/workflows/multidocs.yml index 272c819..de671f5 100644 --- a/.github/workflows/multidocs.yml +++ b/.github/workflows/multidocs.yml @@ -11,9 +11,9 @@ jobs: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@latest with: - version: '1.6' + version: '1.10' - name: Install dependencies - run: julia --project=docs/ -e 'using Pkg; Pkg.instantiate()' + run: julia --project=docs/ -e 'using Pkg; Pkg.develop(path=@__DIR__); Pkg.instantiate()' - name: Aggregate and deploy run: | git config user.name github-actions diff --git a/Project.toml b/Project.toml index de770d2..58dec6a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,17 +1,19 @@ name = "QUBO" uuid = "ce8c2e91-a970-4681-856b-16178c24a30c" -authors = ["pedromxavier ", "pedroripper ", "joaquimg ", "AndradeTiago ", "bernalde "] -version = "0.3.1" +authors = ["pedromxavier ", "pedroripper ", "joaquimg ", "AndradeTiago ", "bernalde "] +version = "0.3.2" [deps] JuMP = "4076af6c-e467-56ae-b986-b466b2749572" +MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" QUBODrivers = "a3f166f7-2cd3-47b6-9e1e-6fbfe0449eb0" QUBOTools = "60eb5b62-0a39-4ddc-84c5-97d2adff9319" ToQUBO = "9a412ddf-83fa-43b6-9748-7843c851aa65" [compat] -JuMP = "1" -QUBODrivers = "0.3.2" -QUBOTools = "0.9.3" -ToQUBO = "0.1.8" -julia = "1.6" +JuMP = "1" +MathOptInterface = "1" +QUBODrivers = "0.3.3" +QUBOTools = "0.10" +ToQUBO = "0.1.9" +julia = "1.9" diff --git a/docs/Project.toml b/docs/Project.toml index db95749..12c66c6 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -4,3 +4,6 @@ MultiDocumenter = "87ed4bf0-c935-4a67-83c3-2a03bee4197c" QUBODrivers = "a3f166f7-2cd3-47b6-9e1e-6fbfe0449eb0" QUBOTools = "60eb5b62-0a39-4ddc-84c5-97d2adff9319" ToQUBO = "9a412ddf-83fa-43b6-9748-7843c851aa65" + +[compat] +Documenter = "1" diff --git a/docs/make.jl b/docs/make.jl index f8b1bae..160d3b4 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,21 +1,26 @@ using Documenter +using QUBO + +# Set up to run docstrings with jldoctest +DocMeta.setdocmeta!(QUBO, :DocTestSetup, :(using QUBO); recursive = true) makedocs(; - doctest = true, - clean = true, - format = Documenter.HTML( - assets = ["assets/extra_styles.css", "assets/favicon.ico"], + doctest = true, + clean = true, + warnonly = [:missing_docs], + format = Documenter.HTML( # + assets = ["assets/extra_styles.css", "assets/favicon.ico"], mathengine = Documenter.KaTeX(), - sidebar_sitename = false, + sidebar_sitename = false ), sitename = "QUBO.jl", - authors = "Pedro Xavier and Pedro Ripper and Tiago Andrade and Joaquim Garcia and David Bernal", - pages = ["Home" => "index.md"], - workdir = ".", + authors = "Pedro Maciel Xavier and Pedro Ripper and Tiago Andrade and Joaquim Dias Garcia and David E. Bernal Neira", + pages = ["Home" => "index.md"], + workdir = @__DIR__ ) if "--skip-deploy" ∈ ARGS @warn "Skipping deployment" else - deploydocs(repo = raw"github.com/psrenergy/QUBO.jl.git", push_preview = true) + deploydocs(repo = raw"github.com/JuliaQUBO/QUBO.jl.git", push_preview = true) end diff --git a/docs/multimake.jl b/docs/multimake.jl index 4936611..2f07f7a 100644 --- a/docs/multimake.jl +++ b/docs/multimake.jl @@ -8,25 +8,25 @@ docs = [ upstream = joinpath(temp_dir, "QUBO.jl"), path = "QUBO.jl", name = "QUBO.jl", - giturl = "https://github.com/psrenergy/QUBO.jl.git", + giturl = "https://github.com/JuliaQUBO/QUBO.jl.git", ), MultiDocumenter.MultiDocRef( upstream = joinpath(temp_dir, "ToQUBO.jl"), path = "ToQUBO.jl", name = "ToQUBO.jl", - giturl = "https://github.com/psrenergy/ToQUBO.jl.git", + giturl = "https://github.com/JuliaQUBO/ToQUBO.jl.git", ), MultiDocumenter.MultiDocRef( upstream = joinpath(temp_dir, "QUBODrivers.jl"), path = "QUBODrivers.jl", name = "QUBODrivers.jl", - giturl = "https://github.com/psrenergy/QUBODrivers.jl.git", + giturl = "https://github.com/JuliaQUBO/QUBODrivers.jl.git", ), MultiDocumenter.MultiDocRef( upstream = joinpath(temp_dir, "QUBOTools.jl"), path = "QUBOTools.jl", name = "QUBOTools.jl", - giturl = "https://github.com/psrenergy/QUBOTools.jl.git", + giturl = "https://github.com/JuliaQUBO/QUBOTools.jl.git", ), ] diff --git a/src/QUBO.jl b/src/QUBO.jl index bac1862..1ecc1b3 100644 --- a/src/QUBO.jl +++ b/src/QUBO.jl @@ -1,16 +1,41 @@ module QUBO import JuMP +import MathOptInterface as MOI -import QUBOTools, QUBODrivers, ToQUBO -export QUBOTools, QUBODrivers, ToQUBO +# QUBOTools +import QUBOTools +import QUBOTools: ↑, ↓ +import QUBOTools: reads +const QUBOTools_MOI = Base.get_extension(QUBOTools, :QUBOTools_MOI) +const Spin = QUBOTools_MOI.Spin +const NumberOfReads = QUBOTools_MOI.NumberOfReads + +export QUBOTools +export ↑, ↓ +export reads +export Spin, NumberOfReads + +# QUBODrivers +import QUBODrivers import QUBODrivers: ExactSampler, IdentitySampler, RandomSampler + +export QUBODrivers export ExactSampler, IdentitySampler, RandomSampler -import QUBODrivers: Spin -export Spin +# ToQUBO +import ToQUBO +export ToQUBO + +include("wrapper.jl") + +function source_model(model::JuMP.Model) + return JuMP.get_attribute(model, ToQUBO.Attributes.SourceModel()) +end -include("jump/wrapper.jl") +function target_model(model::JuMP.Model) + return JuMP.get_attribute(model, ToQUBO.Attributes.TargetModel()) +end end # module QUBO diff --git a/src/jump/wrapper.jl b/src/wrapper.jl similarity index 53% rename from src/jump/wrapper.jl rename to src/wrapper.jl index a32ace7..2dab505 100644 --- a/src/jump/wrapper.jl +++ b/src/wrapper.jl @@ -9,8 +9,8 @@ function JuMP.build_variable(::Function, info::JuMP.VariableInfo, ::Type{Spin}; return SpinInfo(info) end -function JuMP.add_variable(model::JuMP.Model, info::SpinInfo, name::String) - x = JuMP.add_variable(model, JuMP.ScalarVariable(info.info), name) +function JuMP.add_variable(model::JuMP.Model, spin_info::SpinInfo, name::String) + x = JuMP.add_variable(model, JuMP.ScalarVariable(spin_info.info), name) JuMP.@constraint(model, x ∈ Spin()) @@ -19,3 +19,13 @@ end JuMP.in_set_string(::MIME"text/plain", ::Spin) = "spin" JuMP.in_set_string(::MIME"text/latex", ::Spin) = raw"\in \left\langle{-1, 1}\right\rangle" + +# Number of Reads +@doc raw""" + reads(model::JuMP.Model; result::Integer = 1) + +Returns the multiplicity of a given result. +""" +function QUBOTools.reads(model::JuMP.Model; result::Integer = 1) + return JuMP.get_attribute(model, NumberOfReads(result))::Integer +end diff --git a/test/spin_model.jl b/test/spin_model.jl index 41e7ff6..c6a35ea 100644 --- a/test/spin_model.jl +++ b/test/spin_model.jl @@ -14,8 +14,9 @@ function test_spin_model() optimize!(model) - @test value.(s) ≈ [1, 1, -1] || value.(s) ≈ [1, -1, 1] || value.(s) ≈ [-1, 1, 1] + @test value.(s) ≈ [↑, ↑, ↓] || value.(s) ≈ [↑, ↓, ↑] || value.(s) ≈ [↓, ↑, ↑] @test objective_value(model) ≈ -3.0 + @test reads(model) == 1 end return nothing