Skip to content

Commit

Permalink
updates to content
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPatrie committed May 26, 2024
1 parent d731f43 commit 8959d69
Show file tree
Hide file tree
Showing 18 changed files with 1,493 additions and 2,350 deletions.
Empty file added __init__.py
Empty file.
2 changes: 1 addition & 1 deletion biosimulator_processes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
('amici', 'amici_process.AmiciProcess')]

STEPS_TO_REGISTER = [
('get_sbml_step', 'get_sbml.GetSbmlStep'),
# ('get_sbml_step', 'get_sbml.GetSbmlStep'),
('plotter', 'viz.CompositionPlotter'),
('plotter2d', 'viz.Plotter2d')]

Expand Down
4 changes: 2 additions & 2 deletions biosimulator_processes/data_model/sed_data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from types import NoneType
import requests
from abc import abstractmethod, ABC

from pydantic import Field, create_model
from biosimulator_processes.data_model import _BaseClass

from biosimulator_processes.data_model import _BaseClass

__all__ = ['SedDataModel']

@dataclass
class SimulationModelParameter(_BaseClass):
Expand Down
23 changes: 23 additions & 0 deletions biosimulator_processes/data_model/verify_data_model.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
from dataclasses import dataclass

from process_bigraph.experiments.parameter_scan import RunProcess

from biosimulator_processes import CORE


@dataclass
class OutputAspectVerification:
aspect_type: str # one of: 'names', 'values'. TODO: Add more
is_verified: bool
expected_data: any
process_data: any


class ODEProcess(RunProcess):
def __init__(self, config=None, core=CORE, **kwargs):
"""ODE-based wrapper of RunProcess from process_bigraph.
kwargs:
'process_address': 'string',
'process_config': 'tree[any]',
'observables': 'list[path]',
'timestep': 'float',
'runtime': 'float'
"""
configuration = config or kwargs
configuration['observables'] = kwargs.get('observables') or self.set_observables()
super().__init__(configuration, core)

def set_observables(self):
return [(k, v) for k, v in self.process.inputs().items()]
59 changes: 59 additions & 0 deletions biosimulator_processes/instance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import matplotlib.pyplot as plt
from process_bigraph.experiments.parameter_scan import RunProcess

from biosimulator_processes import CORE
from biosimulator_processes.steps.ode_simulation import ODEProcess


def get_observables(proc: RunProcess):
observables = []
for port_name, port_dict in proc.process.inputs().items():
if port_name.lower() == 'floating_species_concentrations':
if isinstance(port_dict, dict):
for name, typeVal in port_dict.items():
obs = [port_name, name]
observables.append(obs)
else:
obs = [port_name]
observables.append(obs)
return observables


def generate_ode_instance(process_address: str, model_fp: str, step_size: float, duration: float) -> ODEProcess:
ode_process_config = {'model': {'model_source': model_fp}}
proc = RunProcess(
config={
'process_address': process_address,
'process_config': ode_process_config,
'timestep': step_size,
'runtime': duration},
core=CORE)
obs = get_observables(proc)

return ODEProcess(
address=process_address,
model_fp=model_fp,
observables=obs,
step_size=step_size,
duration=duration)


def plot_ode_output_data(data: dict):
time = data['results']['time']
spec_outputs = []
for name, output in data['results']['floating_species_concentrations'].items():
spec_outputs.append({name: output})

# Plotting the data
plt.figure(figsize=(10, 8))
for output in spec_outputs:
for name, out in output.items():
plt.plot(time, out, label=name)

plt.xlabel('Time')
plt.ylabel('Concentration')
plt.title('Species Concentrations Over Time')
plt.legend()
plt.grid(True)
plt.show()

62 changes: 0 additions & 62 deletions biosimulator_processes/processes/instance.py

This file was deleted.

36 changes: 36 additions & 0 deletions biosimulator_processes/steps/ode_simulation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import abc

from process_bigraph import Step
from process_bigraph.experiments.parameter_scan import RunProcess

from biosimulator_processes import CORE


class OdeSimulation(Step, abc.ABC):
Expand Down Expand Up @@ -37,3 +41,35 @@ def set_global_parameters(self):
@abc.abstractmethod
def set_reactions(self):
pass


class ODEProcess(RunProcess):
def __init__(self,
address: str,
model_fp: str,
observables: list[list[str]],
step_size: float,
duration: float,
config=None,
core=CORE,
**kwargs):
"""
Kwargs:
'process_address': 'string',
'process_config': 'tree[any]',
'observables': 'list[path]',
'timestep': 'float',
'runtime': 'float'
"""
configuration = config or {}
if not config:
configuration['process_address'] = address
configuration['timestep'] = step_size
configuration['runtime'] = duration
configuration['process_config'] = {'model': {'model_source': model_fp}}
configuration['observables'] = observables
super().__init__(config=configuration, core=core)

def run(self, inputs=None):
input_state = inputs or {}
return self.update(input_state)
Loading

0 comments on commit 8959d69

Please sign in to comment.