Skip to content

Commit 69715d9

Browse files
committed
store only one PBmodel in HybridProblem for n_batch sites
and use create_nsite_applicator to create the ones for n_site. Additionally, adjust docu to use is_testmode=true in calls to calls that eventually invoke the ML model
1 parent 4105d3c commit 69715d9

34 files changed

+206
-74
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "HybridVariationalInference"
22
uuid = "a108c475-a4e2-4021-9a84-cfa7df242f64"
33
authors = ["Thomas Wutzler <[email protected]> and contributors"]
4-
version = "1.0.0-DEV"
4+
version = "0.2"
55

66
[deps]
77
Bijectors = "76274a88-744f-5084-9051-94815aaf08c4"

dev/doubleMM.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@ end
560560
end
561561

562562
#ζi = first(eachrow(Array(chain)))
563-
f_allsites = get_hybridproblem_PBmodel(prob0; scenario, use_all_sites = true)
563+
f = get_hybridproblem_PBmodel(probc; scenario)
564+
f_allsites = create_nsite_applicator(f, n_site)
564565
#ζs = mapreduce(ζi -> transposeMs(ζi, intm_PMs_gen, true), hcat, eachrow(Array(chain)));
565566
ζsP = Array(chain)[:,1:n_θP]'
566567
ζsMst = reshape(Array(chain)[:,(n_θP+1) : end], n_sample_NUTS, n_site, n_θM)

docs/_quarto.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ project:
33
render:
44
- src/tutorials/basic_cpu.qmd
55
- src/tutorials/*.qmd
6+
# julia:
7+
# # workaround for quarto not pciking up the correct environment variable
8+
# # https://github.com/quarto-dev/quarto-cli/issues/13416#issuecomment-3333700286
9+
# env: ["JULIA_DEPOT_PATH=/User/homes/twutz/scratch/twutz/julia_gpu_depots"]
610

711

812

docs/src/tutorials/basic_cpu.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ The example process based model (PBM) predicts a double-monod constrained rate
2727
for different substrate concentrations, `S1`, and `S2`.
2828

2929
$$
30-
y = r_0+ r_1 \frac{S_1}{K_1 + S_1} \frac{S_2}{K_2 + S_2}$$
30+
y = r_0+ r_1 \frac{S_1}{K_1 + S_1} \frac{S_2}{K_2 + S_2}
31+
$$
3132

3233
``` julia
3334
function f_doubleMM(θc::CA.ComponentVector{ET}, x) where ET
@@ -229,10 +230,10 @@ given a vector of global parameters, and a matrix of site parameters to
229230
invocation of the process based model (PBM), defined at the beginning.
230231

231232
``` julia
232-
f_batch = f_allsites = PBMSiteApplicator(f_doubleMM; θP, θM, θFix, xPvec=xP[:,1])
233+
f_batch = PBMSiteApplicator(f_doubleMM; θP, θM, θFix, xPvec=xP[:,1])
233234

234235
prob = HybridProblem(θP, θM, g_chain_scaled, ϕg0,
235-
f_batch, f_allsites, priors_dict, py,
236+
f_batch, priors_dict, py,
236237
transM, transP, train_dataloader, n_covar, n_site, n_batch)
237238
```
238239

@@ -241,6 +242,11 @@ prob = HybridProblem(θP, θM, g_chain_scaled, ϕg0,
241242
Eventually, having assembled all the moving parts of the HVI, we can perform
242243
the inversion.
243244

245+
``` julia
246+
# silence warning of no GPU backend found (because we did not import CUDA here)
247+
ENV["MLDATADEVICES_SILENCE_WARN_NO_GPU"] = 1
248+
```
249+
244250
``` julia
245251
using OptimizationOptimisers
246252
import Zygote
@@ -313,8 +319,7 @@ The HVI Problem needs to be updated with this new applicatior.
313319

314320
``` julia
315321
f_batch = PBMPopulationApplicator(f_doubleMM_sites, n_batch; θP, θM, θFix, xPvec=xP[:,1])
316-
f_allsites = PBMPopulationApplicator(f_doubleMM_sites, n_site; θP, θM, θFix, xPvec=xP[:,1])
317-
probo_sites = HybridProblem(probo; f_batch, f_allsites)
322+
probo_sites = HybridProblem(probo; f_batch)
318323
```
319324

320325
For numerical efficiency, the number of sites within one batch is part of the
@@ -345,8 +350,7 @@ module `Main` to allow for easier reloading with JLD2.
345350

346351
``` julia
347352
f_batch = PBMPopulationApplicator(DoubleMM.f_doubleMM_sites, n_batch; θP, θM, θFix, xPvec=xP[:,1])
348-
f_allsites = PBMPopulationApplicator(DoubleMM.f_doubleMM_sites, n_site; θP, θM, θFix, xPvec=xP[:,1])
349-
probo2 = HybridProblem(probo; f_batch, f_allsites)
353+
probo2 = HybridProblem(probo; f_batch)
350354
```
351355

352356
``` julia

docs/src/tutorials/basic_cpu.qmd

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ The example process based model (PBM) predicts a double-monod constrained rate
3636
for different substrate concentrations, `S1`, and `S2`.
3737

3838
$$
39-
y = r_0+ r_1 \frac{S_1}{K_1 + S_1} \frac{S_2}{K_2 + S_2}$$
39+
y = r_0+ r_1 \frac{S_1}{K_1 + S_1} \frac{S_2}{K_2 + S_2}
40+
$$
4041

4142
```{julia}
4243
function f_doubleMM(θc::CA.ComponentVector{ET}, x) where ET
@@ -239,10 +240,10 @@ given a vector of global parameters, and a matrix of site parameters to
239240
invocation of the process based model (PBM), defined at the beginning.
240241

241242
```{julia}
242-
f_batch = f_allsites = PBMSiteApplicator(f_doubleMM; θP, θM, θFix, xPvec=xP[:,1])
243+
f_batch = PBMSiteApplicator(f_doubleMM; θP, θM, θFix, xPvec=xP[:,1])
243244
244245
prob = HybridProblem(θP, θM, g_chain_scaled, ϕg0,
245-
f_batch, f_allsites, priors_dict, py,
246+
f_batch, priors_dict, py,
246247
transM, transP, train_dataloader, n_covar, n_site, n_batch)
247248
```
248249

@@ -265,7 +266,7 @@ y1 = f_batch(CA.getdata(θP), CA.getdata(θMs), CA.getdata(x_batch))[2]
265266
#using Cthulhu
266267
#@descend_code_warntype f_batch(CA.getdata(θP), CA.getdata(θMs), CA.getdata(x_batch))
267268
prob0 = HVI.DoubleMM.DoubleMMCase()
268-
f_batch0 = get_hybridproblem_PBmodel(prob0; use_all_sites = false)
269+
f_batch0 = get_hybridproblem_PBmodel(prob0)
269270
y1f = f_batch0(θP, θMs, x_batch)[2]
270271
y1 .- y1f # equal
271272
end
@@ -276,6 +277,11 @@ end
276277
Eventually, having assembled all the moving parts of the HVI, we can perform
277278
the inversion.
278279

280+
```{julia}
281+
# silence warning of no GPU backend found (because we did not import CUDA here)
282+
ENV["MLDATADEVICES_SILENCE_WARN_NO_GPU"] = 1
283+
```
284+
279285
```{julia}
280286
using OptimizationOptimisers
281287
import Zygote
@@ -349,8 +355,7 @@ The HVI Problem needs to be updated with this new applicatior.
349355

350356
```{julia}
351357
f_batch = PBMPopulationApplicator(f_doubleMM_sites, n_batch; θP, θM, θFix, xPvec=xP[:,1])
352-
f_allsites = PBMPopulationApplicator(f_doubleMM_sites, n_site; θP, θM, θFix, xPvec=xP[:,1])
353-
probo_sites = HybridProblem(probo; f_batch, f_allsites)
358+
probo_sites = HybridProblem(probo; f_batch)
354359
```
355360

356361
For numerical efficiency, the number of sites within one batch is part of the
@@ -380,8 +385,7 @@ module `Main` to allow for easier reloading with JLD2.
380385

381386
```{julia}
382387
f_batch = PBMPopulationApplicator(DoubleMM.f_doubleMM_sites, n_batch; θP, θM, θFix, xPvec=xP[:,1])
383-
f_allsites = PBMPopulationApplicator(DoubleMM.f_doubleMM_sites, n_site; θP, θM, θFix, xPvec=xP[:,1])
384-
probo2 = HybridProblem(probo; f_batch, f_allsites)
388+
probo2 = HybridProblem(probo; f_batch)
385389
```
386390

387391
```{julia}
@@ -397,4 +401,4 @@ end
397401
#| eval: false
398402
#| echo: false
399403
probo = load(fname, "probo"; iotype = IOStream);
400-
```
404+
```
-8.38 KB
Loading
751 Bytes
Loading
1.33 KB
Loading
16.2 KB
Loading
8.84 KB
Loading

0 commit comments

Comments
 (0)