diff --git a/__init__.py b/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/biosimulator_processes/__init__.py b/biosimulator_processes/__init__.py
index 731a630b0..e23786aee 100644
--- a/biosimulator_processes/__init__.py
+++ b/biosimulator_processes/__init__.py
@@ -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')]
diff --git a/biosimulator_processes/data_model/sed_data_model.py b/biosimulator_processes/data_model/sed_data_model.py
index 5cb2aa1db..f95be096b 100644
--- a/biosimulator_processes/data_model/sed_data_model.py
+++ b/biosimulator_processes/data_model/sed_data_model.py
@@ -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):
diff --git a/biosimulator_processes/data_model/verify_data_model.py b/biosimulator_processes/data_model/verify_data_model.py
index bb12ecc7a..f3842cb96 100644
--- a/biosimulator_processes/data_model/verify_data_model.py
+++ b/biosimulator_processes/data_model/verify_data_model.py
@@ -1,5 +1,9 @@
from dataclasses import dataclass
+from process_bigraph.experiments.parameter_scan import RunProcess
+
+from biosimulator_processes import CORE
+
@dataclass
class OutputAspectVerification:
@@ -7,3 +11,22 @@ class OutputAspectVerification:
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()]
diff --git a/biosimulator_processes/instance.py b/biosimulator_processes/instance.py
new file mode 100644
index 000000000..939d6fe00
--- /dev/null
+++ b/biosimulator_processes/instance.py
@@ -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()
+
diff --git a/biosimulator_processes/processes/instance.py b/biosimulator_processes/processes/instance.py
deleted file mode 100644
index c05d75f15..000000000
--- a/biosimulator_processes/processes/instance.py
+++ /dev/null
@@ -1,62 +0,0 @@
-from dataclasses import dataclass
-from typing import *
-
-from process_bigraph.experiments.parameter_scan import RunProcess
-
-from biosimulator_processes import CORE
-from biosimulator_processes.data_model import _BaseClass
-
-
-class ODEProcess(RunProcess):
- def __init__(self, config=None, core=None):
- super().__init__(config, core)
-
- def run(self, input_state=None):
- return self.update(input_state or {})
-
-
-@dataclass
-class ProcessObservable(_BaseClass):
- path_root: str
- root_children: list[str]
- path: list[str] = None
-
- def __post_init__(self):
- self.path = [self.path_root, *self.root_children]
-
-
-def generate_ode_process_instance(
- entrypoint: Union[str, dict[str, any]], # either sbml model path or sed_model dict which conforms to the spec in sed data model in this repo.
- process_address: str,
- observables: List[List[str]],
- step_size: float,
- duration: float,
- **process_config
-) -> ODEProcess:
- """Generate loaded ode process.
-
- Args:
- entrypoint (Union[str, dict[str, any]]): either sbml model path or sed_model dict which conforms to the spec in sed data model in this repo.
- process_address (str): the address in registry of the process to be loaded as per the CORE registry
- observables (list[str]): observables to be loaded in path form
- step_size (float): the step size in seconds
- duration (float): the duration in seconds
- **process_config (dict): the process config kwargs specific to the simulator process
-
- Returns:
- ODEProcess instance
- """
- if not isinstance(entrypoint, str or dict[str, any]):
- raise ValueError('entrypoint must be a string sbml model path or a dict defining SED_MODEL within biosimulator_processes.data_model.sed_data_model')
-
- config = {'model': {'model_source': entrypoint, **process_config}} if isinstance(entrypoint, str) else entrypoint
- return ODEProcess(
- config={
- 'process_address': f'local:{process_address}',
- 'process_config': config,
- 'observables': observables,
- 'timestep': step_size,
- 'runtime': duration
- },
- core=CORE)
-
diff --git a/biosimulator_processes/steps/ode_simulation.py b/biosimulator_processes/steps/ode_simulation.py
index 59582a98e..d24a6675f 100644
--- a/biosimulator_processes/steps/ode_simulation.py
+++ b/biosimulator_processes/steps/ode_simulation.py
@@ -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):
@@ -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)
diff --git a/composer-notebooks/amici_process_composer.ipynb b/composer-notebooks/amici_process_composer.ipynb
index b3ae9763b..5b6f1ebd3 100644
--- a/composer-notebooks/amici_process_composer.ipynb
+++ b/composer-notebooks/amici_process_composer.ipynb
@@ -11,6 +11,7 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"import sys\n",
"\n",
@@ -27,8 +28,7 @@
"from biosimulator_processes.data_model.compare_data_model import ODEComparisonDocument, DocumentFactory\n",
"from biosimulator_processes import CORE\n",
"from process_bigraph import Composite, pp"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -41,6 +41,7 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"#### Step 1: Define the document to be read by the Composite, which is implemented by the Process.\n",
"biomodel_id = 'BIOMD0000000630'\n",
@@ -57,8 +58,7 @@
" model_filepath=model_fp)\n",
"\n",
"comparison_document.composite"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -71,6 +71,7 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"# Amici Model from compiled module\n",
"sbml_importer = amici.SbmlImporter(model_fp)\n",
@@ -86,8 +87,7 @@
"compiled_model = model_module.getModel()\n",
"# instantiate solver\n",
"method = compiled_model.getSolver()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -100,6 +100,7 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"# From load sbml model module \n",
"sbml_reader = libsbml.SBMLReader()\n",
@@ -108,8 +109,7 @@
"species_objects_list = sbml_model.getListOfSpecies()\n",
"floating_species_list = [s.getId() for s in species_objects_list]\n",
"floating_species_initial = dict(zip(floating_species_list, [s.getInitialConcentration() for s in species_objects_list]))"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -122,11 +122,11 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"for s in species_objects_list:\n",
" print(s.getInitialAmount())"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -139,10 +139,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"[s.getId() for s in species_objects_list]"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -155,10 +155,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"floating_species_initial"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -171,10 +171,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"dict(zip(floating_species_list, [s.getInitialConcentration() for s in species_objects_list]))"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -187,10 +187,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"floating_species_initial"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -203,10 +203,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"species_objects_list = sbml_model.getListOfSpecies()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -219,12 +219,12 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"for i, s in enumerate(species_objects_list):\n",
" print(s.getId())\n",
" print(i, s.getInitialConcentration())"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -237,10 +237,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"dir(model)"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -253,10 +253,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"model.getParameters()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -269,10 +269,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"model.getParameterList()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -285,10 +285,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"model.getParameterIds()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -297,10 +297,10 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"model_parameters_list = model.getP"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -313,10 +313,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"dir(sbml_model)"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -329,10 +329,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"model_parameter_objects = sbml_model.getListOfParameters()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -345,10 +345,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"model_parameter_objects"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -361,13 +361,13 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"for m in model_parameter_objects:\n",
" print(dir(m))\n",
" print(m.getValue())\n",
" print(m.getName())"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -376,12 +376,12 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"model_parameter_objects = sbml_model.getListOfParameters()\n",
"model_parameters_list = [param.getName() for param in model_parameter_objects]\n",
"model_parameters_values = [param.getValue() for param in model_parameter_objects]"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -394,10 +394,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"dir(sbml_model)"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -410,13 +410,13 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"reaction_objects = sbml_model.reactions\n",
"reaction_list = [reaction.getName() for reaction in reaction_objects]\n",
"\n",
"reaction_list"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -429,10 +429,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"dir(reaction_objects[0])"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -445,10 +445,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"reaction_objects[0].getProduct()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -461,10 +461,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"dir(sbml_model)"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -477,6 +477,7 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"from biosimulator_processes.processes.amici_process import AmiciProcess\n",
"\n",
@@ -488,8 +489,7 @@
" sbml_model_fp=model_fp)\n",
"\n",
"amici_process_document"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -502,10 +502,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"amici_process_config = amici_process_document[process_id]['config']"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -518,10 +518,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"amici_process_config"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -534,12 +534,12 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"amici_workflow = Composite(\n",
" config={'state': amici_process_document},\n",
" core=CORE)"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -552,10 +552,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"amici_process: AmiciProcess = amici_workflow.state[process_id]['instance']"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -568,10 +568,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"amici_process.initial_state()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -584,10 +584,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"amici_process.reaction_list"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -600,10 +600,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"amici_process.initial_state()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -616,6 +616,7 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"# Let's compare that against copasi process\n",
"from biosimulator_processes.processes.copasi_process import CopasiProcess\n",
@@ -623,8 +624,7 @@
"\n",
"copasi_process: CopasiProcess = CopasiProcess(\n",
" config=comparison_document.composite['copasi_0']['config'])"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -637,10 +637,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"copasi_process.outputs() == amici_process.outputs()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -653,10 +653,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"amici_process.initial_state() == copasi_process.initial_state()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -669,10 +669,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"copasi_process.reaction_list == amici_process.reaction_list"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -681,8 +681,8 @@
"metadata": {
"collapsed": false
},
- "source": [],
- "outputs": []
+ "outputs": [],
+ "source": []
}
],
"metadata": {
diff --git a/composer-notebooks/copasi_process_composer.ipynb b/composer-notebooks/copasi_process_composer.ipynb
index c0d90b5ab..09c7acc4f 100644
--- a/composer-notebooks/copasi_process_composer.ipynb
+++ b/composer-notebooks/copasi_process_composer.ipynb
@@ -21,12 +21,12 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"import sys \n",
"\n",
"sys.path.insert(0, '..')"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -39,13 +39,13 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"import os \n",
"from process_bigraph import pp, pf \n",
"from biosimulator_processes.data_model import *\n",
"from biosimulator_processes.biosimulator_builder import BiosimulatorBuilder"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -58,10 +58,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"from bigraph_schema.registry import map_type_to_pydantic"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -74,6 +74,7 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"c = {'process_name': 'Rose'}\n",
"\n",
@@ -83,8 +84,7 @@
"tree = StringTree(a=10, b=20, c=30)\n",
"\n",
"tree"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "markdown",
@@ -103,10 +103,10 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"b = BiosimulatorBuilder()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "markdown",
@@ -139,12 +139,12 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"model_filepath = '../biosimulator_processes/model_files/BIOMD0000000061_url.xml'\n",
"\n",
"os.path.exists(model_filepath)"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -153,12 +153,12 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"# Uncomment if you wish to inspect the species referenced below\n",
"# model_from_file = load_model(model_filepath)\n",
"# get_species(model=model_from_file)"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -167,6 +167,7 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"# 1. specify model changes (we know the model specs as we are providing the file. TODO: allow users to introspect the model before change)\n",
"process_model_changes = TimeCourseModelChanges(\n",
@@ -175,8 +176,7 @@
"\n",
"\n",
"pp(process_model_changes.model_dump())"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -185,6 +185,7 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"# 2. define the model schema to be used by the composite process (one of the copasiprocess config parameters)\n",
"\n",
@@ -197,8 +198,7 @@
"\n",
"\n",
"pp(process_model_from_file.model_dump())"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -207,6 +207,7 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"# 3. Define config schema to be used as 'config' parameter of Process constructor\n",
"process_config_from_file = CopasiProcessConfigSchema(\n",
@@ -217,8 +218,7 @@
"\n",
"\n",
"pp(process_config_from_file.model_dump())"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -227,10 +227,10 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"process_config_from_file.process_name, process_config_from_file.method, process_config_from_file.model"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -239,6 +239,7 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"# 4. Add the process instance by the name of 'simple_copasi' to the builder\n",
"\n",
@@ -248,8 +249,7 @@
" model=process_config_from_file.model,\n",
" method=process_config_from_file.method\n",
")"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "markdown",
@@ -268,6 +268,7 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"# Uncomment if you wish to introspect the model referred below\n",
"# from basico import *\n",
@@ -277,8 +278,7 @@
"# biomodel_id = 'BIOMD0000000861'\n",
"# biomodel = load_biomodel(biomodel_id)\n",
"# get_species(model=biomodel)"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -287,12 +287,12 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"# reaction_names = get_reactions(model=biomodel)\n",
"# \n",
"# reaction_names"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -301,6 +301,7 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"rparam = ReactionParameter(\n",
" parameter_name='EpoRpRJAK2',\n",
@@ -321,8 +322,7 @@
" reaction_name='reaction_11',\n",
" reaction_scheme='A + B -> C'\n",
")"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -331,12 +331,12 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"biomodel_process_changes = TimeCourseModelChanges(\n",
" reaction_changes=[rc1, rc2]\n",
")"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -345,10 +345,10 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"pp(biomodel_process_changes.model_dump())"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -357,6 +357,7 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"biomodel_id = 'BIOMD0000000861'\n",
"\n",
@@ -369,8 +370,7 @@
")\n",
"\n",
"pp(biomodel_process_model.model_dump())"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -379,6 +379,7 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"biomodel_process_config = CopasiProcessConfigSchema(\n",
" process_name='copasi_process_from_biomodel',\n",
@@ -388,8 +389,7 @@
"\n",
"\n",
"pp(biomodel_process_config.model_dump())"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "markdown",
@@ -408,14 +408,14 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"b[biomodel_process_config.process_name].add_process(\n",
" name='CopasiProcess',\n",
" model=biomodel_process_config.model,\n",
" method=biomodel_process_config.method\n",
")"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "markdown",
@@ -434,10 +434,10 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"b.visualize()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "markdown",
@@ -456,12 +456,12 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"b.connect_all(append_to_store_name='_store')\n",
"\n",
"b"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -470,10 +470,10 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"b.visualize()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "markdown",
@@ -492,10 +492,10 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"composite = b.generate()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -504,10 +504,10 @@
"metadata": {
"collapsed": false
},
+ "outputs": [],
"source": [
"composite.run(10)"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "markdown",
@@ -530,10 +530,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"b2 = BiosimulatorBuilder()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -546,13 +546,13 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"single_process_model = TimeCourseModel(\n",
" model_source=ModelFilepath(value=model_filepath),\n",
" model_id='BIOMD0000000061'\n",
")"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -565,6 +565,7 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"single_process_config = CopasiProcessConfigSchema(\n",
" process_name='single_copasi_process',\n",
@@ -573,8 +574,7 @@
")\n",
"\n",
"pp(single_process_config.model_dump())"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -587,14 +587,14 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"b2[single_process_config.process_name].add_process(\n",
" name='CopasiProcess',\n",
" model=single_process_config.model,\n",
" method=single_process_config.method\n",
")"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -607,10 +607,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"b2.connect_all(append_to_store_name='_store')"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -623,10 +623,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"b2.visualize()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -639,10 +639,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"pp(b2)"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -655,10 +655,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"composite2 = b2.generate()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -671,12 +671,12 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"# TODO: try different solvers for this: certainly stochastic\n",
"\n",
"composite2.run(10)"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "markdown",
@@ -699,6 +699,7 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"from biosimulator_processes.data_model import EmitterConfig, EmittedType\n",
"\n",
@@ -711,8 +712,7 @@
" ],\n",
" name='emitter'\n",
")"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -725,6 +725,7 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"# b2[emitter_config.name].add_process(\n",
"# name='ram-emitter',\n",
@@ -738,8 +739,7 @@
" 'floating_species': 'tree[float]',\n",
" 'time': 'float'}\n",
")"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -752,10 +752,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"b2.connect_all()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -768,10 +768,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"b2.visualize()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -784,10 +784,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"b2"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -800,10 +800,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"composite3 = b2.generate()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -816,10 +816,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"composite3.run(10)"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "markdown",
@@ -842,10 +842,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"b2.write(filename='single_copasi_process_with_emitter')"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "markdown",
@@ -866,10 +866,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"!ls out"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -882,10 +882,10 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"!cat out/single_copasi_process_with_emitter.json"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -898,6 +898,7 @@
},
"collapsed": false
},
+ "outputs": [],
"source": [
"import json \n",
"\n",
@@ -907,8 +908,7 @@
" \n",
" \n",
"data.keys()"
- ],
- "outputs": []
+ ]
},
{
"cell_type": "code",
@@ -917,8 +917,8 @@
"metadata": {
"collapsed": false
},
- "source": [],
- "outputs": []
+ "outputs": [],
+ "source": []
}
],
"metadata": {
diff --git a/composer-notebooks/tests.ipynb b/composer-notebooks/tests.ipynb
index 80ea35e2f..49bee8fe0 100644
--- a/composer-notebooks/tests.ipynb
+++ b/composer-notebooks/tests.ipynb
@@ -2,14 +2,16 @@
"cells": [
{
"cell_type": "code",
+ "execution_count": 2,
"id": "initial_id",
"metadata": {
- "collapsed": true,
"ExecuteTime": {
"end_time": "2024-05-13T21:02:38.898151Z",
"start_time": "2024-05-13T21:02:38.818296Z"
- }
+ },
+ "collapsed": true
},
+ "outputs": [],
"source": [
"import itertools\n",
"import numpy as np \n",
@@ -29,31 +31,34 @@
"\n",
"data = {}\n",
"data['process_outputs'] = process_outputs"
- ],
- "execution_count": 2,
- "outputs": []
+ ]
},
{
+ "cell_type": "code",
+ "execution_count": 3,
+ "id": "cb687937cff4c0dd",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-13T21:02:38.995881Z",
"start_time": "2024-05-13T21:02:38.987678Z"
}
},
- "cell_type": "code",
- "source": "data",
- "id": "cb687937cff4c0dd",
- "execution_count": 3,
- "outputs": []
+ "outputs": [],
+ "source": [
+ "data"
+ ]
},
{
+ "cell_type": "code",
+ "execution_count": 4,
+ "id": "6c7bb2899830d818",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-13T21:02:39.135699Z",
"start_time": "2024-05-13T21:02:39.133660Z"
}
},
- "cell_type": "code",
+ "outputs": [],
"source": [
"def generate_pairwise_mapping(results: dict, rTol: float, aTol: float):\n",
" \"\"\"\n",
@@ -64,19 +69,19 @@
" \n",
" \"\"\"\n",
" pass"
- ],
- "id": "6c7bb2899830d818",
- "execution_count": 4,
- "outputs": []
+ ]
},
{
+ "cell_type": "code",
+ "execution_count": 5,
+ "id": "7c717eafb0a6d919",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-13T21:02:39.305366Z",
"start_time": "2024-05-13T21:02:39.302816Z"
}
},
- "cell_type": "code",
+ "outputs": [],
"source": [
"somelists = [\n",
" [1, 2, 3],\n",
@@ -85,32 +90,34 @@
"]\n",
"for element in itertools.product(*somelists):\n",
" print(element)"
- ],
- "id": "7c717eafb0a6d919",
- "execution_count": 5,
- "outputs": []
+ ]
},
{
+ "cell_type": "code",
+ "execution_count": 20,
+ "id": "efb17dd215b11b40",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-13T21:19:10.349879Z",
"start_time": "2024-05-13T21:19:10.347102Z"
}
},
- "cell_type": "code",
- "source": "results_data = {'sim_a': np.array([0.20, 0.30]), 'sim_b': np.array([0.43, 0.21]), 'sim_c': np.array([2.3, 0.34])}\n",
- "id": "efb17dd215b11b40",
- "execution_count": 20,
- "outputs": []
+ "outputs": [],
+ "source": [
+ "results_data = {'sim_a': np.array([0.20, 0.30]), 'sim_b': np.array([0.43, 0.21]), 'sim_c': np.array([2.3, 0.34])}\n"
+ ]
},
{
+ "cell_type": "code",
+ "execution_count": 33,
+ "id": "d74c83f75f844104",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-13T21:27:32.448609Z",
"start_time": "2024-05-13T21:27:32.442161Z"
}
},
- "cell_type": "code",
+ "outputs": [],
"source": [
"prods = {}\n",
"\n",
@@ -125,19 +132,19 @@
"param_outputs = pd.DataFrame(outputs, columns=param_names, index=list(results_data.keys()))\n",
"\n",
"param_outputs"
- ],
- "id": "d74c83f75f844104",
- "execution_count": 33,
- "outputs": []
+ ]
},
{
+ "cell_type": "code",
+ "execution_count": 35,
+ "id": "b51cb2ccb94c925e",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-13T21:28:00.354363Z",
"start_time": "2024-05-13T21:28:00.349166Z"
}
},
- "cell_type": "code",
+ "outputs": [],
"source": [
"col_vectors = np.stack(outputs, axis=1)\n",
"\n",
@@ -151,53 +158,53 @@
"feature_vals = pd.DataFrame(col_vectors, columns=feature_names, index=param_names)\n",
"\n",
"feature_vals"
- ],
- "id": "b51cb2ccb94c925e",
- "execution_count": 35,
- "outputs": []
+ ]
},
{
+ "cell_type": "code",
+ "execution_count": 12,
+ "id": "f49a1b5117217d01",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-13T21:10:45.013284Z",
"start_time": "2024-05-13T21:10:45.009944Z"
}
},
- "cell_type": "code",
+ "outputs": [],
"source": [
"names = list(x.keys())\n",
"vals = list(x.values())"
- ],
- "id": "f49a1b5117217d01",
- "execution_count": 12,
- "outputs": []
+ ]
},
{
+ "cell_type": "code",
+ "execution_count": 13,
+ "id": "645b85a1c8592be",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-13T21:10:45.157237Z",
"start_time": "2024-05-13T21:10:45.154505Z"
}
},
- "cell_type": "code",
+ "outputs": [],
"source": [
"names_product = itertools.product(*names)\n",
"\n",
"for el in names_product:\n",
" print(el)"
- ],
- "id": "645b85a1c8592be",
- "execution_count": 13,
- "outputs": []
+ ]
},
{
+ "cell_type": "code",
+ "execution_count": 14,
+ "id": "3c21aba2eac3298",
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-13T21:13:03.164130Z",
"start_time": "2024-05-13T21:13:03.160288Z"
}
},
- "cell_type": "code",
+ "outputs": [],
"source": [
"def generate_binary_combinations(elements):\n",
" \"\"\"\n",
@@ -229,18 +236,15 @@
"print(\"All possible combinations of elements:\")\n",
"for combo in combinations:\n",
" print(combo)"
- ],
- "id": "3c21aba2eac3298",
- "execution_count": 14,
- "outputs": []
+ ]
},
{
- "metadata": {},
"cell_type": "code",
"execution_count": null,
- "source": "",
"id": "1628409e45c78943",
- "outputs": []
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
],
"metadata": {
diff --git a/demos/biolab_api_demo.ipynb b/demos/biolab_api_demo.ipynb
deleted file mode 100644
index 0eee55ab7..000000000
--- a/demos/biolab_api_demo.ipynb
+++ /dev/null
@@ -1,473 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "id": "8087f67dcdaefdee",
- "metadata": {
- "collapsed": false
- },
- "source": [
- "# BioLab API Demo (BioLab container)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "id": "c253d92e47737dd9",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T18:23:49.375459Z",
- "start_time": "2024-05-01T18:23:49.229821Z"
- }
- },
- "source": [
- "# TODO: create sep repo and pypi for data model so that you can install it and import like `import sed_data as sed`"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "id": "initial_id",
- "metadata": {
- "collapsed": true,
- "ExecuteTime": {
- "end_time": "2024-05-01T18:23:49.375680Z",
- "start_time": "2024-05-01T18:23:49.234219Z"
- }
- },
- "source": [
- "import sys\n",
- "import os\n",
- "\n",
- "sys.path.insert(0, '..')"
- ],
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "id": "572ce5fd9c49efcb",
- "metadata": {
- "collapsed": false
- },
- "source": [
- "#### **_Experiment 1_**: Here we cross a boundary in the stack that is a biological simulation. We go from model configuration, to experiment. Thus, this tooling sits at that level: both experiment specification AND experiment execution. It's not just a way to specify an experiment, but it is also a way to run it, given the many knobs and buttons that you can use predefine and customize the way the actual model is being solved. Our users are seeking to be involved in an experiment as a \"stack\". We should make a bigger distinction between terms like \"model\"."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "id": "e3218a2629726818",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T18:23:51.747571Z",
- "start_time": "2024-05-01T18:23:49.237895Z"
- }
- },
- "source": [
- "from process_bigraph import pp\n",
- "from biosimulator_processes.biosimulator_builder import BuildPrompter\n",
- "from biosimulator_processes.data_model.sed_data_model import SedDataModel as sed "
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "id": "871b58285775fb24",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T18:23:52.256123Z",
- "start_time": "2024-05-01T18:23:51.745806Z"
- }
- },
- "source": [
- "# 1a. define a model for the process composition. In this case, just one model to be re-used as configuration for the processes we create:\n",
- "tumor_control_biomodel_id = 'BIOMD0000000749'\n",
- "simple_tc_model = sed.TimeCourseModel(model_source=tumor_control_biomodel_id)\n",
- "\n",
- "pp(simple_tc_model)"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "id": "1519914d8b9a85ce",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T18:23:52.257772Z",
- "start_time": "2024-05-01T18:23:52.254603Z"
- }
- },
- "source": [
- "# 1b. view model info for model source:\n",
- "\n",
- "pp(simple_tc_model.source_info)"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "id": "a30f5e94167513c9",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T18:23:52.266338Z",
- "start_time": "2024-05-01T18:23:52.258070Z"
- }
- },
- "source": [
- "# 1c. define a TimeCourse process instance using the above object as a parameter. The other parameter is method. See BasiCO documentation for more details on solvers\n",
- "\n",
- "simple_tc_process = sed.TimeCourseProcess(model=simple_tc_model, method='lsoda')"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "id": "a9c15126dda87970",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T18:23:52.266655Z",
- "start_time": "2024-05-01T18:23:52.261921Z"
- }
- },
- "source": [
- "# >> The process model instance is viewable as a dataclass...\n",
- "\n",
- "pp(simple_tc_process)"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "id": "ba3d6e8bae50f216",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T18:23:52.268987Z",
- "start_time": "2024-05-01T18:23:52.265517Z"
- }
- },
- "source": [
- "# >> ...or a dict:\n",
- "\n",
- "pp(simple_tc_process.to_dict())"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "id": "f6d099ae829fb063",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T18:23:52.319339Z",
- "start_time": "2024-05-01T18:23:52.269208Z"
- }
- },
- "source": [
- "# 2. instantiate the prompter:\n",
- "\n",
- "prompter = BuildPrompter()"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "id": "6ff0228586348da1",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T18:23:59.152054Z",
- "start_time": "2024-05-01T18:23:52.273445Z"
- }
- },
- "source": [
- "# 3. add process(es) to the bigraph with the Time Course model instance we created above. For now, just one process will be added.\n",
- "\n",
- "prompter.add_single_process(config=simple_tc_process)"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "b833c7217603645c",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T18:23:59.157229Z",
- "start_time": "2024-05-01T18:23:59.153391Z"
- }
- },
- "source": [
- "# 4. Inspect the builder instance within prompter:\n",
- "\n",
- "pp(prompter.builder_instance)"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "8400f44e3a2e8433",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "start_time": "2024-05-01T18:23:59.155333Z"
- }
- },
- "source": [
- "# 5. Visualize the fully-connected composition:\n",
- "\n",
- "prompter.visualize_bigraph()"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "38052757b3b95baa",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "start_time": "2024-05-01T18:23:59.156753Z"
- }
- },
- "source": [
- "# 6. Generate a composite engine and use to execute the bigraph that we just created:\n",
- "\n",
- "prompter.run()"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "45ae5b121110cdce",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "start_time": "2024-05-01T18:23:59.158776Z"
- }
- },
- "source": [
- "# 7. Clear the builder and start from scratch, writing it out first:\n",
- "\n",
- "prompter.flush(fp='simple_single_demo')"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "79fbea4fa6708088",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "start_time": "2024-05-01T18:23:59.160556Z"
- }
- },
- "source": [
- "prompter.builder_instance"
- ],
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "id": "b65a6fab79ad097c",
- "metadata": {
- "collapsed": false
- },
- "source": [
- "#### **_Experiment 2_**: Load an SBML model from a specified model filepath and add Model changes to the composite before adding it to the bigraph. Here, we expect the user to be familiar enough with the model file they are passing to make individual species/parameter/reaction changes for specific species types. In the Caravagna model, for example, the species involved are T, E, I. Let's change the initial concentration for some of these as an example of model changes:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "89739e0302d6b89a",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "start_time": "2024-05-01T18:23:59.162011Z"
- }
- },
- "source": [
- "caravagna_model_filepath = '../biosimulator_processes/model_files/Caravagna2010.xml'\n",
- "print(os.path.exists(caravagna_model_filepath))"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "55e063c857e51f3",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "start_time": "2024-05-01T18:23:59.163295Z"
- }
- },
- "source": [
- "# first make the timecourse model which is easily configured with objects related to model changes\n",
- "adjusted_tc_model_from_file = sed.TimeCourseModel(\n",
- " model_source=caravagna_model_filepath, \n",
- " model_changes=sed.TimeCourseModelChanges(\n",
- " species_changes=sed.SpeciesChange(species_name='T', initial_concentration=0.234)\n",
- " )\n",
- ")\n",
- "\n",
- "\n",
- "pp(adjusted_tc_model_from_file)"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "c1ddec005282e13f",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "start_time": "2024-05-01T18:23:59.164702Z"
- }
- },
- "source": [
- "adjusted_tc_process = sed.TimeCourseProcess(model=adjusted_tc_model_from_file, method='stochastic')\n",
- "\n",
- "pp(adjusted_tc_process)"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "32b4be407a09f96",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "start_time": "2024-05-01T18:23:59.165980Z"
- }
- },
- "source": [
- "# add the process we just created with the prompter. The prompter will create a new instance of builder for us, if not passed:\n",
- "\n",
- "prompter.add_single_process(config=adjusted_tc_process)"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "d0121977a95c320c",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "start_time": "2024-05-01T18:23:59.167039Z"
- }
- },
- "source": [
- "# visualize the adjusted creation\n",
- "\n",
- "prompter.visualize_bigraph()"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "a6e83469c5b8b93d",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "start_time": "2024-05-01T18:23:59.167933Z"
- }
- },
- "source": [
- "# view the builder document\n",
- "\n",
- "prompter.builder_instance.document()"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "121064387d7729b0",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "start_time": "2024-05-01T18:23:59.168771Z"
- }
- },
- "source": [
- "# run the composite\n",
- "\n",
- "prompter.run()"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "6918be74a9a99f7d",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "start_time": "2024-05-01T18:23:59.169791Z"
- }
- },
- "source": [
- "# stochastic works with Caravagna!!"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "f160008fa3538b5",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "start_time": "2024-05-01T18:23:59.170806Z"
- }
- },
- "source": [],
- "outputs": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 2
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython2",
- "version": "2.7.6"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 5
-}
diff --git a/demos/compositions.ipynb b/demos/compositions.ipynb
deleted file mode 100644
index 1161f850c..000000000
--- a/demos/compositions.ipynb
+++ /dev/null
@@ -1,615 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "source": [
- "import sys\n",
- "\n",
- "sys.path.insert(0, '..')\n",
- "\n",
- "import os\n",
- "import requests\n",
- "import json"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T08:45:09.699631Z",
- "start_time": "2024-05-01T08:45:09.646937Z"
- }
- },
- "id": "24fc5d62890368dd",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "source": [
- "from biosimulator_processes.compare import ComparisonDocument\n",
- "from biosimulator_processes import CORE\n",
- "from process_bigraph import pp, Composite"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T08:45:13.511424Z",
- "start_time": "2024-05-01T08:45:10.281028Z"
- }
- },
- "id": "1dc1ba69e5acc44",
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "source": [
- "### Example Composite process using copasi and tellurium"
- ],
- "metadata": {
- "collapsed": false
- },
- "id": "8491845ac8f593cd"
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "source": [
- "simulators = ['copasi', 'tellurium'] # , 'amici']\n",
- "duration = 30\n",
- "n_steps = 200\n",
- "model_filepath = '../biosimulator_processes/model_files/sbml/Caravagna2010.xml'\n",
- "\n",
- "\n",
- "comparison = ComparisonDocument(simulators, duration, n_steps, model_filepath)"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T06:59:32.979028Z",
- "start_time": "2024-05-01T06:59:32.976561Z"
- }
- },
- "id": "d9fce82a600bb9af",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "source": [
- "pp(comparison.composite)"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T06:59:32.985217Z",
- "start_time": "2024-05-01T06:59:32.981251Z"
- }
- },
- "id": "57a94e90c5c2ba41",
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "source": [
- "### ODE Simulator Comparison"
- ],
- "metadata": {
- "collapsed": false
- },
- "id": "659245544fd8d1b3"
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "source": [
- "from biosimulator_processes.compare import ComparisonDocument\n",
- "\n",
- "sbml_model_path = '../biosimulator_processes/model_files/sbml/BIOMD0000000630_url.xml'\n",
- "simulators = ['copasi', 'copasi'] # , 'tellurium']\n",
- "duration = 30 \n",
- "n_steps = 50 \n",
- "target_parameter = {\n",
- " 'name': 'plasmin',\n",
- " 'value': 2.01\n",
- "}\n",
- "\n",
- "\n",
- "def create_comparison_document(\n",
- " sbml_model_path: str, \n",
- " simulators: list[str], \n",
- " duration: int, \n",
- " n_steps: int, \n",
- " target_param: dict = None\n",
- " ) -> ComparisonDocument:\n",
- " return ComparisonDocument(\n",
- " simulators=simulators, \n",
- " duration=duration, \n",
- " num_steps=n_steps,\n",
- " model_filepath=sbml_model_path,\n",
- " target_parameter=target_param)\n",
- "\n",
- "\n",
- "def generate_workflow(document: ComparisonDocument):\n",
- " return Composite(\n",
- " config={'state': document.composite},\n",
- " core=CORE)\n",
- "\n",
- "\n",
- "ode_comparison_document = create_comparison_document(sbml_model_path, simulators, duration, n_steps, target_parameter)"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T06:59:32.991192Z",
- "start_time": "2024-05-01T06:59:32.986334Z"
- }
- },
- "id": "3cc9032bbca74784",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "source": [
- "pp(ode_comparison_document.composite)"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T06:59:33.502935Z",
- "start_time": "2024-05-01T06:59:33.496658Z"
- }
- },
- "id": "5f99df92f1acbf52",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "source": [
- "ode_comparison_workflow = Composite(config={'state': ode_comparison_document.composite}, core=CORE)"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T06:59:34.342968Z",
- "start_time": "2024-05-01T06:59:34.257050Z"
- }
- },
- "id": "9c44bd491ad5ddb0",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "source": [
- "ode_comparison_workflow.run(duration)\n",
- "ode_comparison_results = ode_comparison_workflow.gather_results()"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T06:59:34.956538Z",
- "start_time": "2024-05-01T06:59:34.946595Z"
- }
- },
- "id": "a52b1903520045a0",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "source": [
- "ode_comparison_results"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T06:59:35.546107Z",
- "start_time": "2024-05-01T06:59:35.539397Z"
- }
- },
- "id": "806d60012d71a2eb",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "source": [],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T06:56:28.165350Z",
- "start_time": "2024-05-01T06:56:28.160529Z"
- }
- },
- "id": "da55f1556e28363f",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "source": [],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T06:56:28.166914Z",
- "start_time": "2024-05-01T06:56:28.163347Z"
- }
- },
- "id": "3330d11b7b80252b",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "source": [
- "import tellurium as te\n",
- "\n",
- "simulator = te.loadSBMLModel('../biosimulator_processes/model_files/sbml/BIOMD0000000630_url.xml')\n"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T06:56:28.959849Z",
- "start_time": "2024-05-01T06:56:28.167336Z"
- }
- },
- "id": "5f07a08ac835b2b5",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "source": [
- "dir(simulator)"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T06:56:28.967633Z",
- "start_time": "2024-05-01T06:56:28.963005Z"
- }
- },
- "id": "f4fd7072004772cb",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "source": [
- "simulator.getReactionRates()"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T06:56:28.973429Z",
- "start_time": "2024-05-01T06:56:28.967766Z"
- }
- },
- "id": "e92d5b185840048f",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 13,
- "source": [
- "simulator.getReactionIds()"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T06:56:28.976229Z",
- "start_time": "2024-05-01T06:56:28.971951Z"
- }
- },
- "id": "278ae59c7dedfc33",
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "source": [],
- "metadata": {
- "collapsed": false
- },
- "id": "264bd8c515dda5aa"
- },
- {
- "cell_type": "code",
- "execution_count": 14,
- "source": [
- "simulator.integrator = 'stochastic'"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T06:56:29.393537Z",
- "start_time": "2024-05-01T06:56:28.975565Z"
- }
- },
- "id": "3692858d8548cbee",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "source": [
- "simulator.integrator"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T06:56:29.398884Z",
- "start_time": "2024-05-01T06:56:29.394793Z"
- }
- },
- "id": "f688e9553786d36e",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "source": [
- "simulator.getIds()"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "start_time": "2024-05-01T06:56:29.397421Z"
- }
- },
- "id": "850c62b4ab027800",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "source": [],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T08:34:23.555250Z",
- "start_time": "2024-05-01T08:34:23.547556Z"
- }
- },
- "id": "66b8d04c5b4d6d38",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "source": [
- "import numpy as np \n",
- "type(np.random.rand(3, 4))"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T16:16:16.860293Z",
- "start_time": "2024-05-01T16:16:16.843628Z"
- }
- },
- "id": "665d11516a211ac8",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "source": [
- "import numpy as np\n",
- "from dataclasses import dataclass\n",
- "from random import randint\n",
- "\n",
- "\n",
- "@dataclass\n",
- "class BestOutput:\n",
- " value: float \n",
- " generation: int \n",
- " index: int \n",
- " winning_value: float \n",
- " \n",
- "\n",
- "# Fetch experimental data\n",
- "def get_experimental_data(param_name: str = None) -> float:\n",
- " # TODO: enable this\n",
- " return np.random.rand()\n",
- "\n",
- "# Initialize parameters\n",
- "winning_value = get_experimental_data() # TODO: Fetch this data from experimental online\n",
- "population_size = 100 # Number of simulators being compared\n",
- "mutation_rate = 0.1 # Initial mutation rate\n",
- "range_low = 0 \n",
- "range_high = 20 # TODO: make low and high derived automatically from population size and winning value\n",
- "\n",
- "\n",
- "# Fitness function\n",
- "def calculate_fitness(population):\n",
- " return [abs(individual - winning_value) for individual in population]\n",
- "\n",
- "# Selection function\n",
- "def select_individuals(fitness, num_parents):\n",
- " fitness = np.array(fitness)\n",
- " sorted_indices = np.argsort(fitness)\n",
- " return sorted_indices[:num_parents]\n",
- "\n",
- "# Crossover function\n",
- "def crossover(parents, num_offspring):\n",
- " offspring = []\n",
- " for _ in range(num_offspring):\n",
- " parent1, parent2 = np.random.choice(parents, 2, replace=False)\n",
- " child = (parent1 + parent2) / 2\n",
- " offspring.append(child)\n",
- " return offspring\n",
- "\n",
- "# Mutation function\n",
- "def mutate(offspring, mutation_rate):\n",
- " for i in range(len(offspring)):\n",
- " if np.random.rand() < mutation_rate:\n",
- " offspring[i] += np.random.normal(0, 0.1)\n",
- " return offspring\n",
- "\n",
- "# Feedback function to adjust algorithm parameters based on real-world testing\n",
- "def feedback_adjustment(best_output, current_range):\n",
- " error = abs(best_output - winning_value)\n",
- " new_mutation_rate = max(0.01, mutation_rate - 0.02 * (1 - error / (range_high - range_low)))\n",
- " new_range_low, new_range_high = current_range\n",
- " if error < 1:\n",
- " new_range_low, new_range_high = best_output - 5, best_output + 5\n",
- " return new_mutation_rate, new_range_low, new_range_high\n",
- "\n",
- "# Main genetic algorithm function with dynamic stopping\n",
- "def genetic_algorithm(improvement_threshold=0.000001, max_stagnation=40):\n",
- " global range_low, range_high, mutation_rate\n",
- " population = np.random.uniform(low=range_low, high=range_high, size=population_size)\n",
- " best_output = None\n",
- " best_index = None\n",
- " last_best_fitness = float('inf')\n",
- " stagnation_counter = 0\n",
- "\n",
- " generation = 0\n",
- " while True:\n",
- " fitness = calculate_fitness(population)\n",
- " current_best_fitness = min(fitness)\n",
- " print(f\"Generation {generation}\")\n",
- " print(\"Best fitness:\", current_best_fitness)\n",
- "\n",
- " if current_best_fitness < last_best_fitness:\n",
- " if last_best_fitness - current_best_fitness < improvement_threshold:\n",
- " stagnation_counter += 1\n",
- " else:\n",
- " stagnation_counter = 0\n",
- " last_best_fitness = current_best_fitness\n",
- " else:\n",
- " stagnation_counter += 1\n",
- "\n",
- " if stagnation_counter >= max_stagnation:\n",
- " print(f\"Stopping: No improvement in {max_stagnation} generations.\")\n",
- " break\n",
- "\n",
- " selected_indices = select_individuals(fitness, population_size // 2)\n",
- " selected = [population[i] for i in selected_indices]\n",
- "\n",
- " offspring = crossover(selected, population_size - len(selected))\n",
- " offspring = mutate(offspring, mutation_rate)\n",
- "\n",
- " population = np.array(selected + offspring)\n",
- "\n",
- " best_index = np.argmin(calculate_fitness(population))\n",
- " best_output = population[best_index]\n",
- " mutation_rate, range_low, range_high = feedback_adjustment(best_output, (range_low, range_high))\n",
- "\n",
- " generation += 1\n",
- "\n",
- " return BestOutput(value=best_output, generation=generation, index=best_index, winning_value=winning_value)\n",
- "\n",
- "\n",
- "# Running the enhanced genetic algorithm\n",
- "best_output = genetic_algorithm()\n",
- "print(f\"The winning value: {winning_value}\")\n",
- "print(\"Best output closest to winning value with dynamic stopping:\", best_output)"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-01T17:26:10.121893Z",
- "start_time": "2024-05-01T17:26:10.084506Z"
- }
- },
- "id": "e6938f543d913ac",
- "outputs": []
- },
- {
- "cell_type": "code",
- "source": [
- "def euclidian_distance(p1, p2):\n",
- " from math import sqrt\n",
- " return sqrt(((p1[0] - p2[0]) ** 2) + ((p1[1] - p2[1]) ** 2))\n",
- "\n",
- "\n",
- "dist = euclidian_distance([1.0, 2.0], [4.5, 2.5])"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-13T17:23:20.562213Z",
- "start_time": "2024-05-13T17:23:20.560068Z"
- }
- },
- "id": "21fcf6952f0ba30",
- "execution_count": 7,
- "outputs": []
- },
- {
- "metadata": {
- "ExecuteTime": {
- "end_time": "2024-05-13T17:23:21.115195Z",
- "start_time": "2024-05-13T17:23:21.112726Z"
- }
- },
- "cell_type": "code",
- "source": "dist",
- "id": "9cef32173d70af12",
- "execution_count": 8,
- "outputs": []
- },
- {
- "metadata": {
- "ExecuteTime": {
- "end_time": "2024-05-13T17:23:21.523197Z",
- "start_time": "2024-05-13T17:23:21.519616Z"
- }
- },
- "cell_type": "code",
- "source": "dist",
- "id": "7379fb6fc71f9d9a",
- "execution_count": 9,
- "outputs": []
- },
- {
- "metadata": {
- "ExecuteTime": {
- "end_time": "2024-05-13T17:23:44.149883Z",
- "start_time": "2024-05-13T17:23:44.146658Z"
- }
- },
- "cell_type": "code",
- "source": [
- "from math import sqrt\n",
- "\n",
- "sqrt(14).hex"
- ],
- "id": "44efe05ea87e827",
- "execution_count": 11,
- "outputs": []
- },
- {
- "metadata": {},
- "cell_type": "code",
- "execution_count": null,
- "source": "",
- "id": "a78843b27fac13b",
- "outputs": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 2
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython2",
- "version": "2.7.6"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 5
-}
diff --git a/demos/copasi_process_demo.ipynb b/demos/copasi_process_demo.ipynb
deleted file mode 100644
index 0de779cd1..000000000
--- a/demos/copasi_process_demo.ipynb
+++ /dev/null
@@ -1,709 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "id": "40898635d17c0f08",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-02T17:46:15.246340Z",
- "start_time": "2024-05-02T17:46:15.195226Z"
- }
- },
- "source": [
- "import sys\n",
- "sys.path.insert(0, '..')\n",
- "\n",
- "import os\n",
- "import requests\n",
- "import json"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "id": "initial_id",
- "metadata": {
- "collapsed": true,
- "ExecuteTime": {
- "end_time": "2024-05-02T17:46:18.648654Z",
- "start_time": "2024-05-02T17:46:15.382959Z"
- }
- },
- "source": [
- "from biosimulator_processes.utils import prepare_single_copasi_process_schema\n",
- "from biosimulator_processes import CORE\n",
- "from process_bigraph import Composite, pp"
- ],
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "id": "c7dca241b02a7265",
- "metadata": {},
- "source": [
- "#### Step 1: Define the document to be read by the Composite, which is implemented by the Process."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "id": "2633feac24b596a6",
- "metadata": {
- "ExecuteTime": {
- "end_time": "2024-05-02T17:46:18.651630Z",
- "start_time": "2024-05-02T17:46:18.643502Z"
- }
- },
- "source": [
- "biomodel_id = 'BIOMD0000000630'\n",
- "model_fp = f'../biosimulator_processes/model_files/sbml/{biomodel_id}_url.xml'\n",
- "species_context = 'concentrations'\n",
- "species_port_name = f'floating_species_{species_context}'\n",
- "species_store = [f'floating_species_{species_context}_store']\n",
- "duration = 30\n",
- "\n",
- "document = prepare_single_copasi_process_schema(\n",
- " process_name='copasi_A',\n",
- " sbml_model_fp=model_fp)\n",
- "\n",
- "document"
- ],
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "id": "e502cb54666345af",
- "metadata": {},
- "source": [
- "\n",
- "\n",
- "#### Step 2: Define the instance composition along with the process registry"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "id": "bd91dca0be22cd27",
- "metadata": {
- "ExecuteTime": {
- "end_time": "2024-05-02T17:40:47.750756Z",
- "start_time": "2024-05-02T17:40:47.687910Z"
- }
- },
- "source": [
- "workflow = Composite(\n",
- " config={'state': document},\n",
- " core=CORE\n",
- ")"
- ],
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "id": "857667277d39c647",
- "metadata": {},
- "source": [
- "#### Step 3: Run the workflow for a duration and get the results"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "id": "7c6f72142af0616b",
- "metadata": {
- "ExecuteTime": {
- "end_time": "2024-05-02T17:40:48.035636Z",
- "start_time": "2024-05-02T17:40:47.887576Z"
- }
- },
- "source": [
- "workflow.run(duration)\n",
- "\n",
- "results = workflow.gather_results()"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "id": "c7a254aee3009b8c",
- "metadata": {
- "ExecuteTime": {
- "end_time": "2024-05-02T02:22:57.402016Z",
- "start_time": "2024-05-02T02:22:57.387107Z"
- }
- },
- "source": [
- "pp(results)"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "id": "76259bde7fd711f5",
- "metadata": {
- "ExecuteTime": {
- "end_time": "2024-05-02T02:22:59.583591Z",
- "start_time": "2024-05-02T02:22:59.423936Z"
- }
- },
- "source": [
- "emitter = workflow.state['emitter']['instance']"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 15,
- "id": "7924d2e8b42e432d",
- "metadata": {
- "ExecuteTime": {
- "end_time": "2024-05-02T02:28:40.448604Z",
- "start_time": "2024-05-02T02:28:40.443409Z"
- }
- },
- "source": [
- "workflow.state"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "27ae371af7ff2fa6",
- "metadata": {},
- "source": [
- "\n",
- "\n",
- "x"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "136275c9f8743a57",
- "metadata": {},
- "source": [
- "from biosimulator_processes.steps.viz import parse_composition_results\n",
- "\n",
- "\n",
- "results = parse_composition_results(workflow)\n",
- "\n",
- "pp(results)"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "f6bbb65c9a862f12",
- "metadata": {},
- "source": [
- "y_data = []\n",
- "times = list(results.keys())\n",
- "index = 'floating_species_concentrations'\n",
- "\n",
- "\n",
- " \n",
- "\n",
- "for timestamp, result in results.items():\n",
- " \n",
- " root_data = result[index]\n",
- " names = list(root_data.keys())\n",
- " for name in names:\n",
- " y_data.append(results[timestamp][index][name])\n",
- " print(f'Got data for name {name}: {y_data}')\n",
- " y_data.clear()\n",
- " \n",
- " \n",
- " "
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "150dc15755417a42",
- "metadata": {},
- "source": [
- "workflow.state['global_time']"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "b1614b8359c0651f",
- "metadata": {},
- "source": [
- "from biosimulator_processes.steps.viz import ResultsAnimation, Plotter2d"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "601a2e10c945b363",
- "metadata": {},
- "source": [
- "output = results.copy()"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "538db282c51069d6",
- "metadata": {},
- "source": [
- "output_vals = output[('emitter',)]"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "a44c1cc0f9850758",
- "metadata": {},
- "source": [
- "timescale = list(set([val.get('time', 0.0) for val in output_vals]))"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "5c510ec6dac592eb",
- "metadata": {},
- "source": [
- "timescale"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "f27e97fdebb17b07",
- "metadata": {},
- "source": [
- "data = []\n",
- "counts_data = []"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "c476add07372b47c",
- "metadata": {},
- "source": [
- "for i, val in enumerate(output_vals):\n",
- " species_data = val.get('floating_species_concentrations')\n",
- " data.append(species_data.get('plasminogen'))\n",
- " counts = val.get('floating_species_counts')\n",
- " counts_data.append(counts.get('plasminogen'))"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "f84f85bf43a82b40",
- "metadata": {},
- "source": [
- "len(timescale), len(data)"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "4311ca8a4fce3a7c",
- "metadata": {},
- "source": [
- "Plotter2d.plot_single_output(timescale=timescale, data=data, species_name='plasminogen concentration')"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "a385d75479e50b1c",
- "metadata": {},
- "source": [
- "Plotter2d.plot_single_output(timescale=timescale, data=counts_data, species_name='plasminogen counts', plot_concentration=False)"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "4b07263ce48d2094",
- "metadata": {},
- "source": [
- "Plotter2d.plot_output(x_data=data, y_data=counts_data, title='Plasminogen concentration over counts', x_label='concentration', y_label='counts', species='plasminogen')"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "1e5efa38b0de7505",
- "metadata": {},
- "source": [],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "65cf4a00f212edaa",
- "metadata": {},
- "source": [
- "class_name = 'TelluriumProcess'\n",
- "module_name = 'tellurium_process'\n",
- "module__ = module_name.split('_')\n",
- "for i, v in enumerate(module__):\n",
- " val = v.replace(v[0], v[0].upper())\n",
- " module__.pop(i)\n",
- " module__.insert(i, val)\n",
- "print(module__.join())\n",
- "import_statement = f'biosimulator_processes.processes.{module_name}'\n",
- "\n",
- "module = __import__(\n",
- " import_statement, fromlist=[class_name])"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "2b43d4e3d39be4ff",
- "metadata": {
- "collapsed": false
- },
- "source": [
- "module"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "db19fb9af030507",
- "metadata": {
- "collapsed": false
- },
- "source": [
- "class_name\n"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "9aa632d6ba1240d1",
- "metadata": {
- "collapsed": false
- },
- "source": [
- "x = list(range(10))\n",
- "y = list(range(10))\n",
- "z = [x, y]\n",
- "\n",
- "def func(z):\n",
- " for i, v in enumerate(z):\n",
- " if z[i + 1] != z[i]:\n",
- " return"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "id": "5e19d61cb651a822",
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-02T17:46:29.460012Z",
- "start_time": "2024-05-02T17:46:29.441447Z"
- }
- },
- "source": [
- "from biosimulator_processes.processes.copasi_process import CopasiProcess \n",
- "\n",
- "\n",
- "process_name = 'copasi'\n",
- "module_name = f'{process_name}_process'\n",
- "import_statement = f'biosimulator_processes.processes.{module_name}'\n",
- "module_paths = module_name.split('_')\n",
- "module_id = module_paths[0]\n",
- "module_type = module_paths[1]\n",
- "class_name = module_id.replace(module_id[0], module_id[0].upper())\n",
- "class_name += module_type.replace(module_type[0], module_type[0].upper())\n",
- "module = __import__(\n",
- " import_statement, fromlist=[class_name])\n",
- "# Get the class from the module\n",
- "bigraph_class = getattr(module, class_name)"
- ],
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "source": [
- "document['copasi_A']['config']"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-02T17:46:31.253580Z",
- "start_time": "2024-05-02T17:46:31.241197Z"
- }
- },
- "id": "d560d9964c489785",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "source": [
- "copasi_process: CopasiProcess = bigraph_class(config=document['copasi_A']['config'])\n",
- "\n",
- "process_attributes = vars(copasi_process)"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-02T17:46:32.631847Z",
- "start_time": "2024-05-02T17:46:32.573561Z"
- }
- },
- "id": "c1aff67afe1cd8e8",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "source": [
- "new_initial_state = copasi_process.initial_state().copy()\n",
- "\n",
- "new_initial_state['model_parameters']['degradation constant 1'] = 0.50\n",
- "\n",
- "new_initial_state"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-02T17:46:33.853711Z",
- "start_time": "2024-05-02T17:46:33.843267Z"
- }
- },
- "id": "8b3a24a6e47f6eab",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "source": [],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-02T18:01:29.107236Z",
- "start_time": "2024-05-02T18:01:29.092702Z"
- }
- },
- "id": "6a2e21d03e963604",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 13,
- "source": [
- "\n",
- "\n",
- "\n",
- "def parse_state_params(state) -> list[str]:\n",
- " state_parameters = []\n",
- " _nested_vals = {}\n",
- " \n",
- " def parse_state(state): \n",
- " for param_name, val in state.items():\n",
- " if not isinstance(val, dict):\n",
- " state_parameters.append(param_name)\n",
- " else:\n",
- " _nested_vals[param_name] = val\n",
- " \n",
- " parse_state(state)\n",
- " nested = _nested_vals is not None\n",
- " \n",
- " def parse_nested(state, is_nested):\n",
- " if not _nested_vals:\n",
- " nested = False\n",
- " print('nesting complete')\n",
- " return\n",
- " else:\n",
- " print('is nested')\n",
- " parse_state(state)\n",
- " _nested_vals.clear()\n",
- " \n",
- " while nested:\n",
- " parse_state(_nested_vals)\n",
- " \n",
- " return state_parameters\n",
- "\n",
- "\n",
- "\n",
- " \n",
- " \n",
- " \n",
- "\n",
- " \n",
- " "
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-02T18:09:55.905065Z",
- "start_time": "2024-05-02T18:09:55.895769Z"
- }
- },
- "id": "4206e75e0d01fbb8",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 15,
- "source": [
- "params = parse_state_params(new_initial_state)"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-03T15:03:11.977888Z",
- "start_time": "2024-05-02T18:10:16.601120Z"
- }
- },
- "id": "6258b8ec1891a27d",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "source": [
- "\n",
- "copasi_process.initial_state = new_initial_state"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-02T17:48:28.917017Z",
- "start_time": "2024-05-02T17:48:28.904501Z"
- }
- },
- "id": "75aadcdd3dc1c8db",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "source": [
- "one_step = copasi_process.update(new_initial_state, 100.0)\n",
- "\n",
- "one_step"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-02T17:47:21.105371Z",
- "start_time": "2024-05-02T17:47:21.091725Z"
- }
- },
- "id": "f7c8f328902103c",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "source": [
- "copasi_process.initial_state()"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-02T17:48:44.839724Z",
- "start_time": "2024-05-02T17:48:44.666280Z"
- }
- },
- "id": "d64f8f8de7463a00",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "source": [
- "workflow.state"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-02T17:41:00.790459Z",
- "start_time": "2024-05-02T17:41:00.773632Z"
- }
- },
- "id": "2fd1d1169b59660b",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "source": [
- "workflow"
- ],
- "metadata": {
- "collapsed": false,
- "ExecuteTime": {
- "end_time": "2024-05-02T17:40:58.396766Z",
- "start_time": "2024-05-02T17:40:58.305142Z"
- }
- },
- "id": "c74e508f13eaceeb",
- "outputs": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "source": [],
- "metadata": {
- "collapsed": false
- },
- "id": "50919eb9594a555",
- "outputs": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 2
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython2",
- "version": "2.7.6"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 5
-}
diff --git a/demos/nf1_model.xml b/demos/nf1_model.xml
deleted file mode 100644
index a8eeba8c0..000000000
--- a/demos/nf1_model.xml
+++ /dev/null
@@ -1,88 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/demos/ode_process_demo.ipynb b/demos/ode_process_demo.ipynb
new file mode 100644
index 000000000..47c7617cb
--- /dev/null
+++ b/demos/ode_process_demo.ipynb
@@ -0,0 +1,205 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "id": "initial_id",
+ "metadata": {
+ "collapsed": true,
+ "ExecuteTime": {
+ "end_time": "2024-05-26T18:47:36.234190Z",
+ "start_time": "2024-05-26T18:47:34.708184Z"
+ }
+ },
+ "source": [
+ "import sys\n",
+ "import os \n",
+ "\n",
+ "import numpy as np\n",
+ "from process_bigraph import pp\n",
+ "from process_bigraph.experiments.parameter_scan import RunProcess\n",
+ "\n",
+ "\n",
+ "sys.path.insert(0, '..')\n",
+ "\n",
+ "\n",
+ "from biosimulator_processes import CORE\n",
+ "from biosimulator_processes.services.rest_service import BiosimulationsRestService\n",
+ "from biosimulator_processes.instance import generate_ode_instance"
+ ],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "CobraProcess registered successfully as cobra.\n",
+ "\n",
+ "CopasiProcess registered successfully as copasi.\n",
+ "\n",
+ "TelluriumProcess registered successfully as tellurium.\n",
+ "\n",
+ "AmiciProcess registered successfully as amici.\n",
+ "\n",
+ "Available processes:\n",
+ "[ 'console-emitter',\n",
+ " 'ram-emitter',\n",
+ " 'composite',\n",
+ " 'cobra',\n",
+ " 'copasi',\n",
+ " 'tellurium',\n",
+ " 'amici']\n",
+ "CompositionPlotter registered successfully as plotter.\n",
+ "\n",
+ "Plotter2d registered successfully as plotter2d.\n",
+ "\n",
+ "Available processes:\n",
+ "[ 'console-emitter',\n",
+ " 'ram-emitter',\n",
+ " 'composite',\n",
+ " 'cobra',\n",
+ " 'copasi',\n",
+ " 'tellurium',\n",
+ " 'amici',\n",
+ " 'plotter',\n",
+ " 'plotter2d']\n"
+ ]
+ }
+ ],
+ "execution_count": 1
+ },
+ {
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2024-05-26T18:47:36.237044Z",
+ "start_time": "2024-05-26T18:47:36.235328Z"
+ }
+ },
+ "cell_type": "code",
+ "source": [
+ "model_fp = '../test_suite/examples/sbml-core/Caravagna-J-Theor-Biol-2010-tumor-suppressive-oscillations/Caravagna2010.xml'\n",
+ "ode_process_config = {'model': {'model_source': model_fp}}\n",
+ "step_size = 0.25\n",
+ "duration = 10.0"
+ ],
+ "id": "d4cdc5e03d9ccfa6",
+ "outputs": [],
+ "execution_count": 2
+ },
+ {
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2024-05-26T18:47:36.295379Z",
+ "start_time": "2024-05-26T18:47:36.237603Z"
+ }
+ },
+ "cell_type": "code",
+ "source": "copasi_process = generate_ode_instance(process_address='local:copasi', model_fp=model_fp, step_size=step_size, duration=duration)",
+ "id": "fe2876b09d9d0e1a",
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "found a filepath\n",
+ "found a filepath\n"
+ ]
+ }
+ ],
+ "execution_count": 3
+ },
+ {
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2024-05-26T18:47:36.350706Z",
+ "start_time": "2024-05-26T18:47:36.296031Z"
+ }
+ },
+ "cell_type": "code",
+ "source": "data = copasi_process.run()",
+ "id": "bb0bfcad2ead76f8",
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "/Users/alex/Desktop/uchc_work/biosimulators-2.0/biosimulator-processes/demos/../biosimulator_processes/processes/copasi_process.py:194: FutureWarning:\n",
+ "\n",
+ "Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
+ "\n"
+ ]
+ }
+ ],
+ "execution_count": 4
+ },
+ {
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2024-05-26T18:47:36.354084Z",
+ "start_time": "2024-05-26T18:47:36.352268Z"
+ }
+ },
+ "cell_type": "code",
+ "source": "from biosimulator_processes.instance import plot_ode_output_data",
+ "id": "a7cf4c427f5eeafc",
+ "outputs": [],
+ "execution_count": 5
+ },
+ {
+ "metadata": {
+ "ExecuteTime": {
+ "end_time": "2024-05-26T18:47:36.445755Z",
+ "start_time": "2024-05-26T18:47:36.354856Z"
+ }
+ },
+ "cell_type": "code",
+ "source": "plot_ode_output_data(data)",
+ "id": "187172c397cb1448",
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "