alanderos91 / BioSimulator.jl

A stochastic simulation framework in Julia.
https://alanderos91.github.io/BioSimulator.jl/stable/
Other
47 stars 7 forks source link

Easy way to resume the simulation #23

Closed skycolt closed 5 years ago

skycolt commented 5 years ago

Is there an easy way to restart the simulation from the previous run? or can I set uneven sampling time like [0, 100, 200, 201, 202, 203, ... , 210] ?

Thanks

alanderos91 commented 5 years ago

Not without modifying the Network; e.g. model <= Species("X", 5) will override the previous value. There's not interface for handling uneven sampling times, but this is addressed in a future update.

Providing an easy-to-use simulate is nice, but for my own work I'm finding I need to record quantities in the middle of a simulation. The goal is to have something like this working:

for (x, step) in enumerate(simulator)
  # calculate some quantities
  functionof(x)

  # custom logging
  push!(data, x)

  # break early
  if x[3] == 0; break end
end

where simulator is an object that overloads Base.iterate.

skycolt commented 5 years ago

Thanks for the answer! record in the middle of the simulation is nice. I think it will also be useful to have data for each Gillespie step instead for specific time point. Is there a way to do it?

skycolt commented 5 years ago

I looked through the manual again and I guess I should use the SamplePath method for output if I want to have each point of Gillespie simulation?

alanderos91 commented 5 years ago

Yes, that's correct. It will save each step.

skycolt commented 5 years ago

I tried to used the option Val(:full) but the program only returns two time points. The code I use is result1 = simulate(model1, Direct(), time = 10000.0, output_type = Val(:full), trials = 4) I also tried your example of "enzyme kinetics", with command result = simulate(model, Direct(), time = 50.0, trials = 1000, output_type = Val(:full)) It also only returns two time points, the result looks like

julia> result.simulation_data[1] BioSimulator.RegularPath{Float64,Int64}([0.0, 50.0], [301 5; 100 78; 0 22; 0 274])

Am I doing something wrong? Please let me know.

Thanks

alanderos91 commented 5 years ago

Nothing wrong on your end. For some reason build_output returns a RegularEnsemble (hence RegularPath in your example) instead of an Ensemble.

EDIT: I'm mistaken; output_type is a positional argument. You should run this as

result = simulate(model, Direct(), Val(:full), time = 50.0, trials = 1000)

This needs to be reworked and clarified in the manual.

skycolt commented 5 years ago

Thank you! I didn't notice that to be a positional argument.