Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eagmon committed Jul 19, 2023
1 parent 9f2081d commit d03d24e
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 289 deletions.
105 changes: 0 additions & 105 deletions template/experiments/glucose_phosphorylation.py

This file was deleted.

119 changes: 0 additions & 119 deletions template/processes/glucose_phosphorylation.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
'''
Execute by running: ``python template/processes/template_process.py``
TODO: Replace the template code to implement your own process.
'''

import os

from vivarium.core.process import Process
from vivarium.core.composition import (
simulate_process,
PROCESS_OUT_DIR,
)
from vivarium.plots.simulation_output import plot_simulation_output

from vivarium.core.engine import Engine, pp

# a global NAME is used for the output directory and for the process name
NAME = 'template'
# TODO import tellurium


class Template(Process):
'''
This mock process provides a basic template that can be used for a new process
'''

# give the process a name, so that it can register in the process_repository
name = NAME
class TelluriumProcess(Process):
''' Vivarium Process for Tellurium '''

# declare default parameters as class variables
defaults = {
'model_path': '',
'uptake_rate': 0.1,
}

Expand All @@ -50,6 +32,7 @@ def ports_schema(self):
* `_serializer`
'''

# TODO this needs to be done automatically by reading the tellurium model. Maybe study vivarium-biosimulators
return {
'internal': {
'A': {
Expand All @@ -67,36 +50,35 @@ def ports_schema(self):
},
}

def next_update(self, timestep, states):
def next_update(self, interval, states):

# get the states
# get the states from the tellurium model
internal_A = states['internal']['A']
external_A = states['external']['A']

# calculate timestep-dependent updates
internal_update = self.parameters['uptake_rate'] * external_A * timestep
# run tellurium here
internal_update = self.parameters['uptake_rate'] * external_A * interval
external_update = -1 * internal_update

# return an update that mirrors the ports structure
return {
# get the results from tellurium
update = {
'internal': {
'A': internal_update},
'external': {
'A': external_update}
}

# return an update that mirrors the ports structure
return update

# functions to configure and run the process
def run_template_process():
'''Run a simulation of the process.

Returns:
The simulation output.
'''

# initialize the process by passing in parameters
parameters = {}
template_process = Template(parameters)
def test_tellurium():
totaltime = 10.0

# initialize the process
config = {}
tellurium_process = TelluriumProcess(config)

# declare the initial state, mirroring the ports structure
initial_state = {
Expand All @@ -108,38 +90,26 @@ def run_template_process():
},
}

# run the simulation
sim_settings = {
'total_time': 10,
'initial_state': initial_state}
output = simulate_process(template_process, sim_settings)

return output

ports = tellurium_process.ports_schema()
print('PORTS')
print(ports)

def test_template_process():
'''Test that the process runs correctly.
# make the simulation
sim = Engine(
processes={'tellurium_process': tellurium_process},
topology={'tellurium_process': {port_id: (port_id,) for port_id in ports.keys()}},
initial_state=initial_state
)

This will be executed by pytest.
'''
output = run_template_process()
# TODO: Add assert statements to ensure correct performance.


def main():
'''Simulate the process and plot results.'''
# make an output directory to save plots
out_dir = os.path.join(PROCESS_OUT_DIR, NAME)
if not os.path.exists(out_dir):
os.makedirs(out_dir)
# run the simulation
sim.update(totaltime)

output = run_template_process()
# get the results
data = sim.emitter.get_data()

# plot the simulation output
plot_settings = {}
plot_simulation_output(output, plot_settings, out_dir)
print(pp(data))


# run module with python template/processes/template_process.py
if __name__ == '__main__':
main()
test_tellurium()

0 comments on commit d03d24e

Please sign in to comment.