mirror of
https://github.com/ANL-CEEESA/MIPLearn.jl.git
synced 2025-12-06 00:18:51 -06:00
Replace sysimage.jl by juliaw; reformat source code
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,3 +10,4 @@ docs/build/
|
||||
docs/site/
|
||||
.ipy*
|
||||
build/
|
||||
**/Manifest.toml
|
||||
|
||||
19
Makefile
19
Makefile
@@ -2,23 +2,12 @@
|
||||
# Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
JULIA := julia --color=yes --project=@.
|
||||
VERSION := 0.2
|
||||
|
||||
build/sysimage.so: src/utils/sysimage.jl Project.toml
|
||||
julia --project=. -e "using Pkg; Pkg.instantiate()"
|
||||
$(JULIA) src/utils/sysimage.jl test/runtests.jl
|
||||
|
||||
clean:
|
||||
rm -rfv build/*
|
||||
|
||||
test: build/sysimage.so
|
||||
$(JULIA) --sysimage build/sysimage.so test/runtests.jl
|
||||
test:
|
||||
./juliaw test/runtests.jl
|
||||
|
||||
format:
|
||||
julia -e 'using JuliaFormatter; format(["src", "test", "benchmark"], verbose=true);'
|
||||
cd deps/formatter; ../../juliaw format.jl
|
||||
|
||||
install-deps:
|
||||
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.14.4"))'
|
||||
|
||||
.PHONY: docs test format install-deps
|
||||
.PHONY: docs test format
|
||||
|
||||
5
deps/formatter/Project.toml
vendored
Normal file
5
deps/formatter/Project.toml
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
[deps]
|
||||
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
|
||||
|
||||
[compat]
|
||||
JuliaFormatter = "0.14.4"
|
||||
8
deps/formatter/format.jl
vendored
Normal file
8
deps/formatter/format.jl
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
using JuliaFormatter
|
||||
format(
|
||||
[
|
||||
"../../src",
|
||||
"../../test",
|
||||
],
|
||||
verbose=true,
|
||||
)
|
||||
68
juliaw
Executable file
68
juliaw
Executable file
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
# 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.
|
||||
|
||||
if [ ! -e Project.toml ]; then
|
||||
echo "juliaw: Project.toml not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -e Manifest.toml ]; then
|
||||
julia --project=. -e 'using Pkg; Pkg.instantiate()' || exit 1
|
||||
fi
|
||||
|
||||
if [ ! -e build/sysimage.so -o Project.toml -nt build/sysimage.so ]; then
|
||||
echo "juliaw: rebuilding system image..."
|
||||
|
||||
# Generate temporary project folder
|
||||
rm -rf $HOME/.juliaw
|
||||
mkdir -p $HOME/.juliaw/src
|
||||
cp Project.toml Manifest.toml $HOME/.juliaw
|
||||
NAME=$(julia -e 'using TOML; toml = TOML.parsefile("Project.toml"); "name" in keys(toml) && print(toml["name"])')
|
||||
if [ ! -z $NAME ]; then
|
||||
cat > $HOME/.juliaw/src/$NAME.jl << EOF
|
||||
module $NAME
|
||||
end
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Add PackageCompiler dependencies to temporary project
|
||||
julia --project=$HOME/.juliaw -e 'using Pkg; Pkg.add(["PackageCompiler", "TOML", "Logging"])'
|
||||
|
||||
# Generate system image scripts
|
||||
cat > $HOME/.juliaw/sysimage.jl << EOF
|
||||
using PackageCompiler
|
||||
using TOML
|
||||
using Logging
|
||||
|
||||
Logging.disable_logging(Logging.Info)
|
||||
mkpath("$PWD/build")
|
||||
|
||||
println("juliaw: generating precompilation statements...")
|
||||
run(\`julia --project="$PWD" --trace-compile="$PWD"/build/precompile.jl \$(ARGS)\`)
|
||||
|
||||
println("juliaw: finding dependencies...")
|
||||
project = TOML.parsefile("Project.toml")
|
||||
manifest = TOML.parsefile("Manifest.toml")
|
||||
deps = Symbol[]
|
||||
for dep in keys(project["deps"])
|
||||
if "path" in keys(manifest[dep][1])
|
||||
println(" - \$(dep) [skip]")
|
||||
else
|
||||
println(" - \$(dep)")
|
||||
push!(deps, Symbol(dep))
|
||||
end
|
||||
end
|
||||
|
||||
println("juliaw: building system image...")
|
||||
create_sysimage(
|
||||
deps,
|
||||
precompile_statements_file = "$PWD/build/precompile.jl",
|
||||
sysimage_path = "$PWD/build/sysimage.so",
|
||||
)
|
||||
EOF
|
||||
julia --project=$HOME/.juliaw $HOME/.juliaw/sysimage.jl $*
|
||||
else
|
||||
julia --project=. --sysimage build/sysimage.so $*
|
||||
fi
|
||||
@@ -15,7 +15,7 @@ mutable struct FileInstance <: Instance
|
||||
function FileInstance(filename::AbstractString, build_model::Function)::FileInstance
|
||||
instance = new(nothing, nothing, filename, nothing, build_model)
|
||||
instance.py = PyFileInstance(instance)
|
||||
instance.h5 = Hdf5Sample("$filename.h5", mode="a")
|
||||
instance.h5 = Hdf5Sample("$filename.h5", mode = "a")
|
||||
instance.filename = filename
|
||||
return instance
|
||||
end
|
||||
|
||||
@@ -569,13 +569,8 @@ function get_constraints(
|
||||
end
|
||||
end
|
||||
|
||||
lhs = sparse(
|
||||
lhs_rows,
|
||||
lhs_cols,
|
||||
lhs_values,
|
||||
length(rhs),
|
||||
JuMP.num_variables(data.model),
|
||||
)
|
||||
lhs =
|
||||
sparse(lhs_rows, lhs_cols, lhs_values, length(rhs), JuMP.num_variables(data.model))
|
||||
if !isempty(data.x)
|
||||
lhs_value = lhs * data.x
|
||||
slacks = abs.(lhs_value - rhs)
|
||||
@@ -652,11 +647,7 @@ function __init_JuMPSolver__()
|
||||
"slacks",
|
||||
]
|
||||
if repr(self.data.optimizer_factory) in ["Gurobi.Optimizer"]
|
||||
append!(attrs, [
|
||||
"basis_status",
|
||||
"sa_rhs_down",
|
||||
"sa_rhs_up",
|
||||
])
|
||||
append!(attrs, ["basis_status", "sa_rhs_down", "sa_rhs_up"])
|
||||
end
|
||||
return attrs
|
||||
end
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
# UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
using PackageCompiler
|
||||
using TOML
|
||||
using Logging
|
||||
|
||||
Logging.disable_logging(Logging.Info)
|
||||
mkpath("build")
|
||||
|
||||
println("Generating precompilation statements...")
|
||||
run(`julia --project=. --trace-compile=build/precompile.jl $(ARGS)`)
|
||||
|
||||
println("Finding dependencies...")
|
||||
project = TOML.parsefile("Project.toml")
|
||||
manifest = TOML.parsefile("Manifest.toml")
|
||||
deps = Symbol[]
|
||||
for dep in keys(project["deps"])
|
||||
if "path" in keys(manifest[dep][1])
|
||||
println(" - $(dep) [skip]")
|
||||
else
|
||||
println(" - $(dep)")
|
||||
push!(deps, Symbol(dep))
|
||||
end
|
||||
end
|
||||
|
||||
println("Building system image...")
|
||||
create_sysimage(
|
||||
deps,
|
||||
precompile_statements_file = "build/precompile.jl",
|
||||
sysimage_path = "build/sysimage.so",
|
||||
)
|
||||
Reference in New Issue
Block a user