Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eagmon committed Aug 6, 2023
1 parent 95ba2b2 commit b8844e8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 54 deletions.
File renamed without changes.
92 changes: 38 additions & 54 deletions vivarium_tellurium/processes/tellurium_process.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,38 @@
'''
Execute by running: ``python template/processes/template_process.py``
'''
"""
Execute by running: ``python vivarium_tellurium/processes/tellurium_process.py`
"""

from vivarium.core.process import Process
from vivarium.core.engine import Engine, pp
import tellurium as te


class TelluriumProcess(Process):
'''
Class which serves to be a Tellurium implementation of the `vivarium.core.processes.Process()` interface.
'''

defaults = {
'sbml_model_path': '',
'antimony_string': None,
'exposed_species': None, # list of exposed species ids
'parameter1': 3.0,
}
"""Vivarium Process interface for Tellurium.
Instantiates a `roadrunner` simulator instance using either `SBML`(default,`file`) or `antimony`(optional,`str`)
def __init__(self, config=None):
'''
A new instance of a `tellurium`-based implementation of the `vivarium.core.processes.Process() interface.
Instantiates a `roadrunner` simulator instance using either `SBML`(default,`file`) or `antimony`(optional,`str`)
#### Parameters:
----------------
parameters: `Dict`
configurations of the simulator process parameters. Defaults to `defaults`:\n
`'sbml_model_file': ''`
`'antimony_string': None`
`'exposed_species': None` # list of exposed species ids
`'parameter1': 3.0`
#### Returns:
-------------
`TelluriumProcess`
A generic instance of a Tellurium simulator process.
'''

"""

defaults = {
'sbml_model_path': '',
'antimony_string': None,
'exposed_species': None, # list of exposed species ids
}

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

# initialize a tellurium(roadrunner) simulation object. Load the model in using either sbml(default) or antimony
Expand All @@ -49,21 +42,18 @@ def __init__(self, config=None):
self.simulator = te.loadSBMLModel(self.parameters['sbml_model_path'])

# extract the variables
self.species = self.simulator.get_species() # PLACEHOLDER!!!!!!!!

self.species = self.simulator.get_species() # PLACEHOLDER!!!!!!!!

def ports_schema(self):
# TODO -- need to set the ports/variables according to self.config assignments. Similar to viv-biosimul
species_schema = {
species_id: {
# TODO -- set the ports/variables according to self.config assignments. Similar to viv-biosimul
return {
'species': {
species_id: {
'_default': 1.0,
'_updater': 'set',
'_emit': True,
} for species_id in self.config['exposed_species']
}

return {
'species': species_schema
}
}

def next_update(self, interval, states):
Expand All @@ -84,14 +74,9 @@ def next_update(self, interval, states):

# functions to configure and run the process
def test_tellurium_process():
'''
Run a test simulation process. Loaded using SBML.
Returns:
The simulation output.
'''
sbml_model_path = 'vivarium_tellurium/library/Caravagna-J-Theor-Biol-2010-tumor-suppressive-oscillations/Caravagna2010.xml'
# 1.) Declare the initial state, mirroring the ports structure. May be passed as a parsable argument.
sbml_model_path = 'vivarium_tellurium/models/Caravagna2010.xml'

# 1. Declare the initial state, mirroring the ports structure. May be passed as a parsable argument.
initial_state = {
'internal': {
'A': 0.0
Expand All @@ -101,22 +86,21 @@ def test_tellurium_process():
},
}

# 2.) Create the simulation run parameters for the simulator
# 2. Create the simulation run parameters for the simulator
config = {
'sbml_model_path': sbml_model_path,
'parameter1': 4.0,
}
}

# 3.) Initialize the process by passing in a config dict
# 3. Initialize the process by passing in a config dict
template_process = TelluriumProcess(config)

# 4.) Get the ports for the process
# 4. Get the ports for the process
template_process_ports = template_process.ports_schema()

# 4a.) view the ports:
# 4a. view the ports:
print(f'PORTS FOR {pp(template_process)}: {pp(template_process_ports)}')

#5.) Feed the Simulator Process instance you just created to the vivarium Engine
# 5. Feed the Simulator Process instance you just created to the vivarium Engine
sim = Engine(
processes={
'template': template_process,
Expand All @@ -129,33 +113,33 @@ def test_tellurium_process():
initial_state=initial_state
)

#6.) Call update with that sim object, which calls the next_update method in the implementation you created above using total_time
# 6. Call update with that sim object, which calls the next_update method in the implementation you created above using total_time
total_time = 3
sim.update(
interval=total_time
)

#7.) Get the data which is emitted from the sim object.
# 7. Get the data which is emitted from the sim object.
data = sim.emitter.get_timeseries()

#7a.) Observe the data which is return from running the process:
# 7a. Observe the data which is return from running the process:
print(f'RESULTS: {pp(data)}')
return data


def test_load_from_antimony():
# 1.) Adding an antimony string to your config dict will allow for "antimony mode" to be turned on.
# 1. Adding an antimony string to your config dict will allow for "antimony mode" to be turned on.
config = {
'antimony_string': 'S1 -> S2; k1*S1'
}

# 2.) Initialize the process by passing in a config dict
# 2. Initialize the process by passing in a config dict
antimony_process = TelluriumProcess(config)
print(antimony_process.simulator)


# run module with python template/processes/template_process.py
# run module with python vivarium_tellurium/processes/tellurium_process.py
if __name__ == '__main__':
test_tellurium_process()
test_load_from_antimony()
# test_load_from_antimony()

0 comments on commit b8844e8

Please sign in to comment.