Allow module to be precompiled

master
Alinson S. Xavier 4 years ago
parent 062ccf8b39
commit 529e6289ec

@ -2,12 +2,21 @@
# Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved. # Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved.
# Released under the modified BSD license. See COPYING.md for more details. # Released under the modified BSD license. See COPYING.md for more details.
__precompile__(false)
module MIPLearn module MIPLearn
using PyCall using PyCall
global miplearn = pyimport("miplearn")
global traceback = pyimport("traceback") global DynamicLazyConstraintsComponent = PyNULL()
global JuMPSolver = PyNULL()
global MinPrecisionThreshold = PyNULL()
global miplearn = PyNULL()
global ObjectiveValueComponent = PyNULL()
global PrimalSolutionComponent = PyNULL()
global PyFileInstance = PyNULL()
global PyJuMPInstance = PyNULL()
global StaticLazyConstraintsComponent = PyNULL()
global traceback = PyNULL()
global UserCutsComponent = PyNULL()
include("utils/log.jl") include("utils/log.jl")
include("utils/exceptions.jl") include("utils/exceptions.jl")
@ -19,12 +28,19 @@ include("solvers/learning.jl")
include("solvers/macros.jl") include("solvers/macros.jl")
include("utils/benchmark.jl") include("utils/benchmark.jl")
DynamicLazyConstraintsComponent = miplearn.DynamicLazyConstraintsComponent function __init__()
UserCutsComponent = miplearn.UserCutsComponent copy!(miplearn, pyimport("miplearn"))
ObjectiveValueComponent = miplearn.ObjectiveValueComponent copy!(traceback, pyimport("traceback"))
PrimalSolutionComponent = miplearn.PrimalSolutionComponent copy!(DynamicLazyConstraintsComponent, miplearn.DynamicLazyConstraintsComponent)
StaticLazyConstraintsComponent = miplearn.StaticLazyConstraintsComponent copy!(UserCutsComponent, miplearn.UserCutsComponent)
MinPrecisionThreshold = miplearn.MinPrecisionThreshold copy!(ObjectiveValueComponent, miplearn.ObjectiveValueComponent)
copy!(PrimalSolutionComponent, miplearn.PrimalSolutionComponent)
copy!(StaticLazyConstraintsComponent, miplearn.StaticLazyConstraintsComponent)
copy!(MinPrecisionThreshold, miplearn.MinPrecisionThreshold)
__init_PyFileInstance__()
__init_PyJuMPInstance__()
__init_JuMPSolver__()
end
export DynamicLazyConstraintsComponent, export DynamicLazyConstraintsComponent,
UserCutsComponent, UserCutsComponent,

@ -3,7 +3,8 @@
# Released under the modified BSD license. See COPYING.md for more details. # Released under the modified BSD license. See COPYING.md for more details.
@pydef mutable struct PyFileInstance <: miplearn.Instance function __init_PyFileInstance__()
@pydef mutable struct Class <: miplearn.Instance
function __init__(self, filename) function __init__(self, filename)
self.filename = filename self.filename = filename
self.loaded = nothing self.loaded = nothing
@ -51,7 +52,8 @@
save(self.filename, self.loaded) save(self.filename, self.loaded)
end end
end end
copy!(PyFileInstance, Class)
end
struct FileInstance <: Instance struct FileInstance <: Instance
py::PyCall.PyObject py::PyCall.PyObject

@ -5,8 +5,8 @@
using JuMP using JuMP
using JLD2 using JLD2
function __init_PyJuMPInstance__()
@pydef mutable struct PyJuMPInstance <: miplearn.Instance @pydef mutable struct Class <: miplearn.Instance
function __init__(self, model) function __init__(self, model)
init_miplearn_ext(model) init_miplearn_ext(model)
self.model = model self.model = model
@ -45,6 +45,8 @@ using JLD2
return get(model.ext[:miplearn][:constraint_categories], c, nothing) return get(model.ext[:miplearn][:constraint_categories], c, nothing)
end end
end end
copy!(PyJuMPInstance, Class)
end
struct JuMPInstance <: Instance struct JuMPInstance <: Instance

@ -467,7 +467,8 @@ function get_constraints(
end end
@pydef mutable struct JuMPSolver <: miplearn.solvers.internal.InternalSolver function __init_JuMPSolver__()
@pydef mutable struct Class <: miplearn.solvers.internal.InternalSolver
function __init__(self, optimizer_factory) function __init__(self, optimizer_factory)
self.data = JuMPSolverData( self.data = JuMPSolverData(
optimizer_factory, optimizer_factory,
@ -606,6 +607,8 @@ end
solve_lp(self; tee=false) = solve_lp(self; tee=false) =
solve_lp(self.data, tee=tee) solve_lp(self.data, tee=tee)
end end
copy!(JuMPSolver, Class)
end
export JuMPSolver export JuMPSolver

Loading…
Cancel
Save