From f6a031b1a3be5c5a6aa1951eeebdecf64bdab8a4 Mon Sep 17 00:00:00 2001 From: alexPatrie Date: Fri, 1 Mar 2024 08:29:21 -0500 Subject: [PATCH] added granular species pydantic types --- biosimulator_processes/process_types.py | 42 +- .../processes/copasi_process.py | 4 +- notebooks/builder_composer.ipynb | 1492 +++++++++++++++- notebooks/demo.ipynb | 1537 ----------------- 4 files changed, 1510 insertions(+), 1565 deletions(-) delete mode 100644 notebooks/demo.ipynb diff --git a/biosimulator_processes/process_types.py b/biosimulator_processes/process_types.py index c56bb17c7..a605357d9 100644 --- a/biosimulator_processes/process_types.py +++ b/biosimulator_processes/process_types.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod -class ModelChange(BaseModel): +'''class ModelChange(BaseModel): config: Union[Dict[str, Dict[str, Dict[str, Union[float, str]]]], Dict[str, Dict[str, Union[Dict[str, float], str]]]] @@ -51,7 +51,7 @@ class SedModel(BaseModel): model_source: str model_language: str = 'sbml' model_name: str = 'composite_process_model' - model_changes: ModelChanges + model_changes: ModelChanges''' changes = { @@ -72,10 +72,44 @@ class SedModel(BaseModel): } } + +class SpeciesChanges(BaseModel): # <-- this is done like set_species('B', kwarg=) where the inner most keys are the kwargs + species_name: str + unit: str + initial_concentration: float + initial_particle_number: float + initial_expression: str + expression: str + + +class GlobalParameterChanges(BaseModel): # <-- this is done with set_parameters(PARAM, kwarg=). where the inner most keys are the kwargs + parameter_name: str + initial_value: float + initial_expression: str + expression: str + status: str + param_type: str # ie: fixed, assignment, reactions, etc + + +class ReactionParameter(BaseModel): + name: str + value: Union[float, int, str] + + +class ReactionChanges(BaseModel): + reaction_name: str + reaction_parameters: Dict[str, ReactionParameter] + reaction_scheme: str + + +# class ModelChanges: + + + CHANGES_SCHEMA = """The following types have been derived from both SEDML L1v4 and basico itself. BASICO_MODEL_CHANGES_TYPE = { - 'species_changes': { # <-- this is done like set_species('B', kwarg=) where the inner most keys are the kwargs + 'species_changes': { 'species_name': { 'unit': 'maybe[string]', 'initial_concentration': 'maybe[float]', @@ -84,7 +118,7 @@ class SedModel(BaseModel): 'expression': 'maybe[string]' } }, - 'global_parameter_changes': { # <-- this is done with set_parameters(PARAM, kwarg=). where the inner most keys are the kwargs + 'global_parameter_changes': { 'global_parameter_name': { 'initial_value': 'maybe[float]', 'initial_expression': 'maybe[string]', diff --git a/biosimulator_processes/processes/copasi_process.py b/biosimulator_processes/processes/copasi_process.py index b0ac7b7f4..1f2bd1b12 100644 --- a/biosimulator_processes/processes/copasi_process.py +++ b/biosimulator_processes/processes/copasi_process.py @@ -328,5 +328,5 @@ def test_process(): assert ('emitter',) in results.keys(), "This instance was not properly configured with an emitter." -if __name__ == "__main__": - test_process() +# if __name__ == "__main__": +# test_process() diff --git a/notebooks/builder_composer.ipynb b/notebooks/builder_composer.ipynb index d68219d2a..d8f2af791 100644 --- a/notebooks/builder_composer.ipynb +++ b/notebooks/builder_composer.ipynb @@ -1,29 +1,390 @@ { "cells": [ + { + "cell_type": "markdown", + "id": "808b6a4b-0894-4a8e-99d8-bf11b3164b6a", + "metadata": {}, + "source": [ + "# Bigraph-Builder Demo" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "b385dca6-942d-472c-9963-13b8cb33843c", + "metadata": { + "ExecuteTime": { + "end_time": "2024-02-29T22:16:03.547147Z", + "start_time": "2024-02-29T22:16:02.510078Z" + } + }, + "outputs": [], + "source": [ + "from builder import Builder, Process, ProcessTypes" + ] + }, + { + "cell_type": "markdown", + "id": "a403d619-4dbe-49cc-8f24-29a83e31fe15", + "metadata": {}, + "source": [ + "## Initialize the builder" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "23ae6471dca4692b", + "metadata": { + "ExecuteTime": { + "end_time": "2024-02-29T22:16:36.372695Z", + "start_time": "2024-02-29T22:16:30.599813Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CobraProcess registered successfully.\n" + ] + }, + { + "ename": "TypeError", + "evalue": "Too many parameters for typing.Dict; actual 3, expected 2", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[2], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mbiosimulator_processes\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m CORE\n", + "File \u001b[0;32m~/Desktop/uchc_work/biosimulator-processes/biosimulator_processes/__init__.py:18\u001b[0m\n\u001b[1;32m 15\u001b[0m module_name, class_name \u001b[38;5;241m=\u001b[39m process_path\u001b[38;5;241m.\u001b[39mrsplit(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;241m1\u001b[39m)\n\u001b[1;32m 16\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 17\u001b[0m \u001b[38;5;66;03m# Dynamically import the module\u001b[39;00m\n\u001b[0;32m---> 18\u001b[0m process_module \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43m__import__\u001b[39;49m\u001b[43m(\u001b[49m\n\u001b[1;32m 19\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43mf\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mbiosimulator_processes.processes.\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mmodule_name\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfromlist\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\u001b[43mclass_name\u001b[49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 20\u001b[0m \u001b[38;5;66;03m# Get the class from the module\u001b[39;00m\n\u001b[1;32m 21\u001b[0m process_class \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mgetattr\u001b[39m(process_module, class_name)\n", + "File \u001b[0;32m~/Desktop/uchc_work/biosimulator-processes/biosimulator_processes/processes/copasi_process.py:36\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mprocess_bigraph\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Process, Composite, pf\n\u001b[1;32m 35\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mbiosimulator_processes\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mutils\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m fetch_biomodel\n\u001b[0;32m---> 36\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mbiosimulator_processes\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mprocess_types\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m MODEL_TYPE\n\u001b[1;32m 37\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mbiosimulator_processes\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mprocesses\u001b[39;00m\n\u001b[1;32m 40\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01mCopasiProcess\u001b[39;00m(Process):\n", + "File \u001b[0;32m~/Desktop/uchc_work/biosimulator-processes/biosimulator_processes/process_types.py:6\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtyping\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mabc\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m ABC, abstractmethod\n\u001b[0;32m----> 6\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01mModelChange\u001b[39;00m(BaseModel):\n\u001b[1;32m 7\u001b[0m config: Dict[\u001b[38;5;28mstr\u001b[39m, Union[Dict[\u001b[38;5;28mstr\u001b[39m, Union[\u001b[38;5;28mstr\u001b[39m, \u001b[38;5;28mfloat\u001b[39m]]], Dict[\u001b[38;5;28mstr\u001b[39m, Dict[\u001b[38;5;28mstr\u001b[39m, Union[\u001b[38;5;28mstr\u001b[39m, Dict[\u001b[38;5;28mstr\u001b[39m, Union[\u001b[38;5;28mstr\u001b[39m, \u001b[38;5;28mfloat\u001b[39m]]]]]]\n\u001b[1;32m 10\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01mModelChanges\u001b[39;00m(BaseModel):\n", + "File \u001b[0;32m~/Desktop/uchc_work/biosimulator-processes/biosimulator_processes/process_types.py:7\u001b[0m, in \u001b[0;36mModelChange\u001b[0;34m()\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01mModelChange\u001b[39;00m(BaseModel):\n\u001b[0;32m----> 7\u001b[0m config: \u001b[43mDict\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mUnion\u001b[49m\u001b[43m[\u001b[49m\u001b[43mDict\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mUnion\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mfloat\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mDict\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mDict\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mUnion\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mDict\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mUnion\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mfloat\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\n", + "File \u001b[0;32m~/miniconda3/envs/processes/lib/python3.10/typing.py:312\u001b[0m, in \u001b[0;36m_tp_cache..decorator..inner\u001b[0;34m(*args, **kwds)\u001b[0m\n\u001b[1;32m 310\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m:\n\u001b[1;32m 311\u001b[0m \u001b[38;5;28;01mpass\u001b[39;00m \u001b[38;5;66;03m# All real errors (not unhashable args) are raised below.\u001b[39;00m\n\u001b[0;32m--> 312\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwds\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/miniconda3/envs/processes/lib/python3.10/typing.py:1144\u001b[0m, in \u001b[0;36m_SpecialGenericAlias.__getitem__\u001b[0;34m(self, params)\u001b[0m\n\u001b[1;32m 1142\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mParameters to generic types must be types.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 1143\u001b[0m params \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mtuple\u001b[39m(_type_check(p, msg) \u001b[38;5;28;01mfor\u001b[39;00m p \u001b[38;5;129;01min\u001b[39;00m params)\n\u001b[0;32m-> 1144\u001b[0m \u001b[43m_check_generic\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mparams\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_nparams\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1145\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcopy_with(params)\n", + "File \u001b[0;32m~/miniconda3/envs/processes/lib/python3.10/site-packages/typing_extensions.py:167\u001b[0m, in \u001b[0;36m_check_generic\u001b[0;34m(cls, parameters, elen)\u001b[0m\n\u001b[1;32m 165\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (num_tv_tuples \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m (alen \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m elen \u001b[38;5;241m-\u001b[39m num_tv_tuples):\n\u001b[1;32m 166\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[0;32m--> 167\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mToo \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmany\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mif\u001b[39;00m\u001b[38;5;250m \u001b[39malen\u001b[38;5;250m \u001b[39m\u001b[38;5;241m>\u001b[39m\u001b[38;5;250m \u001b[39melen\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01melse\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfew\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m parameters for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mcls\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m;\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 168\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m actual \u001b[39m\u001b[38;5;132;01m{\u001b[39;00malen\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m, expected \u001b[39m\u001b[38;5;132;01m{\u001b[39;00melen\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n", + "\u001b[0;31mTypeError\u001b[0m: Too many parameters for typing.Dict; actual 3, expected 2" + ] + } + ], + "source": [ + "from biosimulator_processes import CORE" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b6260555-2bad-4834-adc5-e6d358063579", + "metadata": { + "ExecuteTime": { + "end_time": "2024-02-29T22:16:46.801960Z", + "start_time": "2024-02-29T22:16:46.793248Z" + } + }, + "outputs": [], + "source": [ + "b = Builder(core=CORE)" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "initial_id", + "id": "deceb0daee61b0ce", + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "dd85f98e-c5e3-467b-97ab-1ced7e810a17", + "metadata": {}, + "source": [ + "### register new types" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "30297af1-2d65-43d9-9ab7-0589d94a8cfe", "metadata": { - "collapsed": true + "ExecuteTime": { + "end_time": "2024-01-21T21:29:21.896737Z", + "start_time": "2024-01-21T21:29:21.891980Z" + } }, "outputs": [], "source": [ - "import sys\n", + "b.register_type(\n", + " 'default 1', {\n", + " '_inherit': 'float',\n", + " '_default': 1.0})" + ] + }, + { + "cell_type": "markdown", + "id": "4f7cb796-ae5f-4209-b81c-dec1544f0840", + "metadata": {}, + "source": [ + "## Register processes" + ] + }, + { + "cell_type": "markdown", + "id": "603e75fd-7b86-4e4c-9e95-adb9faf9668b", + "metadata": {}, + "source": [ + "### list built-in processes" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "979e0bd85a31d4b0", + "metadata": { + "ExecuteTime": { + "end_time": "2024-02-29T22:17:04.854193Z", + "start_time": "2024-02-29T22:17:04.809312Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['ram-emitter',\n", + " 'CobraProcess',\n", + " 'CopasiProcess',\n", + " 'console-emitter',\n", + " 'TelluriumProcess']" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b.list_processes()" + ] + }, + { + "cell_type": "markdown", + "id": "9710444c-97c5-484c-83b0-8d82c3fdb92f", + "metadata": {}, + "source": [ + "### register process with process class" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "5bff2ea4-42f9-430e-b1cc-f0581510ec8d", + "metadata": {}, + "outputs": [], + "source": [ + "from process_bigraph.experiments.minimal_gillespie import GillespieEvent\n", + "b.register_process('GillespieEvent', GillespieEvent)" + ] + }, + { + "cell_type": "markdown", + "id": "c3635047-66dd-4c80-85ea-481c74da2a86", + "metadata": {}, + "source": [ + "### register process by address\n", + "currently only supports local addresses, but the plan is to support remote addresses and different protocols" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "f2893d4a-c13a-4d95-b85e-d5e9dce53a89", + "metadata": {}, + "outputs": [], + "source": [ + "b.register_process(\n", + " 'GillespieInterval',\n", + " address='process_bigraph.experiments.minimal_gillespie.GillespieInterval', \n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "731974c5-b470-4ddf-a037-4d4aeebc7b42", + "metadata": {}, + "source": [ + "### register with decorator" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "aec69dcc-471e-4c18-b22b-824cfe440e79", + "metadata": {}, + "outputs": [], + "source": [ + "@b.register_process('toy')\n", + "class Toy(Process):\n", + " config_schema = {\n", + " 'A': 'float',\n", + " 'B': 'float'}\n", + "\n", + " def __init__(self, config, core):\n", + " super().__init__(config, core)\n", "\n", - "sys.path.insert(0, '..')\n", - "import os\n", - "from basico import *\n", - "from process_bigraph import Composite, pf\n", - "from builder import Builder, Process as builderProcess, ProcessTypes\n", - "from biosimulator_processes.processes.copasi_process import CopasiProcess\n", - "from biosimulator_processes.process_types import MODEL_TYPE, CHANGES_SCHEMA\n", - "from biosimulator_processes.utils import play_composition\n", - "from biosimulator_processes.process_types import SedModel, ModelChange, ModelChanges" + " def schema(self):\n", + " return {\n", + " 'inputs': {\n", + " 'A': 'float',\n", + " 'B': 'float'},\n", + " 'outputs': {\n", + " 'C': 'float'}}\n", + "\n", + " def update(self, state, interval):\n", + " update = {'C': state['A'] + state['B']}\n", + " return update\n" + ] + }, + { + "cell_type": "markdown", + "id": "a108cbf0-a594-41d4-996a-de9bf9b6aeea", + "metadata": {}, + "source": [ + "### list registered processes" ] }, { "cell_type": "code", + "execution_count": 5, + "id": "40cde984-cfdf-4571-af9c-3a3755e3763c", + "metadata": { + "ExecuteTime": { + "end_time": "2024-02-29T22:17:55.896655Z", + "start_time": "2024-02-29T22:17:55.865157Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['ram-emitter',\n", + " 'CobraProcess',\n", + " 'CopasiProcess',\n", + " 'console-emitter',\n", + " 'TelluriumProcess']" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b.list_processes()" + ] + }, + { + "cell_type": "markdown", + "id": "dfa2d764-8cdb-4a1e-84c5-fd81cc4e6afe", + "metadata": {}, + "source": [ + "## Add processes to the bigraph" + ] + }, + { + "cell_type": "markdown", + "id": "49cca341-3f7d-4ac8-be5a-6a7e9f6c4872", + "metadata": {}, + "source": [ + "### add event_process" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "a153fd48f8c69115", + "metadata": { + "ExecuteTime": { + "end_time": "2024-02-29T22:18:58.854687Z", + "start_time": "2024-02-29T22:18:58.838535Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'model_id': 'string',\n", + " 'model_source': 'string',\n", + " 'model_language': {'_type': 'string', '_default': 'sbml'},\n", + " 'model_name': {'_type': 'string', '_default': 'composite_process_model'},\n", + " 'model_changes': {'species_changes': 'tree[string]',\n", + " 'global_parameter_changes': 'tree[string]',\n", + " 'reaction_changes': 'tree[string]'},\n", + " 'model_units': 'tree[string]'}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from biosimulator_processes.process_types import MODEL_TYPE\n", + "\n", + "MODEL_TYPE" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "b79dc6639a17e353", + "metadata": { + "ExecuteTime": { + "end_time": "2024-02-29T22:52:19.098009Z", + "start_time": "2024-02-29T22:52:19.072379Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, + "outputs": [], + "source": [ + "\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "64f1c09a938354e2", + "metadata": { + "ExecuteTime": { + "end_time": "2024-02-29T22:52:19.676325Z", + "start_time": "2024-02-29T22:52:19.658003Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, "outputs": [], "source": [ "species_changes = ModelChange(config={\n", @@ -47,41 +408,1128 @@ " model_language='sbml',\n", " model_name='Glyc',\n", " model_changes=model_changes\n", + ")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "dd7bc7acafe252fd", + "metadata": { + "ExecuteTime": { + "end_time": "2024-02-29T22:52:20.659250Z", + "start_time": "2024-02-29T22:52:20.644293Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'model_id': 'BIO232423',\n", + " 'model_source': 'uri:2424',\n", + " 'model_language': 'sbml',\n", + " 'model_name': 'Glyc',\n", + " 'model_changes': {'species_changes': {'config': {'A': {'initial_expression': 'A -> B'}}},\n", + " 'global_parameter_changes': {'config': {'Bol': {'unit': 'ml'}}},\n", + " 'reaction_changes': None}}" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "model.model_dump()" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "503863ee-0a58-44b3-accc-20e0167b947b", + "metadata": { + "ExecuteTime": { + "end_time": "2024-02-29T22:18:04.150647Z", + "start_time": "2024-02-29T22:18:03.537292Z" + } + }, + "outputs": [ + { + "ename": "Exception", + "evalue": "config key kdeg not in config_schema for CopasiProcess", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mException\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[6], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mb\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mcopasi_A\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43madd_process\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 2\u001b[0m \u001b[43m \u001b[49m\u001b[43mname\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mCopasiProcess\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 3\u001b[0m \u001b[43m \u001b[49m\u001b[43mkdeg\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1.0\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# kwargs fill parameters in the config\u001b[39;49;00m\n\u001b[1;32m 4\u001b[0m \u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/builder/builder_api.py:148\u001b[0m, in \u001b[0;36mBuilderNode.add_process\u001b[0;34m(self, name, config, inputs, outputs, **kwargs)\u001b[0m\n\u001b[1;32m 139\u001b[0m state \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m 140\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_type\u001b[39m\u001b[38;5;124m'\u001b[39m: edge_type,\n\u001b[1;32m 141\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124maddress\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlocal:\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;66;03m# TODO -- only support local right now?\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 144\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124moutputs\u001b[39m\u001b[38;5;124m'\u001b[39m: {} \u001b[38;5;28;01mif\u001b[39;00m outputs \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m outputs,\n\u001b[1;32m 145\u001b[0m }\n\u001b[1;32m 147\u001b[0m set_path(tree\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuilder\u001b[38;5;241m.\u001b[39mtree, path\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpath, value\u001b[38;5;241m=\u001b[39mstate)\n\u001b[0;32m--> 148\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbuilder\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcomplete\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/builder/builder_api.py:233\u001b[0m, in \u001b[0;36mBuilder.complete\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 232\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcomplete\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[0;32m--> 233\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mschema, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtree \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcore\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcomplete\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mschema\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtree\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/bigraph_schema/type_system.py:1334\u001b[0m, in \u001b[0;36mTypeSystem.complete\u001b[0;34m(self, initial_schema, initial_state)\u001b[0m\n\u001b[1;32m 1328\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhydrate(\n\u001b[1;32m 1329\u001b[0m full_schema,\n\u001b[1;32m 1330\u001b[0m initial_state)\n\u001b[1;32m 1332\u001b[0m \u001b[38;5;66;03m# fill in the parts of the composition schema\u001b[39;00m\n\u001b[1;32m 1333\u001b[0m \u001b[38;5;66;03m# determined by the state\u001b[39;00m\n\u001b[0;32m-> 1334\u001b[0m schema, state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minfer_schema\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1335\u001b[0m \u001b[43m \u001b[49m\u001b[43mfull_schema\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1336\u001b[0m \u001b[43m \u001b[49m\u001b[43mstate\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1338\u001b[0m final_state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfill(schema, state)\n\u001b[1;32m 1340\u001b[0m \u001b[38;5;66;03m# TODO: add flag to types.access(copy=True)\u001b[39;00m\n", + "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/process_bigraph/composite.py:270\u001b[0m, in \u001b[0;36mProcessTypes.infer_schema\u001b[0;34m(self, schema, state, top_state, path)\u001b[0m\n\u001b[1;32m 267\u001b[0m inner_path \u001b[38;5;241m=\u001b[39m path \u001b[38;5;241m+\u001b[39m (key,)\n\u001b[1;32m 268\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m get_path(schema, inner_path) \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mor\u001b[39;00m get_path(state, inner_path) \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mor\u001b[39;00m (\n\u001b[1;32m 269\u001b[0m \u001b[38;5;28misinstance\u001b[39m(value, \u001b[38;5;28mdict\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_type\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m value):\n\u001b[0;32m--> 270\u001b[0m schema, top_state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minfer_schema\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 271\u001b[0m \u001b[43m \u001b[49m\u001b[43mschema\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 272\u001b[0m \u001b[43m \u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 273\u001b[0m \u001b[43m \u001b[49m\u001b[43mtop_state\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtop_state\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 274\u001b[0m \u001b[43m \u001b[49m\u001b[43mpath\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43minner_path\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 276\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(state, \u001b[38;5;28mstr\u001b[39m):\n\u001b[1;32m 277\u001b[0m \u001b[38;5;28;01mpass\u001b[39;00m\n", + "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/process_bigraph/composite.py:222\u001b[0m, in \u001b[0;36mProcessTypes.infer_schema\u001b[0;34m(self, schema, state, top_state, path)\u001b[0m\n\u001b[1;32m 219\u001b[0m state_type \u001b[38;5;241m=\u001b[39m state[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_type\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[1;32m 220\u001b[0m state_schema \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39maccess(state_type)\n\u001b[0;32m--> 222\u001b[0m hydrated_state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdeserialize\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstate_schema\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstate\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 223\u001b[0m top_state \u001b[38;5;241m=\u001b[39m set_path(\n\u001b[1;32m 224\u001b[0m top_state,\n\u001b[1;32m 225\u001b[0m path,\n\u001b[1;32m 226\u001b[0m hydrated_state)\n\u001b[1;32m 228\u001b[0m schema \u001b[38;5;241m=\u001b[39m set_path(\n\u001b[1;32m 229\u001b[0m schema,\n\u001b[1;32m 230\u001b[0m path,\n\u001b[1;32m 231\u001b[0m {\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_type\u001b[39m\u001b[38;5;124m'\u001b[39m: state_type})\n", + "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/bigraph_schema/type_system.py:675\u001b[0m, in \u001b[0;36mTypeSystem.deserialize\u001b[0;34m(self, schema, encoded)\u001b[0m\n\u001b[1;32m 672\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m encoded \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 673\u001b[0m encoded \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdefault(schema)\n\u001b[0;32m--> 675\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mdeserialize_function\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 676\u001b[0m \u001b[43m \u001b[49m\u001b[43mfound\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 677\u001b[0m \u001b[43m \u001b[49m\u001b[43mencoded\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 678\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 680\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(encoded, \u001b[38;5;28mdict\u001b[39m):\n\u001b[1;32m 681\u001b[0m result \u001b[38;5;241m=\u001b[39m {}\n", + "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/process_bigraph/composite.py:95\u001b[0m, in \u001b[0;36mdeserialize_process\u001b[0;34m(schema, encoded, core)\u001b[0m\n\u001b[1;32m 90\u001b[0m interval \u001b[38;5;241m=\u001b[39m core\u001b[38;5;241m.\u001b[39mdeserialize(\n\u001b[1;32m 91\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124minterval\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 92\u001b[0m encoded\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124minterval\u001b[39m\u001b[38;5;124m'\u001b[39m))\n\u001b[1;32m 94\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124minstance\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m deserialized:\n\u001b[0;32m---> 95\u001b[0m process \u001b[38;5;241m=\u001b[39m \u001b[43minstantiate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcore\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcore\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 96\u001b[0m deserialized[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124minstance\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m process\n\u001b[1;32m 98\u001b[0m deserialized[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mconfig\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m config\n", + "File \u001b[0;32m~/Desktop/uchc_work/biosimulator-processes/biosimulator_processes/processes/copasi_process.py:121\u001b[0m, in \u001b[0;36mCopasiProcess.__init__\u001b[0;34m(self, config, core)\u001b[0m\n\u001b[1;32m 120\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m, config\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, core\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[0;32m--> 121\u001b[0m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;21;43m__init__\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcore\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 123\u001b[0m model_file \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mconfig\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmodel\u001b[39m\u001b[38;5;124m'\u001b[39m)\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmodel_source\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 124\u001b[0m sed_model_id \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mconfig\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmodel\u001b[39m\u001b[38;5;124m'\u001b[39m)\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmodel_id\u001b[39m\u001b[38;5;124m'\u001b[39m)\n", + "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/process_bigraph/composite.py:438\u001b[0m, in \u001b[0;36mProcess.__init__\u001b[0;34m(self, config, core)\u001b[0m\n\u001b[1;32m 436\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m key \u001b[38;5;129;01min\u001b[39;00m config\u001b[38;5;241m.\u001b[39mkeys():\n\u001b[1;32m 437\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m key \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mconfig_schema:\n\u001b[0;32m--> 438\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mconfig key \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mkey\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m not in config_schema for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 440\u001b[0m \u001b[38;5;66;03m# fill in defaults for config\u001b[39;00m\n\u001b[1;32m 441\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mconfig \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcore\u001b[38;5;241m.\u001b[39mfill(\n\u001b[1;32m 442\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mconfig_schema,\n\u001b[1;32m 443\u001b[0m config)\n", + "\u001b[0;31mException\u001b[0m: config key kdeg not in config_schema for CopasiProcess" + ] + } + ], + "source": [ + "copasi_config = \n", + "b['copasi_A'].add_process(\n", + " name='CopasiProcess',\n", + " kdeg=1.0, # kwargs fill parameters in the config\n", ")" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "b094f1e5-5202-48d0-8bdd-57bbdded7fd1", + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "bigraph\n", + "\n", + "\n", + "\n", + "('event_process', 'interval')\n", + "\n", + "interval\n", + "\n", + "\n", + "\n", + "('event_process',)\n", + "\n", + "event_process\n", + "\n", + "\n", + "\n", + "('event_process',)->('event_process', 'interval')\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "('event_process', 'm', 'R', 'N', 'A')->('event_process',)\n", + "\n", + "\n", + "mRNA\n", + "\n", + "\n", + "\n", + "('event_process', 'm', 'R', 'N', 'A')->('event_process',)\n", + "\n", + "\n", + "mRNA\n", + "\n", + "\n", + "\n", + "\n", + "('event_process', 'D', 'N', 'A')->('event_process',)\n", + "\n", + "\n", + "DNA\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } ], + "source": [ + "# visualize shows the process with its disconnected ports\n", + "b.visualize()" + ] + }, + { + "cell_type": "markdown", + "id": "0238392e-5d1f-403d-98c9-785576a0d91b", + "metadata": {}, + "source": [ + "### print ports" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "5ea31425-a8bb-45c3-a31d-77714cc8c137", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{ '_inputs': { 'DNA': {'A gene': 'float', 'B gene': 'float'},\n", + " 'mRNA': 'map[float]'},\n", + " '_outputs': {'mRNA': 'map[float]'}}\n" + ] + } + ], + "source": [ + "b['event_process'].interface(True)" + ] + }, + { + "cell_type": "markdown", + "id": "8068e0af-ebdd-4f01-8c54-4fb3b07fc21e", + "metadata": {}, + "source": [ + "### connect ports using connect_all\n", + "`Builder.connect_all` connects ports to stores of the same name." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "c9f462bb-5316-4724-aa8e-b3b71eb379b2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Builder({ 'event_process': { '_type': 'process',\n", + " 'address': 'local:GillespieEvent',\n", + " 'config': {'kdeg': 1.0, 'ktsc': 5.0},\n", + " 'inputs': {'DNA': ['DNA_store'], 'mRNA': ['mRNA_store']},\n", + " 'instance': ,\n", + " 'interval': 1.0,\n", + " 'outputs': {'mRNA': ['mRNA_store']}}})" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b.connect_all(append_to_store_name='_store')\n", + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "79809baf-1d87-475a-b85f-3729f4716cb4", + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "bigraph\n", + "\n", + "\n", + "\n", + "('event_process', 'interval')\n", + "\n", + "interval\n", + "\n", + "\n", + "\n", + "('mRNA_store',)\n", + "\n", + "mRNA_store\n", + "\n", + "\n", + "\n", + "('event_process',)\n", + "\n", + "event_process\n", + "\n", + "\n", + "\n", + "('mRNA_store',)->('event_process',)\n", + "\n", + "\n", + "mRNA\n", + "\n", + "\n", + "\n", + "('mRNA_store',)->('event_process',)\n", + "\n", + "\n", + "mRNA\n", + "\n", + "\n", + "\n", + "('DNA_store',)\n", + "\n", + "DNA_store\n", + "\n", + "\n", + "\n", + "('DNA_store', 'A gene')\n", + "\n", + "A gene\n", + "\n", + "\n", + "\n", + "('DNA_store',)->('DNA_store', 'A gene')\n", + "\n", + "\n", + "\n", + "\n", + "('DNA_store', 'B gene')\n", + "\n", + "B gene\n", + "\n", + "\n", + "\n", + "('DNA_store',)->('DNA_store', 'B gene')\n", + "\n", + "\n", + "\n", + "\n", + "('DNA_store',)->('event_process',)\n", + "\n", + "\n", + "DNA\n", + "\n", + "\n", + "\n", + "('event_process',)->('event_process', 'interval')\n", + "\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b.visualize()" + ] + }, + { + "cell_type": "markdown", + "id": "c7687da5-6992-447b-a51b-14373984597f", + "metadata": {}, + "source": [ + "### add interval process to the config" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "f02c15797bdb73b8", + "metadata": { + "ExecuteTime": { + "start_time": "2024-01-21T21:29:21.997588Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, + "outputs": [], + "source": [ + "b['interval_process'].add_process(\n", + " name='GillespieInterval',\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "aeb344bcd6a120ae", "metadata": { - "collapsed": false + "ExecuteTime": { + "start_time": "2024-01-21T21:29:21.998661Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, - "id": "774d37b1e2bcb0c7", - "execution_count": null + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "bigraph\n", + "\n", + "\n", + "\n", + "('event_process', 'interval')\n", + "\n", + "interval\n", + "\n", + "\n", + "\n", + "('mRNA_store',)\n", + "\n", + "mRNA_store\n", + "\n", + "\n", + "\n", + "('event_process',)\n", + "\n", + "event_process\n", + "\n", + "\n", + "\n", + "('mRNA_store',)->('event_process',)\n", + "\n", + "\n", + "mRNA\n", + "\n", + "\n", + "\n", + "('mRNA_store',)->('event_process',)\n", + "\n", + "\n", + "mRNA\n", + "\n", + "\n", + "\n", + "('DNA_store',)\n", + "\n", + "DNA_store\n", + "\n", + "\n", + "\n", + "('DNA_store', 'A gene')\n", + "\n", + "A gene\n", + "\n", + "\n", + "\n", + "('DNA_store',)->('DNA_store', 'A gene')\n", + "\n", + "\n", + "\n", + "\n", + "('DNA_store', 'B gene')\n", + "\n", + "B gene\n", + "\n", + "\n", + "\n", + "('DNA_store',)->('DNA_store', 'B gene')\n", + "\n", + "\n", + "\n", + "\n", + "('DNA_store',)->('event_process',)\n", + "\n", + "\n", + "DNA\n", + "\n", + "\n", + "\n", + "('event_process',)->('event_process', 'interval')\n", + "\n", + "\n", + "\n", + "\n", + "('interval_process',)\n", + "\n", + "interval_process\n", + "\n", + "\n", + "\n", + "\n", + "('interval_process', 'D', 'N', 'A')->('interval_process',)\n", + "\n", + "\n", + "DNA\n", + "\n", + "\n", + "\n", + "\n", + "('interval_process', 'm', 'R', 'N', 'A')->('interval_process',)\n", + "\n", + "\n", + "mRNA\n", + "\n", + "\n", + "\n", + "\n", + "('interval_process', 'i', 'n', 't', 'e', 'r', 'v', 'a', 'l')->('interval_process',)\n", + "\n", + "\n", + "interval\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b.visualize()" + ] + }, + { + "cell_type": "markdown", + "id": "be3f6695-80ed-4819-a121-de29c5cce23e", + "metadata": {}, + "source": [ + "### connect port to specific target" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "a5a1f48a-41aa-4768-b931-ad268495d836", + "metadata": {}, + "outputs": [], + "source": [ + "# to connect a port in a more targeted way, use connect and specify the port and its target path\n", + "b['interval_process'].connect(port='interval', target=['event_process', 'interval']) \n", + "\n", + "# the remaining ports can connect_all\n", + "b.connect_all() " + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "b21b54ae-49e8-47ad-bc88-1327a8e9d230", + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "bigraph\n", + "\n", + "\n", + "\n", + "('event_process', 'interval')\n", + "\n", + "interval\n", + "\n", + "\n", + "\n", + "('interval_process',)\n", + "\n", + "interval_process\n", + "\n", + "\n", + "\n", + "('event_process', 'interval')->('interval_process',)\n", + "\n", + "\n", + "interval\n", + "\n", + "\n", + "\n", + "('mRNA_store',)\n", + "\n", + "mRNA_store\n", + "\n", + "\n", + "\n", + "('mRNA_store', 'A mRNA')\n", + "\n", + "A mRNA\n", + "\n", + "\n", + "\n", + "('mRNA_store',)->('mRNA_store', 'A mRNA')\n", + "\n", + "\n", + "\n", + "\n", + "('mRNA_store', 'B mRNA')\n", + "\n", + "B mRNA\n", + "\n", + "\n", + "\n", + "('mRNA_store',)->('mRNA_store', 'B mRNA')\n", + "\n", + "\n", + "\n", + "\n", + "('event_process',)\n", + "\n", + "event_process\n", + "\n", + "\n", + "\n", + "('mRNA_store',)->('event_process',)\n", + "\n", + "\n", + "mRNA\n", + "\n", + "\n", + "\n", + "('mRNA_store',)->('event_process',)\n", + "\n", + "\n", + "mRNA\n", + "\n", + "\n", + "\n", + "('mRNA_store',)->('interval_process',)\n", + "\n", + "\n", + "mRNA\n", + "\n", + "\n", + "\n", + "('DNA_store',)\n", + "\n", + "DNA_store\n", + "\n", + "\n", + "\n", + "('DNA_store', 'A gene')\n", + "\n", + "A gene\n", + "\n", + "\n", + "\n", + "('DNA_store',)->('DNA_store', 'A gene')\n", + "\n", + "\n", + "\n", + "\n", + "('DNA_store', 'B gene')\n", + "\n", + "B gene\n", + "\n", + "\n", + "\n", + "('DNA_store',)->('DNA_store', 'B gene')\n", + "\n", + "\n", + "\n", + "\n", + "('DNA_store',)->('event_process',)\n", + "\n", + "\n", + "DNA\n", + "\n", + "\n", + "\n", + "('DNA_store',)->('interval_process',)\n", + "\n", + "\n", + "DNA\n", + "\n", + "\n", + "\n", + "('event_process',)->('event_process', 'interval')\n", + "\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b.visualize()" + ] + }, + { + "cell_type": "markdown", + "id": "ed3131ee-c607-42e5-88a3-930a84eedf0f", + "metadata": {}, + "source": [ + "### check current Builder config" + ] }, { "cell_type": "code", + "execution_count": 18, + "id": "6e00749f-03b8-496e-9a10-106dbac3713f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Builder({ 'DNA_store': {'A gene': 0.0, 'B gene': 0.0},\n", + " 'event_process': { '_type': 'process',\n", + " 'address': 'local:GillespieEvent',\n", + " 'config': {'kdeg': 1.0, 'ktsc': 5.0},\n", + " 'inputs': {'DNA': ['DNA_store'], 'mRNA': ['mRNA_store']},\n", + " 'instance': ,\n", + " 'interval': 1.0,\n", + " 'outputs': {'mRNA': ['mRNA_store']}},\n", + " 'interval_process': { '_type': 'step',\n", + " 'address': 'local:GillespieInterval',\n", + " 'config': {'kdeg': 0.1, 'ktsc': 5.0},\n", + " 'inputs': { 'DNA': ['DNA_store'],\n", + " 'mRNA': ['mRNA_store']},\n", + " 'instance': ,\n", + " 'outputs': {'interval': ['event_process', 'interval']}},\n", + " 'mRNA_store': {}})" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "markdown", + "id": "9fd708e8-0688-4b97-a50c-e3d0a1c78d83", + "metadata": {}, + "source": [ + "## Update the initial state" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "212f4501-8050-4c39-88b8-986b3c38e716", + "metadata": {}, "outputs": [], - "source": [], + "source": [ + "initial_state = {\n", + " 'DNA_store': {\n", + " 'A gene': 2.0,\n", + " 'B gene': 1.0},\n", + "}\n", + "b.update(initial_state)" + ] + }, + { + "cell_type": "markdown", + "id": "305582d1-f701-4a55-88a3-f8ec21643033", + "metadata": {}, + "source": [ + "## Generate composite from builder config and simulate" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "e9a69f36-154c-416e-b00c-5df0726be49e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "produced interval: {'interval': 1.21174311488629}\n", + "received interval: 1.21174311488629\n", + "produced interval: {'interval': 30.66671505248375}\n" + ] + } + ], + "source": [ + "composite = b.generate()\n", + "composite.run(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "578492a9-027d-4c5b-b90a-7d63e3f46bc0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "composite" + ] + }, + { + "cell_type": "markdown", + "id": "743960b7-a6d3-41af-8737-2776a66c60cd", + "metadata": {}, + "source": [ + "## Retrieve the composite document" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "c975aab012b2706f", "metadata": { - "collapsed": false + "ExecuteTime": { + "start_time": "2024-01-21T21:29:21.999855Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, - "id": "5660853c0ff3a9d1" + "outputs": [ + { + "data": { + "text/plain": [ + "{'event_process': {'_type': 'process',\n", + " 'address': 'local:GillespieEvent',\n", + " 'config': {'kdeg': 1.0, 'ktsc': 5.0},\n", + " 'inputs': {'mRNA': ['mRNA_store'], 'DNA': ['DNA_store']},\n", + " 'outputs': {'mRNA': ['mRNA_store']},\n", + " 'interval': 1.0},\n", + " 'mRNA_store': {'A mRNA': '1.0', 'B mRNA': '1.0'},\n", + " 'DNA_store': {'A gene': '2.0', 'B gene': '1.0'},\n", + " 'interval_process': {'_type': 'step',\n", + " 'address': 'local:GillespieInterval',\n", + " 'config': {'ktsc': 5.0, 'kdeg': 0.1},\n", + " 'inputs': {'DNA': ['DNA_store'], 'mRNA': ['mRNA_store']},\n", + " 'outputs': {'interval': ['event_process', 'interval']}},\n", + " 'global_time': '0.0'}" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "doc = b.document()\n", + "doc" + ] + }, + { + "cell_type": "markdown", + "id": "b32a13ed-134d-4de1-a1ed-b72807b4af45", + "metadata": {}, + "source": [ + "### save the document to file" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "752e43636bf9fd17", + "metadata": { + "ExecuteTime": { + "start_time": "2024-01-21T21:29:22.001078Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "File 'toy_bigraph' successfully written in 'out' directory.\n" + ] + } + ], + "source": [ + "b.write(filename='toy_bigraph')" + ] + }, + { + "cell_type": "markdown", + "id": "ebdd7599-0b0e-4f79-a8ab-d507a81646d8", + "metadata": { + "ExecuteTime": { + "start_time": "2024-01-21T21:29:22.001943Z" + }, + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } + }, + "source": [ + "### load a composite from document\n", + "This document represents the full state of the composite, and so can reproduce the previous composite when loaded into a fresh Builder" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "56b14beb-27de-469d-b4e6-10fc628e15e0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Builder({ 'DNA_store': {'A gene': '2.0', 'B gene': '1.0'},\n", + " 'event_process': { '_type': 'process',\n", + " 'address': 'local:GillespieEvent',\n", + " 'config': {'kdeg': 1.0, 'ktsc': 5.0},\n", + " 'inputs': {'DNA': ['DNA_store'], 'mRNA': ['mRNA_store']},\n", + " 'instance': ,\n", + " 'interval': 1.0,\n", + " 'outputs': {'mRNA': ['mRNA_store']}},\n", + " 'global_time': '0.0',\n", + " 'interval_process': { '_type': 'step',\n", + " 'address': 'local:GillespieInterval',\n", + " 'config': {'kdeg': 0.1, 'ktsc': 5.0},\n", + " 'inputs': { 'DNA': ['DNA_store'],\n", + " 'mRNA': ['mRNA_store']},\n", + " 'instance': ,\n", + " 'outputs': {'interval': ['event_process', 'interval']}},\n", + " 'mRNA_store': {'A mRNA': '1.0', 'B mRNA': '1.0'}})" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b2 = Builder(core=core, file_path='out/toy_bigraph.json')\n", + "b2" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "6197f4c3-41ca-468b-929f-cc0ebc1fabe9", + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "bigraph\n", + "\n", + "\n", + "\n", + "('event_process', 'interval')\n", + "\n", + "interval\n", + "\n", + "\n", + "\n", + "('interval_process',)\n", + "\n", + "interval_process\n", + "\n", + "\n", + "\n", + "('event_process', 'interval')->('interval_process',)\n", + "\n", + "\n", + "interval\n", + "\n", + "\n", + "\n", + "('mRNA_store',)\n", + "\n", + "mRNA_store\n", + "\n", + "\n", + "\n", + "('mRNA_store', 'A mRNA')\n", + "\n", + "A mRNA\n", + "\n", + "\n", + "\n", + "('mRNA_store',)->('mRNA_store', 'A mRNA')\n", + "\n", + "\n", + "\n", + "\n", + "('mRNA_store', 'B mRNA')\n", + "\n", + "B mRNA\n", + "\n", + "\n", + "\n", + "('mRNA_store',)->('mRNA_store', 'B mRNA')\n", + "\n", + "\n", + "\n", + "\n", + "('event_process',)\n", + "\n", + "event_process\n", + "\n", + "\n", + "\n", + "('mRNA_store',)->('event_process',)\n", + "\n", + "\n", + "mRNA\n", + "\n", + "\n", + "\n", + "('mRNA_store',)->('event_process',)\n", + "\n", + "\n", + "mRNA\n", + "\n", + "\n", + "\n", + "('mRNA_store',)->('interval_process',)\n", + "\n", + "\n", + "mRNA\n", + "\n", + "\n", + "\n", + "('DNA_store',)\n", + "\n", + "DNA_store\n", + "\n", + "\n", + "\n", + "('DNA_store', 'A gene')\n", + "\n", + "A gene\n", + "\n", + "\n", + "\n", + "('DNA_store',)->('DNA_store', 'A gene')\n", + "\n", + "\n", + "\n", + "\n", + "('DNA_store', 'B gene')\n", + "\n", + "B gene\n", + "\n", + "\n", + "\n", + "('DNA_store',)->('DNA_store', 'B gene')\n", + "\n", + "\n", + "\n", + "\n", + "('DNA_store',)->('event_process',)\n", + "\n", + "\n", + "DNA\n", + "\n", + "\n", + "\n", + "('DNA_store',)->('interval_process',)\n", + "\n", + "\n", + "DNA\n", + "\n", + "\n", + "\n", + "('event_process',)->('event_process', 'interval')\n", + "\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b2.visualize()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6c11fc1f-23ee-45e5-9975-f3d3b2e1dff9", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" + "pygments_lexer": "ipython3", + "version": "3.10.13" } }, "nbformat": 4, diff --git a/notebooks/demo.ipynb b/notebooks/demo.ipynb deleted file mode 100644 index d8f2af791..000000000 --- a/notebooks/demo.ipynb +++ /dev/null @@ -1,1537 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "808b6a4b-0894-4a8e-99d8-bf11b3164b6a", - "metadata": {}, - "source": [ - "# Bigraph-Builder Demo" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "b385dca6-942d-472c-9963-13b8cb33843c", - "metadata": { - "ExecuteTime": { - "end_time": "2024-02-29T22:16:03.547147Z", - "start_time": "2024-02-29T22:16:02.510078Z" - } - }, - "outputs": [], - "source": [ - "from builder import Builder, Process, ProcessTypes" - ] - }, - { - "cell_type": "markdown", - "id": "a403d619-4dbe-49cc-8f24-29a83e31fe15", - "metadata": {}, - "source": [ - "## Initialize the builder" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "23ae6471dca4692b", - "metadata": { - "ExecuteTime": { - "end_time": "2024-02-29T22:16:36.372695Z", - "start_time": "2024-02-29T22:16:30.599813Z" - }, - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "CobraProcess registered successfully.\n" - ] - }, - { - "ename": "TypeError", - "evalue": "Too many parameters for typing.Dict; actual 3, expected 2", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[2], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mbiosimulator_processes\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m CORE\n", - "File \u001b[0;32m~/Desktop/uchc_work/biosimulator-processes/biosimulator_processes/__init__.py:18\u001b[0m\n\u001b[1;32m 15\u001b[0m module_name, class_name \u001b[38;5;241m=\u001b[39m process_path\u001b[38;5;241m.\u001b[39mrsplit(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;241m1\u001b[39m)\n\u001b[1;32m 16\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 17\u001b[0m \u001b[38;5;66;03m# Dynamically import the module\u001b[39;00m\n\u001b[0;32m---> 18\u001b[0m process_module \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43m__import__\u001b[39;49m\u001b[43m(\u001b[49m\n\u001b[1;32m 19\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43mf\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mbiosimulator_processes.processes.\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mmodule_name\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfromlist\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\u001b[43mclass_name\u001b[49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 20\u001b[0m \u001b[38;5;66;03m# Get the class from the module\u001b[39;00m\n\u001b[1;32m 21\u001b[0m process_class \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mgetattr\u001b[39m(process_module, class_name)\n", - "File \u001b[0;32m~/Desktop/uchc_work/biosimulator-processes/biosimulator_processes/processes/copasi_process.py:36\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mprocess_bigraph\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Process, Composite, pf\n\u001b[1;32m 35\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mbiosimulator_processes\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mutils\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m fetch_biomodel\n\u001b[0;32m---> 36\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mbiosimulator_processes\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mprocess_types\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m MODEL_TYPE\n\u001b[1;32m 37\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mbiosimulator_processes\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mprocesses\u001b[39;00m\n\u001b[1;32m 40\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01mCopasiProcess\u001b[39;00m(Process):\n", - "File \u001b[0;32m~/Desktop/uchc_work/biosimulator-processes/biosimulator_processes/process_types.py:6\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtyping\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mabc\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m ABC, abstractmethod\n\u001b[0;32m----> 6\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01mModelChange\u001b[39;00m(BaseModel):\n\u001b[1;32m 7\u001b[0m config: Dict[\u001b[38;5;28mstr\u001b[39m, Union[Dict[\u001b[38;5;28mstr\u001b[39m, Union[\u001b[38;5;28mstr\u001b[39m, \u001b[38;5;28mfloat\u001b[39m]]], Dict[\u001b[38;5;28mstr\u001b[39m, Dict[\u001b[38;5;28mstr\u001b[39m, Union[\u001b[38;5;28mstr\u001b[39m, Dict[\u001b[38;5;28mstr\u001b[39m, Union[\u001b[38;5;28mstr\u001b[39m, \u001b[38;5;28mfloat\u001b[39m]]]]]]\n\u001b[1;32m 10\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01mModelChanges\u001b[39;00m(BaseModel):\n", - "File \u001b[0;32m~/Desktop/uchc_work/biosimulator-processes/biosimulator_processes/process_types.py:7\u001b[0m, in \u001b[0;36mModelChange\u001b[0;34m()\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01mModelChange\u001b[39;00m(BaseModel):\n\u001b[0;32m----> 7\u001b[0m config: \u001b[43mDict\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mUnion\u001b[49m\u001b[43m[\u001b[49m\u001b[43mDict\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mUnion\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mfloat\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mDict\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mDict\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mUnion\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mDict\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mUnion\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mfloat\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\n", - "File \u001b[0;32m~/miniconda3/envs/processes/lib/python3.10/typing.py:312\u001b[0m, in \u001b[0;36m_tp_cache..decorator..inner\u001b[0;34m(*args, **kwds)\u001b[0m\n\u001b[1;32m 310\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m:\n\u001b[1;32m 311\u001b[0m \u001b[38;5;28;01mpass\u001b[39;00m \u001b[38;5;66;03m# All real errors (not unhashable args) are raised below.\u001b[39;00m\n\u001b[0;32m--> 312\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwds\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/miniconda3/envs/processes/lib/python3.10/typing.py:1144\u001b[0m, in \u001b[0;36m_SpecialGenericAlias.__getitem__\u001b[0;34m(self, params)\u001b[0m\n\u001b[1;32m 1142\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mParameters to generic types must be types.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 1143\u001b[0m params \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mtuple\u001b[39m(_type_check(p, msg) \u001b[38;5;28;01mfor\u001b[39;00m p \u001b[38;5;129;01min\u001b[39;00m params)\n\u001b[0;32m-> 1144\u001b[0m \u001b[43m_check_generic\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mparams\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_nparams\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1145\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcopy_with(params)\n", - "File \u001b[0;32m~/miniconda3/envs/processes/lib/python3.10/site-packages/typing_extensions.py:167\u001b[0m, in \u001b[0;36m_check_generic\u001b[0;34m(cls, parameters, elen)\u001b[0m\n\u001b[1;32m 165\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (num_tv_tuples \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m (alen \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m elen \u001b[38;5;241m-\u001b[39m num_tv_tuples):\n\u001b[1;32m 166\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[0;32m--> 167\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mToo \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmany\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mif\u001b[39;00m\u001b[38;5;250m \u001b[39malen\u001b[38;5;250m \u001b[39m\u001b[38;5;241m>\u001b[39m\u001b[38;5;250m \u001b[39melen\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01melse\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfew\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m parameters for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mcls\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m;\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 168\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m actual \u001b[39m\u001b[38;5;132;01m{\u001b[39;00malen\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m, expected \u001b[39m\u001b[38;5;132;01m{\u001b[39;00melen\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n", - "\u001b[0;31mTypeError\u001b[0m: Too many parameters for typing.Dict; actual 3, expected 2" - ] - } - ], - "source": [ - "from biosimulator_processes import CORE" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b6260555-2bad-4834-adc5-e6d358063579", - "metadata": { - "ExecuteTime": { - "end_time": "2024-02-29T22:16:46.801960Z", - "start_time": "2024-02-29T22:16:46.793248Z" - } - }, - "outputs": [], - "source": [ - "b = Builder(core=CORE)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "deceb0daee61b0ce", - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "id": "dd85f98e-c5e3-467b-97ab-1ced7e810a17", - "metadata": {}, - "source": [ - "### register new types" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "30297af1-2d65-43d9-9ab7-0589d94a8cfe", - "metadata": { - "ExecuteTime": { - "end_time": "2024-01-21T21:29:21.896737Z", - "start_time": "2024-01-21T21:29:21.891980Z" - } - }, - "outputs": [], - "source": [ - "b.register_type(\n", - " 'default 1', {\n", - " '_inherit': 'float',\n", - " '_default': 1.0})" - ] - }, - { - "cell_type": "markdown", - "id": "4f7cb796-ae5f-4209-b81c-dec1544f0840", - "metadata": {}, - "source": [ - "## Register processes" - ] - }, - { - "cell_type": "markdown", - "id": "603e75fd-7b86-4e4c-9e95-adb9faf9668b", - "metadata": {}, - "source": [ - "### list built-in processes" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "979e0bd85a31d4b0", - "metadata": { - "ExecuteTime": { - "end_time": "2024-02-29T22:17:04.854193Z", - "start_time": "2024-02-29T22:17:04.809312Z" - }, - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "['ram-emitter',\n", - " 'CobraProcess',\n", - " 'CopasiProcess',\n", - " 'console-emitter',\n", - " 'TelluriumProcess']" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "b.list_processes()" - ] - }, - { - "cell_type": "markdown", - "id": "9710444c-97c5-484c-83b0-8d82c3fdb92f", - "metadata": {}, - "source": [ - "### register process with process class" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "5bff2ea4-42f9-430e-b1cc-f0581510ec8d", - "metadata": {}, - "outputs": [], - "source": [ - "from process_bigraph.experiments.minimal_gillespie import GillespieEvent\n", - "b.register_process('GillespieEvent', GillespieEvent)" - ] - }, - { - "cell_type": "markdown", - "id": "c3635047-66dd-4c80-85ea-481c74da2a86", - "metadata": {}, - "source": [ - "### register process by address\n", - "currently only supports local addresses, but the plan is to support remote addresses and different protocols" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "f2893d4a-c13a-4d95-b85e-d5e9dce53a89", - "metadata": {}, - "outputs": [], - "source": [ - "b.register_process(\n", - " 'GillespieInterval',\n", - " address='process_bigraph.experiments.minimal_gillespie.GillespieInterval', \n", - ")" - ] - }, - { - "cell_type": "markdown", - "id": "731974c5-b470-4ddf-a037-4d4aeebc7b42", - "metadata": {}, - "source": [ - "### register with decorator" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "aec69dcc-471e-4c18-b22b-824cfe440e79", - "metadata": {}, - "outputs": [], - "source": [ - "@b.register_process('toy')\n", - "class Toy(Process):\n", - " config_schema = {\n", - " 'A': 'float',\n", - " 'B': 'float'}\n", - "\n", - " def __init__(self, config, core):\n", - " super().__init__(config, core)\n", - "\n", - " def schema(self):\n", - " return {\n", - " 'inputs': {\n", - " 'A': 'float',\n", - " 'B': 'float'},\n", - " 'outputs': {\n", - " 'C': 'float'}}\n", - "\n", - " def update(self, state, interval):\n", - " update = {'C': state['A'] + state['B']}\n", - " return update\n" - ] - }, - { - "cell_type": "markdown", - "id": "a108cbf0-a594-41d4-996a-de9bf9b6aeea", - "metadata": {}, - "source": [ - "### list registered processes" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "40cde984-cfdf-4571-af9c-3a3755e3763c", - "metadata": { - "ExecuteTime": { - "end_time": "2024-02-29T22:17:55.896655Z", - "start_time": "2024-02-29T22:17:55.865157Z" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "['ram-emitter',\n", - " 'CobraProcess',\n", - " 'CopasiProcess',\n", - " 'console-emitter',\n", - " 'TelluriumProcess']" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "b.list_processes()" - ] - }, - { - "cell_type": "markdown", - "id": "dfa2d764-8cdb-4a1e-84c5-fd81cc4e6afe", - "metadata": {}, - "source": [ - "## Add processes to the bigraph" - ] - }, - { - "cell_type": "markdown", - "id": "49cca341-3f7d-4ac8-be5a-6a7e9f6c4872", - "metadata": {}, - "source": [ - "### add event_process" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "a153fd48f8c69115", - "metadata": { - "ExecuteTime": { - "end_time": "2024-02-29T22:18:58.854687Z", - "start_time": "2024-02-29T22:18:58.838535Z" - }, - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'model_id': 'string',\n", - " 'model_source': 'string',\n", - " 'model_language': {'_type': 'string', '_default': 'sbml'},\n", - " 'model_name': {'_type': 'string', '_default': 'composite_process_model'},\n", - " 'model_changes': {'species_changes': 'tree[string]',\n", - " 'global_parameter_changes': 'tree[string]',\n", - " 'reaction_changes': 'tree[string]'},\n", - " 'model_units': 'tree[string]'}" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from biosimulator_processes.process_types import MODEL_TYPE\n", - "\n", - "MODEL_TYPE" - ] - }, - { - "cell_type": "code", - "execution_count": 40, - "id": "b79dc6639a17e353", - "metadata": { - "ExecuteTime": { - "end_time": "2024-02-29T22:52:19.098009Z", - "start_time": "2024-02-29T22:52:19.072379Z" - }, - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [], - "source": [ - "\n", - " " - ] - }, - { - "cell_type": "code", - "execution_count": 41, - "id": "64f1c09a938354e2", - "metadata": { - "ExecuteTime": { - "end_time": "2024-02-29T22:52:19.676325Z", - "start_time": "2024-02-29T22:52:19.658003Z" - }, - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [], - "source": [ - "species_changes = ModelChange(config={\n", - " 'A': {\n", - " 'initial_expression': 'A -> B'\n", - " }\n", - "})\n", - "\n", - "global_params_changes = ModelChange(config={\n", - " 'Bol': {\n", - " 'unit': 'ml'\n", - " }\n", - "})\n", - "\n", - "model_changes = ModelChanges(species_changes=species_changes, global_parameter_changes=global_params_changes)\n", - "\n", - "\n", - "model = SedModel(\n", - " model_id='BIO232423',\n", - " model_source='uri:2424',\n", - " model_language='sbml',\n", - " model_name='Glyc',\n", - " model_changes=model_changes\n", - ")\n" - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "id": "dd7bc7acafe252fd", - "metadata": { - "ExecuteTime": { - "end_time": "2024-02-29T22:52:20.659250Z", - "start_time": "2024-02-29T22:52:20.644293Z" - }, - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'model_id': 'BIO232423',\n", - " 'model_source': 'uri:2424',\n", - " 'model_language': 'sbml',\n", - " 'model_name': 'Glyc',\n", - " 'model_changes': {'species_changes': {'config': {'A': {'initial_expression': 'A -> B'}}},\n", - " 'global_parameter_changes': {'config': {'Bol': {'unit': 'ml'}}},\n", - " 'reaction_changes': None}}" - ] - }, - "execution_count": 42, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "model.model_dump()" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "503863ee-0a58-44b3-accc-20e0167b947b", - "metadata": { - "ExecuteTime": { - "end_time": "2024-02-29T22:18:04.150647Z", - "start_time": "2024-02-29T22:18:03.537292Z" - } - }, - "outputs": [ - { - "ename": "Exception", - "evalue": "config key kdeg not in config_schema for CopasiProcess", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mException\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[6], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mb\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mcopasi_A\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43madd_process\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 2\u001b[0m \u001b[43m \u001b[49m\u001b[43mname\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mCopasiProcess\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 3\u001b[0m \u001b[43m \u001b[49m\u001b[43mkdeg\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1.0\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# kwargs fill parameters in the config\u001b[39;49;00m\n\u001b[1;32m 4\u001b[0m \u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/builder/builder_api.py:148\u001b[0m, in \u001b[0;36mBuilderNode.add_process\u001b[0;34m(self, name, config, inputs, outputs, **kwargs)\u001b[0m\n\u001b[1;32m 139\u001b[0m state \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m 140\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_type\u001b[39m\u001b[38;5;124m'\u001b[39m: edge_type,\n\u001b[1;32m 141\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124maddress\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlocal:\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;66;03m# TODO -- only support local right now?\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 144\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124moutputs\u001b[39m\u001b[38;5;124m'\u001b[39m: {} \u001b[38;5;28;01mif\u001b[39;00m outputs \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m outputs,\n\u001b[1;32m 145\u001b[0m }\n\u001b[1;32m 147\u001b[0m set_path(tree\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuilder\u001b[38;5;241m.\u001b[39mtree, path\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpath, value\u001b[38;5;241m=\u001b[39mstate)\n\u001b[0;32m--> 148\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbuilder\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcomplete\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/builder/builder_api.py:233\u001b[0m, in \u001b[0;36mBuilder.complete\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 232\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcomplete\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[0;32m--> 233\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mschema, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtree \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcore\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcomplete\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mschema\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtree\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/bigraph_schema/type_system.py:1334\u001b[0m, in \u001b[0;36mTypeSystem.complete\u001b[0;34m(self, initial_schema, initial_state)\u001b[0m\n\u001b[1;32m 1328\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhydrate(\n\u001b[1;32m 1329\u001b[0m full_schema,\n\u001b[1;32m 1330\u001b[0m initial_state)\n\u001b[1;32m 1332\u001b[0m \u001b[38;5;66;03m# fill in the parts of the composition schema\u001b[39;00m\n\u001b[1;32m 1333\u001b[0m \u001b[38;5;66;03m# determined by the state\u001b[39;00m\n\u001b[0;32m-> 1334\u001b[0m schema, state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minfer_schema\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1335\u001b[0m \u001b[43m \u001b[49m\u001b[43mfull_schema\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1336\u001b[0m \u001b[43m \u001b[49m\u001b[43mstate\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1338\u001b[0m final_state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfill(schema, state)\n\u001b[1;32m 1340\u001b[0m \u001b[38;5;66;03m# TODO: add flag to types.access(copy=True)\u001b[39;00m\n", - "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/process_bigraph/composite.py:270\u001b[0m, in \u001b[0;36mProcessTypes.infer_schema\u001b[0;34m(self, schema, state, top_state, path)\u001b[0m\n\u001b[1;32m 267\u001b[0m inner_path \u001b[38;5;241m=\u001b[39m path \u001b[38;5;241m+\u001b[39m (key,)\n\u001b[1;32m 268\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m get_path(schema, inner_path) \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mor\u001b[39;00m get_path(state, inner_path) \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mor\u001b[39;00m (\n\u001b[1;32m 269\u001b[0m \u001b[38;5;28misinstance\u001b[39m(value, \u001b[38;5;28mdict\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_type\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m value):\n\u001b[0;32m--> 270\u001b[0m schema, top_state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minfer_schema\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 271\u001b[0m \u001b[43m \u001b[49m\u001b[43mschema\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 272\u001b[0m \u001b[43m \u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 273\u001b[0m \u001b[43m \u001b[49m\u001b[43mtop_state\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtop_state\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 274\u001b[0m \u001b[43m \u001b[49m\u001b[43mpath\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43minner_path\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 276\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(state, \u001b[38;5;28mstr\u001b[39m):\n\u001b[1;32m 277\u001b[0m \u001b[38;5;28;01mpass\u001b[39;00m\n", - "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/process_bigraph/composite.py:222\u001b[0m, in \u001b[0;36mProcessTypes.infer_schema\u001b[0;34m(self, schema, state, top_state, path)\u001b[0m\n\u001b[1;32m 219\u001b[0m state_type \u001b[38;5;241m=\u001b[39m state[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_type\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[1;32m 220\u001b[0m state_schema \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39maccess(state_type)\n\u001b[0;32m--> 222\u001b[0m hydrated_state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdeserialize\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstate_schema\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstate\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 223\u001b[0m top_state \u001b[38;5;241m=\u001b[39m set_path(\n\u001b[1;32m 224\u001b[0m top_state,\n\u001b[1;32m 225\u001b[0m path,\n\u001b[1;32m 226\u001b[0m hydrated_state)\n\u001b[1;32m 228\u001b[0m schema \u001b[38;5;241m=\u001b[39m set_path(\n\u001b[1;32m 229\u001b[0m schema,\n\u001b[1;32m 230\u001b[0m path,\n\u001b[1;32m 231\u001b[0m {\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_type\u001b[39m\u001b[38;5;124m'\u001b[39m: state_type})\n", - "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/bigraph_schema/type_system.py:675\u001b[0m, in \u001b[0;36mTypeSystem.deserialize\u001b[0;34m(self, schema, encoded)\u001b[0m\n\u001b[1;32m 672\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m encoded \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 673\u001b[0m encoded \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdefault(schema)\n\u001b[0;32m--> 675\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mdeserialize_function\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 676\u001b[0m \u001b[43m \u001b[49m\u001b[43mfound\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 677\u001b[0m \u001b[43m \u001b[49m\u001b[43mencoded\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 678\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 680\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(encoded, \u001b[38;5;28mdict\u001b[39m):\n\u001b[1;32m 681\u001b[0m result \u001b[38;5;241m=\u001b[39m {}\n", - "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/process_bigraph/composite.py:95\u001b[0m, in \u001b[0;36mdeserialize_process\u001b[0;34m(schema, encoded, core)\u001b[0m\n\u001b[1;32m 90\u001b[0m interval \u001b[38;5;241m=\u001b[39m core\u001b[38;5;241m.\u001b[39mdeserialize(\n\u001b[1;32m 91\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124minterval\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 92\u001b[0m encoded\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124minterval\u001b[39m\u001b[38;5;124m'\u001b[39m))\n\u001b[1;32m 94\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124minstance\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m deserialized:\n\u001b[0;32m---> 95\u001b[0m process \u001b[38;5;241m=\u001b[39m \u001b[43minstantiate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcore\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcore\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 96\u001b[0m deserialized[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124minstance\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m process\n\u001b[1;32m 98\u001b[0m deserialized[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mconfig\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m config\n", - "File \u001b[0;32m~/Desktop/uchc_work/biosimulator-processes/biosimulator_processes/processes/copasi_process.py:121\u001b[0m, in \u001b[0;36mCopasiProcess.__init__\u001b[0;34m(self, config, core)\u001b[0m\n\u001b[1;32m 120\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m, config\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, core\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[0;32m--> 121\u001b[0m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;21;43m__init__\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcore\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 123\u001b[0m model_file \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mconfig\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmodel\u001b[39m\u001b[38;5;124m'\u001b[39m)\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmodel_source\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 124\u001b[0m sed_model_id \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mconfig\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmodel\u001b[39m\u001b[38;5;124m'\u001b[39m)\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmodel_id\u001b[39m\u001b[38;5;124m'\u001b[39m)\n", - "File \u001b[0;32m~/Library/Caches/pypoetry/virtualenvs/biosimulator-processes-KVuYbFzt-py3.10/lib/python3.10/site-packages/process_bigraph/composite.py:438\u001b[0m, in \u001b[0;36mProcess.__init__\u001b[0;34m(self, config, core)\u001b[0m\n\u001b[1;32m 436\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m key \u001b[38;5;129;01min\u001b[39;00m config\u001b[38;5;241m.\u001b[39mkeys():\n\u001b[1;32m 437\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m key \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mconfig_schema:\n\u001b[0;32m--> 438\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mconfig key \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mkey\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m not in config_schema for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__class__\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 440\u001b[0m \u001b[38;5;66;03m# fill in defaults for config\u001b[39;00m\n\u001b[1;32m 441\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mconfig \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcore\u001b[38;5;241m.\u001b[39mfill(\n\u001b[1;32m 442\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mconfig_schema,\n\u001b[1;32m 443\u001b[0m config)\n", - "\u001b[0;31mException\u001b[0m: config key kdeg not in config_schema for CopasiProcess" - ] - } - ], - "source": [ - "copasi_config = \n", - "b['copasi_A'].add_process(\n", - " name='CopasiProcess',\n", - " kdeg=1.0, # kwargs fill parameters in the config\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "b094f1e5-5202-48d0-8bdd-57bbdded7fd1", - "metadata": {}, - "outputs": [ - { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "bigraph\n", - "\n", - "\n", - "\n", - "('event_process', 'interval')\n", - "\n", - "interval\n", - "\n", - "\n", - "\n", - "('event_process',)\n", - "\n", - "event_process\n", - "\n", - "\n", - "\n", - "('event_process',)->('event_process', 'interval')\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "('event_process', 'm', 'R', 'N', 'A')->('event_process',)\n", - "\n", - "\n", - "mRNA\n", - "\n", - "\n", - "\n", - "('event_process', 'm', 'R', 'N', 'A')->('event_process',)\n", - "\n", - "\n", - "mRNA\n", - "\n", - "\n", - "\n", - "\n", - "('event_process', 'D', 'N', 'A')->('event_process',)\n", - "\n", - "\n", - "DNA\n", - "\n", - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# visualize shows the process with its disconnected ports\n", - "b.visualize()" - ] - }, - { - "cell_type": "markdown", - "id": "0238392e-5d1f-403d-98c9-785576a0d91b", - "metadata": {}, - "source": [ - "### print ports" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "5ea31425-a8bb-45c3-a31d-77714cc8c137", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{ '_inputs': { 'DNA': {'A gene': 'float', 'B gene': 'float'},\n", - " 'mRNA': 'map[float]'},\n", - " '_outputs': {'mRNA': 'map[float]'}}\n" - ] - } - ], - "source": [ - "b['event_process'].interface(True)" - ] - }, - { - "cell_type": "markdown", - "id": "8068e0af-ebdd-4f01-8c54-4fb3b07fc21e", - "metadata": {}, - "source": [ - "### connect ports using connect_all\n", - "`Builder.connect_all` connects ports to stores of the same name." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "c9f462bb-5316-4724-aa8e-b3b71eb379b2", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Builder({ 'event_process': { '_type': 'process',\n", - " 'address': 'local:GillespieEvent',\n", - " 'config': {'kdeg': 1.0, 'ktsc': 5.0},\n", - " 'inputs': {'DNA': ['DNA_store'], 'mRNA': ['mRNA_store']},\n", - " 'instance': ,\n", - " 'interval': 1.0,\n", - " 'outputs': {'mRNA': ['mRNA_store']}}})" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "b.connect_all(append_to_store_name='_store')\n", - "b" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "79809baf-1d87-475a-b85f-3729f4716cb4", - "metadata": {}, - "outputs": [ - { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "bigraph\n", - "\n", - "\n", - "\n", - "('event_process', 'interval')\n", - "\n", - "interval\n", - "\n", - "\n", - "\n", - "('mRNA_store',)\n", - "\n", - "mRNA_store\n", - "\n", - "\n", - "\n", - "('event_process',)\n", - "\n", - "event_process\n", - "\n", - "\n", - "\n", - "('mRNA_store',)->('event_process',)\n", - "\n", - "\n", - "mRNA\n", - "\n", - "\n", - "\n", - "('mRNA_store',)->('event_process',)\n", - "\n", - "\n", - "mRNA\n", - "\n", - "\n", - "\n", - "('DNA_store',)\n", - "\n", - "DNA_store\n", - "\n", - "\n", - "\n", - "('DNA_store', 'A gene')\n", - "\n", - "A gene\n", - "\n", - "\n", - "\n", - "('DNA_store',)->('DNA_store', 'A gene')\n", - "\n", - "\n", - "\n", - "\n", - "('DNA_store', 'B gene')\n", - "\n", - "B gene\n", - "\n", - "\n", - "\n", - "('DNA_store',)->('DNA_store', 'B gene')\n", - "\n", - "\n", - "\n", - "\n", - "('DNA_store',)->('event_process',)\n", - "\n", - "\n", - "DNA\n", - "\n", - "\n", - "\n", - "('event_process',)->('event_process', 'interval')\n", - "\n", - "\n", - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "b.visualize()" - ] - }, - { - "cell_type": "markdown", - "id": "c7687da5-6992-447b-a51b-14373984597f", - "metadata": {}, - "source": [ - "### add interval process to the config" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "f02c15797bdb73b8", - "metadata": { - "ExecuteTime": { - "start_time": "2024-01-21T21:29:21.997588Z" - }, - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [], - "source": [ - "b['interval_process'].add_process(\n", - " name='GillespieInterval',\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "id": "aeb344bcd6a120ae", - "metadata": { - "ExecuteTime": { - "start_time": "2024-01-21T21:29:21.998661Z" - }, - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [ - { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "bigraph\n", - "\n", - "\n", - "\n", - "('event_process', 'interval')\n", - "\n", - "interval\n", - "\n", - "\n", - "\n", - "('mRNA_store',)\n", - "\n", - "mRNA_store\n", - "\n", - "\n", - "\n", - "('event_process',)\n", - "\n", - "event_process\n", - "\n", - "\n", - "\n", - "('mRNA_store',)->('event_process',)\n", - "\n", - "\n", - "mRNA\n", - "\n", - "\n", - "\n", - "('mRNA_store',)->('event_process',)\n", - "\n", - "\n", - "mRNA\n", - "\n", - "\n", - "\n", - "('DNA_store',)\n", - "\n", - "DNA_store\n", - "\n", - "\n", - "\n", - "('DNA_store', 'A gene')\n", - "\n", - "A gene\n", - "\n", - "\n", - "\n", - "('DNA_store',)->('DNA_store', 'A gene')\n", - "\n", - "\n", - "\n", - "\n", - "('DNA_store', 'B gene')\n", - "\n", - "B gene\n", - "\n", - "\n", - "\n", - "('DNA_store',)->('DNA_store', 'B gene')\n", - "\n", - "\n", - "\n", - "\n", - "('DNA_store',)->('event_process',)\n", - "\n", - "\n", - "DNA\n", - "\n", - "\n", - "\n", - "('event_process',)->('event_process', 'interval')\n", - "\n", - "\n", - "\n", - "\n", - "('interval_process',)\n", - "\n", - "interval_process\n", - "\n", - "\n", - "\n", - "\n", - "('interval_process', 'D', 'N', 'A')->('interval_process',)\n", - "\n", - "\n", - "DNA\n", - "\n", - "\n", - "\n", - "\n", - "('interval_process', 'm', 'R', 'N', 'A')->('interval_process',)\n", - "\n", - "\n", - "mRNA\n", - "\n", - "\n", - "\n", - "\n", - "('interval_process', 'i', 'n', 't', 'e', 'r', 'v', 'a', 'l')->('interval_process',)\n", - "\n", - "\n", - "interval\n", - "\n", - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "b.visualize()" - ] - }, - { - "cell_type": "markdown", - "id": "be3f6695-80ed-4819-a121-de29c5cce23e", - "metadata": {}, - "source": [ - "### connect port to specific target" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "id": "a5a1f48a-41aa-4768-b931-ad268495d836", - "metadata": {}, - "outputs": [], - "source": [ - "# to connect a port in a more targeted way, use connect and specify the port and its target path\n", - "b['interval_process'].connect(port='interval', target=['event_process', 'interval']) \n", - "\n", - "# the remaining ports can connect_all\n", - "b.connect_all() " - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "id": "b21b54ae-49e8-47ad-bc88-1327a8e9d230", - "metadata": {}, - "outputs": [ - { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "bigraph\n", - "\n", - "\n", - "\n", - "('event_process', 'interval')\n", - "\n", - "interval\n", - "\n", - "\n", - "\n", - "('interval_process',)\n", - "\n", - "interval_process\n", - "\n", - "\n", - "\n", - "('event_process', 'interval')->('interval_process',)\n", - "\n", - "\n", - "interval\n", - "\n", - "\n", - "\n", - "('mRNA_store',)\n", - "\n", - "mRNA_store\n", - "\n", - "\n", - "\n", - "('mRNA_store', 'A mRNA')\n", - "\n", - "A mRNA\n", - "\n", - "\n", - "\n", - "('mRNA_store',)->('mRNA_store', 'A mRNA')\n", - "\n", - "\n", - "\n", - "\n", - "('mRNA_store', 'B mRNA')\n", - "\n", - "B mRNA\n", - "\n", - "\n", - "\n", - "('mRNA_store',)->('mRNA_store', 'B mRNA')\n", - "\n", - "\n", - "\n", - "\n", - "('event_process',)\n", - "\n", - "event_process\n", - "\n", - "\n", - "\n", - "('mRNA_store',)->('event_process',)\n", - "\n", - "\n", - "mRNA\n", - "\n", - "\n", - "\n", - "('mRNA_store',)->('event_process',)\n", - "\n", - "\n", - "mRNA\n", - "\n", - "\n", - "\n", - "('mRNA_store',)->('interval_process',)\n", - "\n", - "\n", - "mRNA\n", - "\n", - "\n", - "\n", - "('DNA_store',)\n", - "\n", - "DNA_store\n", - "\n", - "\n", - "\n", - "('DNA_store', 'A gene')\n", - "\n", - "A gene\n", - "\n", - "\n", - "\n", - "('DNA_store',)->('DNA_store', 'A gene')\n", - "\n", - "\n", - "\n", - "\n", - "('DNA_store', 'B gene')\n", - "\n", - "B gene\n", - "\n", - "\n", - "\n", - "('DNA_store',)->('DNA_store', 'B gene')\n", - "\n", - "\n", - "\n", - "\n", - "('DNA_store',)->('event_process',)\n", - "\n", - "\n", - "DNA\n", - "\n", - "\n", - "\n", - "('DNA_store',)->('interval_process',)\n", - "\n", - "\n", - "DNA\n", - "\n", - "\n", - "\n", - "('event_process',)->('event_process', 'interval')\n", - "\n", - "\n", - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "b.visualize()" - ] - }, - { - "cell_type": "markdown", - "id": "ed3131ee-c607-42e5-88a3-930a84eedf0f", - "metadata": {}, - "source": [ - "### check current Builder config" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "id": "6e00749f-03b8-496e-9a10-106dbac3713f", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Builder({ 'DNA_store': {'A gene': 0.0, 'B gene': 0.0},\n", - " 'event_process': { '_type': 'process',\n", - " 'address': 'local:GillespieEvent',\n", - " 'config': {'kdeg': 1.0, 'ktsc': 5.0},\n", - " 'inputs': {'DNA': ['DNA_store'], 'mRNA': ['mRNA_store']},\n", - " 'instance': ,\n", - " 'interval': 1.0,\n", - " 'outputs': {'mRNA': ['mRNA_store']}},\n", - " 'interval_process': { '_type': 'step',\n", - " 'address': 'local:GillespieInterval',\n", - " 'config': {'kdeg': 0.1, 'ktsc': 5.0},\n", - " 'inputs': { 'DNA': ['DNA_store'],\n", - " 'mRNA': ['mRNA_store']},\n", - " 'instance': ,\n", - " 'outputs': {'interval': ['event_process', 'interval']}},\n", - " 'mRNA_store': {}})" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "b" - ] - }, - { - "cell_type": "markdown", - "id": "9fd708e8-0688-4b97-a50c-e3d0a1c78d83", - "metadata": {}, - "source": [ - "## Update the initial state" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "id": "212f4501-8050-4c39-88b8-986b3c38e716", - "metadata": {}, - "outputs": [], - "source": [ - "initial_state = {\n", - " 'DNA_store': {\n", - " 'A gene': 2.0,\n", - " 'B gene': 1.0},\n", - "}\n", - "b.update(initial_state)" - ] - }, - { - "cell_type": "markdown", - "id": "305582d1-f701-4a55-88a3-f8ec21643033", - "metadata": {}, - "source": [ - "## Generate composite from builder config and simulate" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "id": "e9a69f36-154c-416e-b00c-5df0726be49e", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "produced interval: {'interval': 1.21174311488629}\n", - "received interval: 1.21174311488629\n", - "produced interval: {'interval': 30.66671505248375}\n" - ] - } - ], - "source": [ - "composite = b.generate()\n", - "composite.run(10)" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "id": "578492a9-027d-4c5b-b90a-7d63e3f46bc0", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "composite" - ] - }, - { - "cell_type": "markdown", - "id": "743960b7-a6d3-41af-8737-2776a66c60cd", - "metadata": {}, - "source": [ - "## Retrieve the composite document" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "id": "c975aab012b2706f", - "metadata": { - "ExecuteTime": { - "start_time": "2024-01-21T21:29:21.999855Z" - }, - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'event_process': {'_type': 'process',\n", - " 'address': 'local:GillespieEvent',\n", - " 'config': {'kdeg': 1.0, 'ktsc': 5.0},\n", - " 'inputs': {'mRNA': ['mRNA_store'], 'DNA': ['DNA_store']},\n", - " 'outputs': {'mRNA': ['mRNA_store']},\n", - " 'interval': 1.0},\n", - " 'mRNA_store': {'A mRNA': '1.0', 'B mRNA': '1.0'},\n", - " 'DNA_store': {'A gene': '2.0', 'B gene': '1.0'},\n", - " 'interval_process': {'_type': 'step',\n", - " 'address': 'local:GillespieInterval',\n", - " 'config': {'ktsc': 5.0, 'kdeg': 0.1},\n", - " 'inputs': {'DNA': ['DNA_store'], 'mRNA': ['mRNA_store']},\n", - " 'outputs': {'interval': ['event_process', 'interval']}},\n", - " 'global_time': '0.0'}" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "doc = b.document()\n", - "doc" - ] - }, - { - "cell_type": "markdown", - "id": "b32a13ed-134d-4de1-a1ed-b72807b4af45", - "metadata": {}, - "source": [ - "### save the document to file" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "id": "752e43636bf9fd17", - "metadata": { - "ExecuteTime": { - "start_time": "2024-01-21T21:29:22.001078Z" - }, - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "File 'toy_bigraph' successfully written in 'out' directory.\n" - ] - } - ], - "source": [ - "b.write(filename='toy_bigraph')" - ] - }, - { - "cell_type": "markdown", - "id": "ebdd7599-0b0e-4f79-a8ab-d507a81646d8", - "metadata": { - "ExecuteTime": { - "start_time": "2024-01-21T21:29:22.001943Z" - }, - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "source": [ - "### load a composite from document\n", - "This document represents the full state of the composite, and so can reproduce the previous composite when loaded into a fresh Builder" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "id": "56b14beb-27de-469d-b4e6-10fc628e15e0", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Builder({ 'DNA_store': {'A gene': '2.0', 'B gene': '1.0'},\n", - " 'event_process': { '_type': 'process',\n", - " 'address': 'local:GillespieEvent',\n", - " 'config': {'kdeg': 1.0, 'ktsc': 5.0},\n", - " 'inputs': {'DNA': ['DNA_store'], 'mRNA': ['mRNA_store']},\n", - " 'instance': ,\n", - " 'interval': 1.0,\n", - " 'outputs': {'mRNA': ['mRNA_store']}},\n", - " 'global_time': '0.0',\n", - " 'interval_process': { '_type': 'step',\n", - " 'address': 'local:GillespieInterval',\n", - " 'config': {'kdeg': 0.1, 'ktsc': 5.0},\n", - " 'inputs': { 'DNA': ['DNA_store'],\n", - " 'mRNA': ['mRNA_store']},\n", - " 'instance': ,\n", - " 'outputs': {'interval': ['event_process', 'interval']}},\n", - " 'mRNA_store': {'A mRNA': '1.0', 'B mRNA': '1.0'}})" - ] - }, - "execution_count": 26, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "b2 = Builder(core=core, file_path='out/toy_bigraph.json')\n", - "b2" - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "id": "6197f4c3-41ca-468b-929f-cc0ebc1fabe9", - "metadata": {}, - "outputs": [ - { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "bigraph\n", - "\n", - "\n", - "\n", - "('event_process', 'interval')\n", - "\n", - "interval\n", - "\n", - "\n", - "\n", - "('interval_process',)\n", - "\n", - "interval_process\n", - "\n", - "\n", - "\n", - "('event_process', 'interval')->('interval_process',)\n", - "\n", - "\n", - "interval\n", - "\n", - "\n", - "\n", - "('mRNA_store',)\n", - "\n", - "mRNA_store\n", - "\n", - "\n", - "\n", - "('mRNA_store', 'A mRNA')\n", - "\n", - "A mRNA\n", - "\n", - "\n", - "\n", - "('mRNA_store',)->('mRNA_store', 'A mRNA')\n", - "\n", - "\n", - "\n", - "\n", - "('mRNA_store', 'B mRNA')\n", - "\n", - "B mRNA\n", - "\n", - "\n", - "\n", - "('mRNA_store',)->('mRNA_store', 'B mRNA')\n", - "\n", - "\n", - "\n", - "\n", - "('event_process',)\n", - "\n", - "event_process\n", - "\n", - "\n", - "\n", - "('mRNA_store',)->('event_process',)\n", - "\n", - "\n", - "mRNA\n", - "\n", - "\n", - "\n", - "('mRNA_store',)->('event_process',)\n", - "\n", - "\n", - "mRNA\n", - "\n", - "\n", - "\n", - "('mRNA_store',)->('interval_process',)\n", - "\n", - "\n", - "mRNA\n", - "\n", - "\n", - "\n", - "('DNA_store',)\n", - "\n", - "DNA_store\n", - "\n", - "\n", - "\n", - "('DNA_store', 'A gene')\n", - "\n", - "A gene\n", - "\n", - "\n", - "\n", - "('DNA_store',)->('DNA_store', 'A gene')\n", - "\n", - "\n", - "\n", - "\n", - "('DNA_store', 'B gene')\n", - "\n", - "B gene\n", - "\n", - "\n", - "\n", - "('DNA_store',)->('DNA_store', 'B gene')\n", - "\n", - "\n", - "\n", - "\n", - "('DNA_store',)->('event_process',)\n", - "\n", - "\n", - "DNA\n", - "\n", - "\n", - "\n", - "('DNA_store',)->('interval_process',)\n", - "\n", - "\n", - "DNA\n", - "\n", - "\n", - "\n", - "('event_process',)->('event_process', 'interval')\n", - "\n", - "\n", - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 27, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "b2.visualize()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6c11fc1f-23ee-45e5-9975-f3d3b2e1dff9", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -}