Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MOI_PythonCall extension + Add #10

Merged
merged 1 commit into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link

Choose a reason for hiding this comment

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

What was the motivation for adding as an extension?

MOI will always be loaded by QUBODrivers.jl (it is a direct dependency).

This method could have been added directly to src.

Copy link
Member Author

@pedromxavier pedromxavier Oct 3, 2023

Choose a reason for hiding this comment

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

MOI is always loaded but PythonCall isn't.
PythonCall is also double-trouble: besides being heavy, precompiling it involves installing and managing python deps. We don't want to add it as a QUBODrivers dep

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
Loading