ecell / ecell4

An integrated software environment for multi-algorithm, multi-timescale, multi-spatial-representation simulation of various cellular phenomena
https://ecell4.e-cell.org/
GNU General Public License v3.0
17 stars 9 forks source link

Provide Session class for encapsulating a single simulation #41

Closed kaizu closed 4 years ago

kaizu commented 8 years ago

run_simulation provides an easy way to run a single simulation.

run_simulation(10, model=m, y0={'C': 60}, return_type='array')
ensemble_simulations(5, 10, model=m, y0={'C': 60}, return_type='array')

This should be also written like:

Session(10, model=m, y0={'C': 60}, return_type='array').run()
average(Session(10, model=m, y0={'C': 60}, return_type='array').run() for _ in range(5))

And Session object will allow to update the settings.

>>> s = Session(10, model=m, y0={'C': 60}, return_type='array')
>>> s.run()
>>> s.update(y0={'A': 30, 'B': 30, 'C': 30}).run()
kaizu commented 8 years ago

The following might be also useful:

>>> s = Session(10, model=m, y0={'C': 60}, return_type='array')
>>> s.update(t=0, y={'X': 0})
>>> s.update(t=10, y={'X': 100})
>>> s.run()
kaizu commented 8 years ago

A duration for the simulation might be better to be an argument of run function:

>>> s = Session(model=m, y0={'C': 60}, return_type='array')
>>> s.update(t=0, y={'X': 0})
>>> s.update(t=10, y={'X': 100})
>>> s.run(duration=30)
kaizu commented 8 years ago

An idea about "operation list":

[
  {'$set': {'model': m}, '$add': {'value': {'C': 60}}},
  {'$run': {'duration': 10, 'observer': [obs1]}},
  {'$set': {'value': {'X': 100}}},
  {'$run': {'duration': 20, 'observer': [obs1]}}
]

# {'$set': {'model': m}, '$add': {'value.C': 60}}
kaizu commented 8 years ago

Or simply,

run_simulation([
    {'$bind_to': m, '$add_molecules': {'C': 60}},
    {'$run': 10},
    {'$set_value': {'X': 100}},
    {'$run': 10}
  ],
  return_type='array')
kaizu commented 5 years ago
>>> s = Session(model=m)
>>> s.update({'C': 60, 'X': 60})
>>> s.run(10)
>>> s.update({'X': 100})
>>> s.run(30)
>>> print(s.todict())
>>> ret = s.solve('ode')
>>> print(ret.asarray())
>>> ret.plot()

run_simulation could be implemented as follows:

def run_simulation(t, m, y0, solver):
    s = Session(model=m)
    s.update(y0)
    s.run(t[-1])
    obs = NumberObserver(t)  #???
    ret = s.solve(solver, [obs])  #???
    return ret.asarray()
kaizu commented 4 years ago

This has been done partially in the new interface.

session = Session(model=m, y0=y0)
ret = session.run(10.0, solver='gillespie')
print(ret.as_array())
ret.plot()