Skip to content

Commit

Permalink
Add MOI_PythonCall extension + Add
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromxavier committed Sep 30, 2023
1 parent f517c0f commit 58031dd
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

0 comments on commit 58031dd

Please sign in to comment.