Last active
February 28, 2021 00:11
-
-
Save anandijain/157bc199a87aca6665c235e61e705a72 to your computer and use it in GitHub Desktop.
testing which models from the suite work with SbmlInterface.jl
This file contains 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
using SbmlInterface, ModelingToolkit, OrdinaryDiffEq, SciMLBase, DataFrames, DifferentialEquations | |
using Plots | |
# assumes this is cloned: https://github.com/sbmlteam/sbml-test-suite | |
path = joinpath(homedir(), "sbml-test-suite/cases/") | |
@test isdir(path) | |
function extract_xmls() | |
dirs = filter(isdir, readdir(path; join=true)) | |
all_dirs = mapreduce(x -> filter(isdir, readdir(x; join=true)), vcat, dirs) | |
all_files = vcat(readdir.(all_dirs; join=true)...) | |
filter!(x -> occursin(".xml", x), all_files) | |
end | |
# theres probably an idiomatic way to do this | |
function call_save_err(f, x) | |
n = length(x) | |
arr = Vector(undef, n) | |
for i in 1:n | |
try | |
arr[i] = f(x[i]) | |
catch e | |
arr[i] = e | |
end | |
end | |
arr | |
end | |
all_files = extract_xmls() | |
n = length(all_files) | |
num = 100 | |
n = num | |
all_files = all_files[1:num] | |
@test all_files isa Vector{String} | |
@time models = getmodel.(all_files); # 8.972979 seconds (779.59 k allocations: 35.538 MiB, 0.57% gc time, 0.73% compilation time) | |
@time ps = getparameters.(models); # 15.963854 seconds (6.03 M allocations: 346.563 MiB, 0.86% gc time, 0.02% compilation time) | |
@time u0s = call_save_err(getinitialconditions, models); # 16.213772 seconds (7.04 M allocations: 408.899 MiB, 0.99% gc time, 0.51% compilation time) | |
@time eqs = call_save_err(getodes, models); # 52.578963 seconds (24.88 M allocations: 1.315 GiB, 1.52% gc time, 0.87% compilation time) | |
@time systems = call_save_err(sbml2odesystem, all_files); # 97.208173 seconds (44.64 M allocations: 2.364 GiB, 1.50% gc time, 0.57% compilation time) | |
@time probs = call_save_err(x->sbml2odeproblem(x, (0., 1.)), all_files); # longer than im willing to wait | |
@time probs = call_save_err(x->sbml2odeproblem(x, (0., 1.)), all_files[1:100]); # longer than im willing to wait | |
@time probs = call_save_err(x->ODEProblem(x...), syss[1:100]); # don't do this | |
df = DataFrame(:id => all_files, :model => models, :p => ps, :u0 => u0s, :eqs => eqs, :sys => systems) # :prob => probs) | |
N, M = size(df) | |
cols = DataFrames.names(df) | |
errored_mask = @. typeof(df[:, :sys]) <: Exception | |
errs = df[errored_mask, :] | |
good = df[Not(errored_mask), :] | |
syss = good.sys | |
# 17.815165 seconds (32.99 M allocations: 2.097 GiB, 3.34% gc time, 0.12% compilation time) | |
good_probs = probs[Not(@. typeof(probs) <: Exception)] | |
@time sols = call_save_err(solve, good_probs); # long, wanna try SciMLBase.tmap | |
@. display(plot(sols)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment