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.
# Released under the modified BSD license. See COPYING.md for more details.
__precompile__(false)
module MIPLearn
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/exceptions.jl")
@ -19,12 +28,19 @@ include("solvers/learning.jl")
include("solvers/macros.jl")
include("utils/benchmark.jl")
DynamicLazyConstraintsComponent = miplearn.DynamicLazyConstraintsComponent
UserCutsComponent = miplearn.UserCutsComponent
ObjectiveValueComponent = miplearn.ObjectiveValueComponent
PrimalSolutionComponent = miplearn.PrimalSolutionComponent
StaticLazyConstraintsComponent = miplearn.StaticLazyConstraintsComponent
MinPrecisionThreshold = miplearn.MinPrecisionThreshold
function __init__()
copy!(miplearn, pyimport("miplearn"))
copy!(traceback, pyimport("traceback"))
copy!(DynamicLazyConstraintsComponent, miplearn.DynamicLazyConstraintsComponent)
copy!(UserCutsComponent, miplearn.UserCutsComponent)
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,
UserCutsComponent,

@ -3,7 +3,8 @@
# 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)
self.filename = filename
self.loaded = nothing
@ -50,9 +51,10 @@
self.loaded.py.samples = self.samples
save(self.filename, self.loaded)
end
end
copy!(PyFileInstance, Class)
end
struct FileInstance <: Instance
py::PyCall.PyObject
filename::AbstractString

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

@ -467,7 +467,8 @@ function get_constraints(
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)
self.data = JuMPSolverData(
optimizer_factory,
@ -605,6 +606,8 @@ end
solve_lp(self; tee=false) =
solve_lp(self.data, tee=tee)
end
copy!(JuMPSolver, Class)
end

Loading…
Cancel
Save