BioSimulator.jl icon indicating copy to clipboard operation
BioSimulator.jl copied to clipboard

Cannot turn ensemble simulation results into data-frame

Open oliviaAB opened this issue 1 month ago • 2 comments

Hi,

I have installed the latest version of BioSimulator from GitHub, and I am running several simulations of a network as an ensemble, as shown in the tutorial. However, the result is not exactly an array of SimplePaths as expected, and I cannot convert it as a data-frame. I have saved the network that I used to reproduce the example, I cannot attach it directly to this issue but happy to share it via email; here is the code:

using BioSimulator
using Serialization
using DataFrames

model = deserialize("biosimulator_test_model.dat")
simalgorithm = BioSimulator.Direct()
sim = [simulate(model, simalgorithm, tfinal = 100.0, save_points = 0:1.0:100.0) for _ in 1:5]
# 5-element Vector{RecursiveArrayTools.DiffEqArray{Int64, 1, Vector{Vector{Int64}}, Vector{Float64}, Nothing, Nothing, Nothing}}:
# ...
DataFrame(sim)
5×5 DataFrame
 Row │ u                                  t                                  p        sys      discretes
     │ Array…                             Array…                             Nothing  Nothing  Nothing
─────┼───────────────────────────────────────────────────────────────────────────────────────────────────
   1 │ [[1, 0, 0, 1, 0, 0, 1, 0, 0, 1  …  [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6…
   2 │ [[1, 0, 0, 1, 0, 0, 1, 0, 0, 1  …  [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6…
   3 │ [[1, 0, 0, 1, 0, 0, 1, 0, 0, 1  …  [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6…
   4 │ [[1, 0, 0, 1, 0, 0, 1, 0, 0, 1  …  [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6…
   5 │ [[1, 0, 0, 1, 0, 0, 1, 0, 0, 1  …  [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6…

And tablefy doesn't work on the full Ensemble, it only works for a single path:

import BioSimulator: tablefy
DataFrame(tablefy(sim))
ERROR: MethodError: no method matching tablefy(::Vector{RecursiveArrayTools.DiffEqArray{Int64, 1, Vector{…}, Vector{…}, Nothing, Nothing, Nothing}})
The function `tablefy` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  tablefy(::Array{RecursiveArrayTools.DiffEqArray{T, N, A, B}, 1} where {T, N, A, B})
   @ BioSimulator C:\Users\HRPOAB\.julia\packages\BioSimulator\TJryJ\src\output\tabletraits.jl:162
  tablefy(::RecursiveArrayTools.DiffEqArray)
   @ BioSimulator C:\Users\HRPOAB\.julia\packages\BioSimulator\TJryJ\src\output\tabletraits.jl:73

Stacktrace:
 [1] top-level scope
   @ REPL[11]:1
Some type information was truncated. Use `show(err)` to see complete types.
import BioSimulator: tablefy
DataFrame(tablefy(sim[1]))
101×95 DataFrame
 Row │ t        X1     X2     X3     X4     X5     X6     X7     X8     X9     X10    X11    X12    X13    X14    X15  ⋯
     │ Float64  Int64  Int64  Int64  Int64  Int64  Int64  Int64  Int64  Int64  Int64  Int64  Int64  Int64  Int64  Int6 ⋯
─────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1 │     0.0      1      0      0      1      0      0      1      0      0      1      0      0      1      0       ⋯
   2 │     1.0      1      0      0      1      0      0      1      0      0      1      0      0      1      0
   3 │     2.0      1      0      0      1      0      0      1      0      0      1      0      0      1      0
   4 │     3.0      1      0      0      1      0      0      1      0      0      1      0      0      1      0
   5 │     4.0      1      0      0      1      0      0      1      0      0      1      0      0      1      0       ⋯
   6 │     5.0      1      0      0      1      0      0      1      0      0      1      0      0      1      0
   7 │     6.0      1      0      0      1      0      0      1      0      0      1      0      0      1      0
   8 │     7.0      1      0      0      1      0      0      1      0      0      1      0      0      1      0
   9 │     8.0      1      0      0      1      0      0      1      0      0      1      0      0      1      0       ⋯
  10 │     9.0      1      0      0      1      0      0      1      0      0      1      0      0      1      0
  11 │    10.0      1      0      0      1      0      0      1      0      0      1      0      0      1      0
  ⋮  │    ⋮       ⋮      ⋮      ⋮      ⋮      ⋮      ⋮      ⋮      ⋮      ⋮      ⋮      ⋮      ⋮      ⋮      ⋮      ⋮  ⋱
  92 │    91.0      1      0      0      1      0      0      1      0      0      0      1      0      1      0
  93 │    92.0      1      0      0      1      0      0      1      0      0      0      1      0      1      0       ⋯
  94 │    93.0      1      0      0      1      0      0      1      0      0      0      1      0      1      0
  95 │    94.0      1      0      0      1      0      0      1      0      0      0      1      0      1      0
  96 │    95.0      1      0      0      1      0      0      1      0      0      0      1      0      1      0
  97 │    96.0      1      0      0      1      0      0      1      0      0      0      1      0      1      0       ⋯
  98 │    97.0      1      0      0      1      0      0      1      0      0      0      1      0      1      0
  99 │    98.0      1      0      0      1      0      0      1      0      0      0      1      0      1      0
 100 │    99.0      1      0      0      1      0      0      1      0      0      0      1      0      1      0
 101 │   100.0      1      0      0      1      0      0      1      0      0      0      1      0      1      0       ⋯
                                                                                          80 columns and 80 rows omitted

I know that turning an Ensemble into a data-frame used to work with an older version of the package, but I haven't used it (or Julia) in a while, so I am not sure whether I am missing some dependencies or if it's an issue that others can reproduce.

Thank you for your help!

oliviaAB avatar Jan 19 '25 10:01 oliviaAB