From 71df92b1035167023e1a30080eac91aff259da90 Mon Sep 17 00:00:00 2001 From: pedromxavier Date: Fri, 15 Mar 2024 16:39:24 -0300 Subject: [PATCH 1/5] Create Checkpoint --- Project.toml | 16 +++++++++------- docs/Project.toml | 3 +++ docs/make.jl | 21 +++++++++++++-------- src/QUBO.jl | 27 ++++++++++++++++++++++----- src/{jump => }/wrapper.jl | 10 ++++++++++ test/spin_model.jl | 3 ++- 6 files changed, 59 insertions(+), 21 deletions(-) rename src/{jump => }/wrapper.jl (71%) diff --git a/Project.toml b/Project.toml index ced8316..521ca0b 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.2.0" +authors = ["pedromxavier ", "pedroripper ", "joaquimg ", "AndradeTiago ", "bernalde "] +version = "0.3.0" [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.2" -QUBOTools = "0.8" -ToQUBO = "0.1.6" -julia = "1.6" +JuMP = "1" +MathOptInterface = "1" +QUBODrivers = "0.3" +QUBOTools = "0.9" +ToQUBO = "0.1.7" +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..86063ca 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,17 +1,22 @@ 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 diff --git a/src/QUBO.jl b/src/QUBO.jl index bac1862..455d8fa 100644 --- a/src/QUBO.jl +++ b/src/QUBO.jl @@ -1,16 +1,33 @@ module QUBO import JuMP +import MathOptInterface as MOI -import QUBOTools, QUBODrivers, ToQUBO -export QUBOTools, QUBODrivers, ToQUBO +# QUBOTools +import QUBOTools +import QUBOTools: ↑, ↓ +import QUBOTools: reads +import QUBOTools: __moi_spin_set, __moi_num_reads +const Spin = QUBOTools.__moi_spin_set() +const NumberOfReads = QUBOTools.__moi_num_reads() + +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("jump/wrapper.jl") +include("wrapper.jl") end # module QUBO diff --git a/src/jump/wrapper.jl b/src/wrapper.jl similarity index 71% rename from src/jump/wrapper.jl rename to src/wrapper.jl index a32ace7..13476f4 100644 --- a/src/jump/wrapper.jl +++ b/src/wrapper.jl @@ -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)) +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 From ddb2d105c8283ce551c52da80ebd2020add349f6 Mon Sep 17 00:00:00 2001 From: Pedro Maciel Xavier Date: Thu, 19 Sep 2024 10:53:08 -0400 Subject: [PATCH 2/5] Require `QUBODrivers >= 0.3.3` --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 6812d3e..7b2986a 100644 --- a/Project.toml +++ b/Project.toml @@ -13,7 +13,7 @@ ToQUBO = "9a412ddf-83fa-43b6-9748-7843c851aa65" [compat] JuMP = "1" MathOptInterface = "1" -QUBODrivers = "0.3" +QUBODrivers = "0.3.3" QUBOTools = "0.9" ToQUBO = "0.1.8" julia = "1.9" From b3f95d3208c1c79212df73607865e53156fbf454 Mon Sep 17 00:00:00 2001 From: Pedro Maciel Xavier Date: Wed, 25 Sep 2024 19:54:30 -0400 Subject: [PATCH 3/5] Update Versions --- Project.toml | 6 +++--- src/QUBO.jl | 14 +++++++++++--- src/wrapper.jl | 6 +++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Project.toml b/Project.toml index 7b2986a..58dec6a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "QUBO" uuid = "ce8c2e91-a970-4681-856b-16178c24a30c" authors = ["pedromxavier ", "pedroripper ", "joaquimg ", "AndradeTiago ", "bernalde "] -version = "0.3.2-dev" +version = "0.3.2" [deps] JuMP = "4076af6c-e467-56ae-b986-b466b2749572" @@ -14,6 +14,6 @@ ToQUBO = "9a412ddf-83fa-43b6-9748-7843c851aa65" JuMP = "1" MathOptInterface = "1" QUBODrivers = "0.3.3" -QUBOTools = "0.9" -ToQUBO = "0.1.8" +QUBOTools = "0.10" +ToQUBO = "0.1.9" julia = "1.9" diff --git a/src/QUBO.jl b/src/QUBO.jl index 455d8fa..1ecc1b3 100644 --- a/src/QUBO.jl +++ b/src/QUBO.jl @@ -7,10 +7,10 @@ import MathOptInterface as MOI import QUBOTools import QUBOTools: ↑, ↓ import QUBOTools: reads -import QUBOTools: __moi_spin_set, __moi_num_reads -const Spin = QUBOTools.__moi_spin_set() -const NumberOfReads = QUBOTools.__moi_num_reads() +const QUBOTools_MOI = Base.get_extension(QUBOTools, :QUBOTools_MOI) +const Spin = QUBOTools_MOI.Spin +const NumberOfReads = QUBOTools_MOI.NumberOfReads export QUBOTools export ↑, ↓ @@ -30,4 +30,12 @@ export ToQUBO include("wrapper.jl") +function source_model(model::JuMP.Model) + return JuMP.get_attribute(model, ToQUBO.Attributes.SourceModel()) +end + +function target_model(model::JuMP.Model) + return JuMP.get_attribute(model, ToQUBO.Attributes.TargetModel()) +end + end # module QUBO diff --git a/src/wrapper.jl b/src/wrapper.jl index 13476f4..2dab505 100644 --- a/src/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()) @@ -27,5 +27,5 @@ JuMP.in_set_string(::MIME"text/latex", ::Spin) = raw"\in \left\langle{-1, 1}\rig Returns the multiplicity of a given result. """ function QUBOTools.reads(model::JuMP.Model; result::Integer = 1) - return JuMP.get_attribute(model, NumberOfReads(result)) + return JuMP.get_attribute(model, NumberOfReads(result))::Integer end From f58ed799ea1d9cd27171b13676c670127a04c47f Mon Sep 17 00:00:00 2001 From: Pedro Maciel Xavier Date: Wed, 25 Sep 2024 22:55:29 -0400 Subject: [PATCH 4/5] Fix url --- docs/make.jl | 2 +- docs/multimake.jl | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 86063ca..160d3b4 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -22,5 +22,5 @@ makedocs(; 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", ), ] From 04eebbcd4d4137cf60c6772f7a345c5b8ffb79bd Mon Sep 17 00:00:00 2001 From: Pedro Maciel Xavier Date: Wed, 25 Sep 2024 22:59:26 -0400 Subject: [PATCH 5/5] Fix docs script --- .github/workflows/docs.yml | 6 +++--- .github/workflows/multidocs.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) 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