-
Notifications
You must be signed in to change notification settings - Fork 3
/
chemostat.py
39 lines (33 loc) · 1.05 KB
/
chemostat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from vivarium.core.process import Process
class Chemostat(Process):
defaults = {
# Map from variable names to the values (must support
# subtraction) those variables should be held at.
"targets": {},
"delay": 0,
}
name = "chemostat"
def __init__(self, parameters=None):
super().__init__(parameters)
self.seconds_to_wait = self.parameters["delay"]
def ports_schema(self):
schema = {
variable: {
"_default": target * 0,
}
for variable, target in self.parameters["targets"].items()
}
return schema
def next_update(self, timestep, state):
if self.seconds_to_wait > 0:
self.seconds_to_wait -= timestep
return {}
targets = self.parameters["targets"]
update = {
variable: {
"_value": targets[variable] - current,
"_updater": "accumulate",
}
for variable, current in state.items()
}
return update