Partial implementation of parallel_solve

This commit is contained in:
2021-05-25 11:23:24 -05:00
parent e72831039c
commit 98024dea95
9 changed files with 100 additions and 44 deletions

View File

@@ -6,20 +6,16 @@ __precompile__(false)
module MIPLearn
using PyCall
export JuMPInstance
export LearningSolver
export @feature
export @category
miplearn = pyimport("miplearn")
global miplearn = pyimport("miplearn")
global traceback = pyimport("traceback")
include("utils/log.jl")
include("utils/exceptions.jl")
include("instance/abstract.jl")
include("instance/jump.jl")
include("instance/file.jl")
include("solvers/jump.jl")
include("solvers/learning.jl")
include("solvers/macros.jl")
include("instance/jump.jl")
include("instance/file.jl")
end # module

8
src/instance/abstract.jl Normal file
View File

@@ -0,0 +1,8 @@
# MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization
# Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved.
# Released under the modified BSD license. See COPYING.md for more details.
abstract type Instance
end

View File

@@ -55,12 +55,16 @@ end
struct FileInstance <: Instance
py::PyCall.PyObject
filename::AbstractString
end
function FileInstance(filename)::FileInstance
filename isa AbstractString || error("filename should be a string. Found $(typeof(filename)) instead.")
return FileInstance(PyFileInstance(filename))
return FileInstance(
PyFileInstance(filename),
filename,
)
end

View File

@@ -2,18 +2,21 @@
# Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved.
# Released under the modified BSD license. See COPYING.md for more details.
using Distributed
struct LearningSolver
py::PyCall.PyObject
end
abstract type Instance
optimizer_factory
end
function LearningSolver(optimizer_factory)::LearningSolver
py = miplearn.LearningSolver(solver=JuMPSolver(optimizer_factory))
return LearningSolver(py)
return LearningSolver(
py,
optimizer_factory,
)
end
@@ -31,7 +34,19 @@ function fit!(solver::LearningSolver, instances::Vector{<:Instance})
end
function parallel_solve!(solver::LearningSolver, instances::Vector{FileInstance})
filenames = [instance.filename for instance in instances]
optimizer_factory = solver.optimizer_factory
@sync @distributed for filename in filenames
s = LearningSolver(optimizer_factory)
solve!(s, FileInstance(filename))
nothing
end
end
export Instance,
LearningSolver,
solve!,
fit!
fit!,
parallel_solve!

View File

@@ -62,3 +62,7 @@ macro category(obj, category)
set_category!($(esc(obj)), $(esc(category)))
end
end
export @feature,
@category

View File

@@ -3,7 +3,6 @@
# Released under the modified BSD license. See COPYING.md for more details.
using PyCall
traceback = pyimport("traceback")
macro python_call(expr)