Skip to content

Commit

Permalink
Parallelism, compat and CI: release (#127)
Browse files Browse the repository at this point in the history
* CI and other small fixes (#120)

* Update compat and CI (#115)

* Fixes for a demo

* Cleaning unused files. Added Aqua and other CI

* spelling

* New version

* Fix an issue when restarting (#122)

* Update Project.toml

* Compat, CI, and threads (#126)
  • Loading branch information
Azzaare authored Jul 12, 2024
1 parent c74d2e7 commit d558c63
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
run: which julia
continue-on-error: true
- name: Install Julia, but only if it is not already available in the PATH
uses: julia-actions/setup-julia@v1
uses: julia-actions/setup-julia@v2
with:
version: "1"
arch: ${{ runner.arch }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
version:
- "1.8"
- "1" # automatically expands to the latest stable 1.x release of Julia
- nightly
- "pre"
os:
- ubuntu-latest
threads:
Expand All @@ -73,7 +73,7 @@ jobs:
version: 1
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
Expand Down
9 changes: 4 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LocalSearchSolvers"
uuid = "2b10edaa-728d-4283-ac71-07e312d6ccf3"
authors = ["Jean-Francois Baffier"]
version = "0.4.6"
version = "0.4.7"

[deps]
CompositionalNetworks = "4b67e4b5-442d-4ef5-b760-3f5df3a57537"
Expand All @@ -13,7 +13,6 @@ Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Lazy = "50d2b5c4-7a5e-59d5-8109-a42b560f39c0"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"

[compat]
Expand All @@ -26,13 +25,13 @@ Distributed = "1"
JSON = "0.21"
Lazy = "0.15"
OrderedCollections = "1"
TestItemRunner = "0.2"
TestItems = "0.1"
TestItems = "0.1, 1"
julia = "1.6"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"

[targets]
test = ["Aqua", "Test"]
test = ["Aqua", "Test", "TestItemRunner"]
34 changes: 26 additions & 8 deletions src/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@ mutable struct Options
info_path::String
iteration::Union{Int, Float64}
print_level::Symbol
process_threads_map::Dict{Int, Int}
solutions::Int
specialize::Bool
tabu_time::Int
tabu_local::Int
tabu_delta::Float64
threads::Int
time_limit::Float64 # seconds

function Options(;
dynamic = false,
info_path = "",
iteration = 10000,
print_level = :minimal,
process_threads_map = Dict{Int, Int}(1 => typemax(0)),
solutions = 1,
specialize = !dynamic,
tabu_time = 0,
tabu_local = 0,
tabu_delta = 0.0,
threads = typemax(0),
time_limit = 60 # seconds
)
ds_str = "The model types are specialized to the starting domains, constraints," *
Expand All @@ -76,12 +76,12 @@ mutable struct Options
info_path,
iteration,
print_level,
process_threads_map,
solutions,
specialize,
tabu_time,
tabu_local,
tabu_delta,
threads,
time_limit
)
end
Expand Down Expand Up @@ -152,6 +152,24 @@ DOCSTRING
"""
_print_level!(options, level) = options.print_level = level

"""
_process_threads_map(options)
TBW
"""
_process_threads_map(options) = options.process_threads_map

"""
_process_threads_map!(options, ptm)
TBW
"""
_process_threads_map!(options, ptm::AbstractDict) = options.process_threads_map = ptm

function _process_threads_map!(options, ptm::AbstractVector)
return _process_threads_map!(options, Dict(enumerate(ptm)))
end

"""
_solutions(options) = begin
Expand Down Expand Up @@ -227,17 +245,17 @@ _tabu_delta!(options, time) = options.tabu_delta = time
DOCSTRING
"""
_threads(options) = options.threads
_threads(options, p = 1) = get!(options.process_threads_map, p, typemax(0))

"""
_threads!(options, threads) = begin
DOCSTRING
"""
_threads!(options, threads) = options.threads = threads
_threads!(options, threads, p = 1) = push!(options.process_threads_map, p => threads)

"""
_time_limit(options) = begin
_time_limit(options)
DOCSTRING
"""
Expand All @@ -254,6 +272,6 @@ function set_option!(options, name, value)
eval(Symbol("_" * name * "!"))(options, value)
end

function get_option(options, name)
eval(Symbol("_" * name))(options)
function get_option(options, name, args...)
eval(Symbol("_" * name))(options, args...)
end
8 changes: 5 additions & 3 deletions src/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,17 @@ function _init!(s, ::Val{:global})
foreach(i -> put!(s.rc_report, nothing), setdiff(workers(), [1]))
end
function _init!(s, ::Val{:meta})
foreach(id -> push!(s.subs, solver(s, id - 1, :sub)), 2:nthreads())
t = min(get_option(s, "threads"), Threads.nthreads())
foreach(id -> push!(s.subs, solver(s, id - 1, :sub)), 2:t)
return nothing
end

function _init!(s, ::Val{:remote})
for w in setdiff(workers(), [1])
ls = remotecall(solver, w, s, w, :lead)
remote_do(set_option!, w, fetch(ls), "print_level", :silent)
remote_do(
set_option!, w, fetch(ls), "threads", remotecall_fetch(Threads.nthreads, w))
t = min(get_option(s, "threads", w), remotecall_fetch(Threads.nthreads, w))
remote_do(set_option!, w, fetch(ls), "threads", t)
push!(s.remotes, w => ls)
end
end
Expand Down
12 changes: 9 additions & 3 deletions test/raw_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,15 @@ end

for m in models
# @info describe(m)
s = solver(m;
options = Options(print_level = :verbose, time_limit = Inf,
iteration = Inf, info_path = "info.json"))
options = Options(
print_level = :verbose,
time_limit = Inf,
iteration = Inf,
info_path = "info.json",
process_threads_map = Dict{Int, Int}(
[2 => 2, 3 => 1]
))
s = solver(m; options)
for x in keys(get_variables(s))
@test get_name(s, x) == "x$x"
for c in get_cons_from_var(s, x)
Expand Down

0 comments on commit d558c63

Please sign in to comment.