Skip to content

Commit

Permalink
feat: updates to ode_simulation mod
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPatrie committed May 26, 2024
1 parent c443b95 commit 4296bad
Show file tree
Hide file tree
Showing 3 changed files with 463 additions and 31 deletions.
68 changes: 56 additions & 12 deletions biosimulator_processes/steps/ode_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,89 @@
from process_bigraph.experiments.parameter_scan import RunProcess

from biosimulator_processes import CORE
from biosimulator_processes.utils import calc_num_steps, calc_duration, calc_step_size


class OdeSimulation(Step, abc.ABC):
config_schema = {
'sbml_filepath': 'string',
'n_steps': 'integer',
'step_size': 'float',
'duration': {
'_type': 'string',
'_default': 10}
'time_config': {
'step_size': 'maybe[float]',
'num_steps': 'maybe[float]',
'duration': 'maybe[float]'
}
}

def __init__(self, config=None, core=None):
super().__init__(config, core)

assert len(list(self.config['time_config'].values())) >= 2, "you must pass two of either: step size, n steps, or duration."
self.step_size = self.config.get('step_size')
self.num_steps = self.config.get('num_steps')
self.duration = self.config.get('duration')
self._set_time_params()

def _set_time_params(self):
if self.step_size and self.num_steps:
self.duration = calc_duration(self.num_steps, self.step_size)
elif self.step_size and self.duration:
self.num_steps = calc_num_steps(self.duration, self.step_size)
else:
self.step_size = calc_step_size(self.duration, self.num_steps)

@abc.abstractmethod
def inputs(self):
def _set_simulator(self, sbml_fp: str) -> object:
"""Load simulator instance"""
pass

@abc.abstractmethod
def outputs(self):
def _get_floating_species_ids(self) -> list[str]:
"""Sim specific method"""
pass

def update(self, inputs):
'''@abc.abstractmethod
def _set_floating_species(self):
"""Sim specific method for starting values relative to this property."""
pass
@abc.abstractmethod
def set_species_list(self):
def _set_global_parameters(self):
"""Sim specific method for starting values relative to this property."""
pass
@abc.abstractmethod
def set_global_parameters(self):
pass
def _set_reactions(self):
"""Sim specific method for starting values relative to this property."""
pass'''

def inputs(self):
"""For now, none"""
return {}

def outputs(self):
return {
'time': 'float',
'floating_species': {
spec_id: 'float'
for spec_id in self.floating_species_ids
}
}

@abc.abstractmethod
def set_reactions(self):
def update(self, inputs):
"""Iteratively update over self.floating_species_ids as per the requirements of the simulator library."""
pass











class ODEProcess(RunProcess):
def __init__(self,
address: str,
Expand Down
12 changes: 12 additions & 0 deletions biosimulator_processes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
import nbformat


def calc_num_steps(dur, step_size):
return dur / step_size


def calc_duration(n_steps, step_size):
return n_steps * step_size


def calc_step_size(dur, n_steps):
return dur / n_steps


def register_module(items_to_register: List[Tuple[str, str]], core: ProcessTypes) -> None:
for process_name, path in items_to_register:
module_name, class_name = path.rsplit('.', 1)
Expand Down
Loading

0 comments on commit 4296bad

Please sign in to comment.