Skip to content

Commit

Permalink
Merge pull request #10 from psrenergy/px/moi-pythoncall-ext
Browse files Browse the repository at this point in the history
Add `MOI_PythonCall` extension + Add
  • Loading branch information
pedromxavier authored Oct 1, 2023
2 parents f517c0f + 58031dd commit 973a41c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 3 deletions.
9 changes: 8 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QUBODrivers"
uuid = "a3f166f7-2cd3-47b6-9e1e-6fbfe0449eb0"
authors = ["pedromxavier <pedroxavier@psr-inc.com>", "pedroripper <pedroripper@psr-inc.com>", "AndradeTiago <tiago.andrade@psr-inc.com>", "joaquimg <joaquim@psr-inc.com>", "bernalde <dbernaln@purdue.edu>"]
version = "0.3.0"
version = "0.3.1"

[deps]
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
Expand All @@ -10,7 +10,14 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[weakdeps]
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"

[extensions]
MOI_PythonCall = ["PythonCall"]

[compat]
MathOptInterface = "1"
PythonCall = "0.9.14"
QUBOTools = "~0.9"
julia = "1.9"
10 changes: 10 additions & 0 deletions ext/MOI_PythonCall.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module MOI_PythonCall

import MathOptInterface as MOI
import PythonCall

if !hasmethod(MOI.Utilities.map_indices, Tuple{PythonCall.Py})
MOI.Utilities.map_indices(::Function, obj::PythonCall.Py) = obj
end

end # module MOI_PythonCall
4 changes: 4 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[deps]
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
PythonCall = "0.9.14"
21 changes: 21 additions & 0 deletions test/ext/MOI_PythonCall.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function test_moi_pythoncall_ext()
@testset "⚠ MathOptInterface-PythonCall ⚠" begin
py_objs = [
PythonCall.pylist([1, 2, 3]),
PythonCall.pydict(Dict("a" => 1, "b" => 2, "c" => 3)),
PythonCall.pytuple((1, 2, 3)),
PythonCall.pyset(Set([1, 2, 3])),
PythonCall.pyint(1),
PythonCall.pyfloat(1.0),
PythonCall.pycomplex(1.0 + 1.0im),
PythonCall.pystr("1"),
PythonCall.pybool(true),
]

for py_obj in py_objs
@test MOI.Utilities.map_indices(identity, py_obj) === py_obj
end
end

return nothing
end
9 changes: 9 additions & 0 deletions test/ext/ext.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include("MOI_PythonCall.jl")

function test_extensions()
@testset "□ Extensions" verbose = true begin
test_moi_pythoncall_ext()
end

return nothing
end
9 changes: 7 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
using Test
using PythonCall
using QUBODrivers
using QUBODrivers: QUBOTools
using QUBODrivers: MOI, QUBOTools

const VI = MOI.VariableIndex
const MOIU = MOI.Utilities
const VI = MOI.VariableIndex

include("assets/test_macro_throws.jl")

include("setup/setup.jl")
include("drivers/sampler_bundle.jl")

include("ext/ext.jl")

function main()
@testset "◈ ◈ ◈ QUBODrivers.jl Test Suite ◈ ◈ ◈" verbose = true begin
test_setup_macro()
test_sampler_bundle()
test_extensions()
end

return nothing
Expand Down

2 comments on commit 973a41c

@pedromxavier
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/92544

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.1 -m "<description of version>" 973a41c70fbaf15dd47f64139021c108ff92249c
git push origin v0.3.1

Please sign in to comment.