-
-
Save tejasramdas/97044d8bf12f7815417324da9d9d2415 to your computer and use it in GitHub Desktop.
Pluto Catalyst ensemble test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### A Pluto.jl notebook ### | |
# v0.20.4 | |
using Markdown | |
using InteractiveUtils | |
# ╔═╡ af7bcb2c-0757-11f0-10ea-af37b4a77c5e | |
using Pkg | |
# ╔═╡ 36875680-4d09-44fd-9c55-e6f3b47dc2df | |
Pkg.activate(".") | |
# ╔═╡ be3e028a-bb08-4aaf-974b-8b22fd33319e | |
using Catalyst, DifferentialEquations, CairoMakie | |
# ╔═╡ 1a5a9378-3393-4f3c-98a1-6464050dcc23 | |
html""" | |
<style>main {max-width: 100%; overflow:hidden; padding-right: 5%;}</style> | |
<style>pluto-editor main {margin-right: 0;}</style> | |
<style>pluto-output.scroll_y {max-height: 2000px;}</style> | |
""" | |
# ╔═╡ 76892d6d-3530-4073-9518-7a8e00c5a1ac | |
@info "Loaded packages" | |
# ╔═╡ d7155949-de4b-4d11-b6b7-21fc6d377e31 | |
begin | |
simple_switch = @reaction_network begin | |
@species M0(t) M1(t) | |
@parameters t_on t_off l_on | |
@default_noise_scaling 0.1 | |
@discrete_events begin | |
(t==t_on) => [l ~ l_on] | |
(t==t_off) => [l ~ 0.0] | |
end | |
(k_f1,k_b1), M0 <--> M1 | |
l, M0 --> M1 | |
end | |
end | |
# ╔═╡ 94c89abc-9d42-4f98-b7d8-613ef1cd3100 | |
@info "Defined CRN" | |
# ╔═╡ 3d7e5c92-497d-4587-8ccc-57dd8f335160 | |
begin | |
t_on=25.0 | |
t_off=150.0 | |
end | |
# ╔═╡ a93dd3b1-445d-4412-8a37-5ba982082d33 | |
begin | |
u0=[:M0=>100.0,:M1=>0.0] | |
ps=[:k_f1=>0.01,:k_b1=>0.5,:l=>0.0,:t_on=>t_on,:t_off=>t_off,:l_on=>0.1] | |
tspan=(0.0,200.0) | |
u0_int=[:M0=>100,:M1=>0] | |
end | |
# ╔═╡ 65bca955-6949-4448-9e83-cf761c7de6df | |
begin | |
ode=ODEProblem(simple_switch,u0,tspan,ps) | |
sde=SDEProblem(simple_switch,u0,tspan,ps) | |
jinput = JumpInputs(simple_switch,u0_int,tspan,ps) | |
jprob=JumpProblem(jinput) | |
end | |
# ╔═╡ 149c9bcb-4277-46de-94c4-3d2fd96b32e8 | |
begin | |
probs=[ode,sde,jprob] | |
eprobs=[EnsembleProblem(probs[i]) for i in 1:3] | |
end | |
# ╔═╡ 13eb7625-4aec-4807-b968-88cfd34c8b67 | |
@info "Made problems" | |
# ╔═╡ baec605a-2cdd-4582-ad2a-955aa8d870fc | |
begin | |
f1=Figure(size=(1500,500)) | |
ax1=[Axis(f1[1,i]) for i in 1:3] | |
[ax1[i].title=["ODE","SDE","Jump"][i] for i in 1:3] | |
lab1=Label(f1[0,:], "Single simulation plots",tellwidth=false,fontsize=24) | |
end | |
# ╔═╡ bc799ae0-e094-42d2-bc9c-457efd14cf27 | |
md""" | |
### Single simulation works fine | |
""" | |
# ╔═╡ 29a5ab4b-cb03-4e3d-9709-b5a8e9ffdffa | |
for j in 1:3 | |
sol=solve(probs[j];tstops=[t_on,t_off]) | |
lines!(ax1[j],0:1:200,sol.(0:1:200,idxs=2),color=:blue) | |
end | |
# ╔═╡ 1aa9535f-4a10-4de8-bf11-4735f42f3a83 | |
f1 | |
# ╔═╡ 6dde4dc4-3b3a-405c-9217-150b2834e890 | |
save("single_plot.png", f1) | |
# ╔═╡ 9c93c8ae-e101-49ec-92eb-d65993c7d676 | |
md""" | |
### Ensemble simulation introduces random perturbations | |
For example, the ODE simlations should be identical across the ensemble | |
""" | |
# ╔═╡ 711948cb-473e-41b3-89b4-314187113614 | |
begin | |
f2=Figure(size=(1500,500)) | |
ax2=[Axis(f2[1,i]) for i in 1:3] | |
[ax2[i].title=["ODE","SDE","Jump"][i] for i in 1:3] | |
lab2=Label(f2[0,:], "Ensemble simulation plots",tellwidth=false,fontsize=24) | |
end | |
# ╔═╡ 54d34ca1-7eaf-47a6-99c8-220b37bf985b | |
for j in 1:3 | |
if j==3 | |
sol=solve(eprobs[j],SSAStepper();trajectories=100,tstops=[t_on,t_off]) | |
else | |
sol=solve(eprobs[j];trajectories=100,tstops=[t_on,t_off]) | |
end | |
for k in 1:100 | |
lines!(ax2[j],0:1:200,sol[k].(0:1:200,idxs=2),color=:blue,alpha=0.1) | |
end | |
end | |
# ╔═╡ bccff2a4-cad8-4d4e-a6e3-6d009795b85f | |
f2 | |
# ╔═╡ 751ed39b-fefa-4780-bbf3-2b0c72ec90e3 | |
save("ensemble_plot.png", f2) | |
# ╔═╡ Cell order: | |
# ╠═af7bcb2c-0757-11f0-10ea-af37b4a77c5e | |
# ╠═36875680-4d09-44fd-9c55-e6f3b47dc2df | |
# ╠═1a5a9378-3393-4f3c-98a1-6464050dcc23 | |
# ╠═be3e028a-bb08-4aaf-974b-8b22fd33319e | |
# ╠═76892d6d-3530-4073-9518-7a8e00c5a1ac | |
# ╠═d7155949-de4b-4d11-b6b7-21fc6d377e31 | |
# ╠═94c89abc-9d42-4f98-b7d8-613ef1cd3100 | |
# ╠═3d7e5c92-497d-4587-8ccc-57dd8f335160 | |
# ╠═a93dd3b1-445d-4412-8a37-5ba982082d33 | |
# ╠═65bca955-6949-4448-9e83-cf761c7de6df | |
# ╠═149c9bcb-4277-46de-94c4-3d2fd96b32e8 | |
# ╠═13eb7625-4aec-4807-b968-88cfd34c8b67 | |
# ╠═baec605a-2cdd-4582-ad2a-955aa8d870fc | |
# ╠═bc799ae0-e094-42d2-bc9c-457efd14cf27 | |
# ╠═29a5ab4b-cb03-4e3d-9709-b5a8e9ffdffa | |
# ╠═1aa9535f-4a10-4de8-bf11-4735f42f3a83 | |
# ╠═6dde4dc4-3b3a-405c-9217-150b2834e890 | |
# ╠═9c93c8ae-e101-49ec-92eb-d65993c7d676 | |
# ╠═711948cb-473e-41b3-89b4-314187113614 | |
# ╠═54d34ca1-7eaf-47a6-99c8-220b37bf985b | |
# ╠═bccff2a4-cad8-4d4e-a6e3-6d009795b85f | |
# ╠═751ed39b-fefa-4780-bbf3-2b0c72ec90e3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment