Skip to content

Commit

Permalink
v0.1.4: Multithreading (#26)
Browse files Browse the repository at this point in the history
* doc up

* Added multihreading in optimize! (#25)

* Added multihreading in optimize!

* Updated CI for multithreading

* Bump new version for multithreading
  • Loading branch information
Azzaare authored Jan 24, 2021
1 parent 820d3af commit d673175
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
arch:
- x64
- x86
threads:
- "2"
exclude:
- os: macOS-latest
arch: x86
Expand All @@ -41,6 +43,8 @@ jobs:
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
env:
JULIA_NUM_THREADS: ${{ matrix.threads }}
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CompositionalNetworks"
uuid = "4b67e4b5-442d-4ef5-b760-3f5df3a57537"
authors = ["Jean-François Baffier"]
version = "0.1.3"
version = "0.1.4"

[deps]
ConstraintDomains = "5800fd60-8556-4464-8d61-84ebf7a0bedb"
Expand All @@ -11,7 +11,7 @@ OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[compat]
ConstraintDomains = "0.1.2"
ConstraintDomains = "0.1"
Dictionaries = "0.3"
Evolutionary = "0.7, 0.8"
OrderedCollections = "1.3"
Expand Down
3 changes: 2 additions & 1 deletion src/CompositionalNetworks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import Evolutionary: GA, tournament, singlepoint, flip, optimize, minimizer, Opt
import Random: bitrand, falses
import OrderedCollections: LittleDict
import Dictionaries: Dictionary, set!
import Base.Iterators: product
import Base.Iterators: product, flatten
import ConstraintDomains: _get_domain, _length
import Base.Threads: @threads, threadid, nthreads

# Exports utilities
export lazy, lazy_param, csv2space
Expand Down
11 changes: 7 additions & 4 deletions src/genetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,17 @@ Optimize and set the weigths of an ICN with a given set of configuration `X` and

function optimize!(icn, X, X_sols, global_iter, local_iter, dom_size, param=nothing; metric=hamming, popSize=100)
results = Dictionary{BitVector,Int}()
@info "Starting optimization of weights"
for i in 1:global_iter
aux_results = Vector{BitVector}(undef, global_iter)
@info """Starting optimization of weights$(nthreads() > 1 ? " (multithreaded)" : "")"""
@threads for i in 1:global_iter
@info "Iteration $i"
_optimize!(icn, X, X_sols, dom_size, param;
aux_icn = deepcopy(icn)
_optimize!(aux_icn, X, X_sols, dom_size, param;
iter=local_iter, metric=metric, pop_size=popSize
)
_incsert!(results, _weigths(icn))
aux_results[i] = _weigths(aux_icn)
end
foreach(bv -> _incsert!(results, bv), aux_results)
best = rand(findall(x -> x == maximum(results), results))
_weigths!(icn, best)
@info show_composition(icn) best results
Expand Down

0 comments on commit d673175

Please sign in to comment.