Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
COBREXA.jl
Manage
Activity
Members
Plan
External wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LCSB-BioCore
COBREXA.jl
Commits
ce2afdd3
Unverified
Commit
ce2afdd3
authored
3 years ago
by
St. Elmo
Browse files
Options
Downloads
Patches
Plain Diff
added tests for hit and run sampler, broken parallel
parent
f7ee5063
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/analysis/sampling/hit_and_run.jl
+14
-14
14 additions, 14 deletions
src/analysis/sampling/hit_and_run.jl
test/analysis/sampling/hit_and_run.jl
+31
-7
31 additions, 7 deletions
test/analysis/sampling/hit_and_run.jl
test/analysis/sampling/warmup.jl
+5
-5
5 additions, 5 deletions
test/analysis/sampling/warmup.jl
with
50 additions
and
26 deletions
src/analysis/sampling/hit_and_run.jl
+
14
−
14
View file @
ce2afdd3
...
...
@@ -7,7 +7,7 @@
keepevery = _constants.sampling_keep_iters,
samplesize = _constants.sampling_size,
warmup_indices = collect(1:n_reactions(model)),
workers = [myid()],
worker
id
s = [myid()],
nchains = 1,
)
...
...
@@ -60,7 +60,7 @@ chains = hit_and_run(
N = 1000_000,
nchains = 3,
modifications = [change_constraint("
EX_glc__D_e
",-8, -8)]
workers = workers()
worker
id
s = workers()
)
```
"""
...
...
@@ -68,11 +68,11 @@ function hit_and_run(
model
,
optimizer
;
modifications
=
[],
N
=
1000
,
N
=
1
50_
000
,
keepevery
=
_constants
.
sampling_keep_iters
,
samplesize
=
_constants
.
sampling_size
,
warmup_indices
=
collect
(
1
:
n_reactions
(
model
)),
workers
=
[
myid
()],
worker
id
s
=
[
myid
()],
nchains
=
1
,
)
...
...
@@ -81,16 +81,16 @@ function hit_and_run(
model
,
optimizer
;
modifications
=
modifications
,
workers
=
workers
,
# parallel
worker
id
s
=
worker
id
s
,
# parallel
warmup_points
=
warmup_indices
,
)
# load warmup points to workers
save_at
.
(
workers
,
:
cobrexa_ws
,
Ref
(
:
(
$
ws
)))
save_at
.
(
workers
,
:
cobrexa_lbs
,
Ref
(
:
(
$
lbs
)))
save_at
.
(
workers
,
:
cobrexa_ubs
,
Ref
(
:
(
$
ubs
)))
save_at
.
(
worker
id
s
,
:
cobrexa_ws
,
Ref
(
:
(
$
ws
)))
save_at
.
(
worker
id
s
,
:
cobrexa_lbs
,
Ref
(
:
(
$
lbs
)))
save_at
.
(
worker
id
s
,
:
cobrexa_ubs
,
Ref
(
:
(
$
ubs
)))
#
do
in parallel!
#
sample
in parallel!
samples
=
dpmap
(
x
->
:
(
$
COBREXA
.
_serial_hit_and_run
(
cobrexa_ws
,
...
...
@@ -100,14 +100,14 @@ function hit_and_run(
$
keepevery
,
$
N
,
)),
CachingPool
(
workers
),
CachingPool
(
worker
id
s
),
1
:
nchains
,
)
# remove warmup points from workers
map
(
fetch
,
remove_from
.
(
workers
,
:
cobrexa_ws
))
map
(
fetch
,
remove_from
.
(
workers
,
:
cobrexa_lbs
))
map
(
fetch
,
remove_from
.
(
workers
,
:
cobrexa_ubs
))
map
(
fetch
,
remove_from
.
(
worker
id
s
,
:
cobrexa_ws
))
map
(
fetch
,
remove_from
.
(
worker
id
s
,
:
cobrexa_lbs
))
map
(
fetch
,
remove_from
.
(
worker
id
s
,
:
cobrexa_ubs
))
# not sure how to do this better - cat/vcat doesn't work, oh well
vals
=
zeros
(
samplesize
,
length
(
lbs
),
nchains
)
...
...
@@ -159,7 +159,7 @@ function _serial_hit_and_run(ws, lbs, ubs, samplesize, keepevery, N)
end
if
λmax
<=
λmin
||
λmin
==
-
Inf
||
λmax
==
Inf
# this sometimes can happen
# @warn "Infeasible direction at iteration $(n)..." #
noisy
# @warn "Infeasible direction at iteration $(n)..." #
TODO: make this optional/ add to a logger... very noisy otherwise
continue
end
...
...
This diff is collapsed.
Click to expand it.
test/analysis/sampling/hit_and_run.jl
+
31
−
7
View file @
ce2afdd3
...
...
@@ -7,22 +7,46 @@
model
=
load_model
(
StandardModel
,
model_path
)
using
Distributed
nps
=
4
-
nprocs
()
# load extra processes, have at least 4 available
if
1
<=
nps
<=
3
addprocs
(
nps
)
end
@everywhere
using
COBREXA
,
Tulip
# Serial test
chains
=
hit_and_run
(
model
,
Tulip
.
Optimizer
;
N
=
500
0_000
,
N
=
1
0_000
,
nchains
=
3
,
samplesize
=
10
_0
00
,
samplesize
=
1000
,
modifications
=
[
change_constraint
(
"EX_glc__D_e"
,
-
10
,
-
10
),
change_constraint
(
"BIOMASS_Ecoli_core_w_GAM"
,
0.8
,
0.8
),
],
workerids
=
[
myid
()],
)
# # The sampling converges very slowly, so can't really do an accurate test
# with so few samples
# this test is ugly, there must be a better way to get the mean
@test
isapprox
(
mean
(
chains
[[
:
PFL
]])
.
nt
.
mean
[
1
],
0.8
,
atol
=
0.5
)
# Do not test for convergence, that requires too many samples
@test
isapprox
(
mean
(
chains
[[
:
PFL
]])
.
nt
.
mean
[
1
],
0.8
,
atol
=
1.0
)
# parallel tests (still broken, not sure why)
chainsparallel
=
hit_and_run
(
model
,
Tulip
.
Optimizer
;
N
=
10_000
,
nchains
=
3
,
samplesize
=
1000
,
modifications
=
[
change_constraint
(
"EX_glc__D_e"
,
-
10
,
-
10
),
change_constraint
(
"BIOMASS_Ecoli_core_w_GAM"
,
0.8
,
0.8
),
],
workerids
=
workers
(),
)
# TODO: parallel tests (still broken, not sure why
)
@test
isapprox
(
mean
(
chainsparallel
[[
:
PFL
]])
.
nt
.
mean
[
1
],
0.8
,
atol
=
1.0
)
end
This diff is collapsed.
Click to expand it.
test/analysis/sampling/warmup.jl
+
5
−
5
View file @
ce2afdd3
...
...
@@ -32,7 +32,7 @@
@test
ubs
[
ind
]
≈
4
# Parallel test
ws
,
lbs
,
ubs
=
warmup
(
ws
parallel
,
lbsparallel
,
ubsparallel
=
warmup
(
model
,
Tulip
.
Optimizer
;
modifications
=
[
change_constraint
(
"EX_glc__D_e"
,
-
4
,
4
)],
...
...
@@ -41,8 +41,8 @@
)
ind
=
first
(
indexin
([
"EX_glc__D_e"
],
reactions
(
model
)))
@test
size
(
ws
)
==
(
95
,
2
)
@test
size
(
ws
[
1
,
1
])
==
(
95
,)
@test
lbs
[
ind
]
≈
-
4
@test
ubs
[
ind
]
≈
4
@test
size
(
ws
parallel
)
==
(
95
,
2
)
@test
size
(
ws
parallel
[
1
,
1
])
==
(
95
,)
@test
lbs
parallel
[
ind
]
≈
-
4
@test
ubs
parallel
[
ind
]
≈
4
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment