Skip to content

Commit 2eabe1f

Browse files
committed
Added helpers to get the model state
Removed the need to use Get/Set_compartment_batch
1 parent 8bead45 commit 2eabe1f

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

ngcsimlib/compilers/process.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@
33
from ngcsimlib.logger import warn
44
from functools import wraps
55
from ngcsimlib.utils import add_component_transition, add_transition_meta
6-
from ngcsimlib.utils import get_current_context, get_context, infer_context
6+
from ngcsimlib.utils import get_current_context, infer_context, Set_Compartment_Batch
77

88
class Process(object):
99
def __init__(self, name):
1010
self._method = None
1111
self._calls = []
1212
self.name = name
13+
self._needed_contexts = set([])
1314

1415
cc = get_current_context()
15-
print(get_current_context())
1616
if cc is not None:
1717
cc.register_process(self)
1818

1919
@staticmethod
2020
def make_process(process_spec):
21-
print(process_spec)
2221
newProcess = Process(process_spec['name'])
2322

2423
for x in process_spec['calls']:
@@ -37,19 +36,32 @@ def __rshift__(self, other):
3736

3837
def transition(self, transition_call):
3938
self._calls.append({"path": transition_call.__self__.path, "key": transition_call.resolver_key})
39+
self._needed_contexts.add(infer_context(transition_call.__self__.path))
4040
new_step = compile_component(transition_call)
4141
self._method = compose(self._method, new_step)
4242
return self
4343

44-
def execute(self, current_state, **kwargs):
44+
def execute(self, update_state=False, **kwargs):
4545
if self._method is None:
4646
warn("Attempting to execute a process with no transition steps")
4747
return
48-
return self.pure(current_state, **kwargs)
48+
state = self.pure(self.get_required_state(), **kwargs)
49+
if update_state:
50+
self.updated_modified_state(state)
51+
return state
4952

5053
def as_obj(self):
5154
return {"name": self.name, "calls": self._calls}
5255

56+
def get_required_state(self):
57+
compound_state = {}
58+
for context in self._needed_contexts:
59+
compound_state.update(context.get_current_state())
60+
return compound_state
61+
62+
@classmethod
63+
def updated_modified_state(cls, modified_state):
64+
Set_Compartment_Batch(modified_state)
5365

5466

5567
def transition(output_compartments):

ngcsimlib/context.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,8 @@ def view_guide(self, guide, skip=None):
650650
return guides
651651

652652
def get_current_state(self):
653-
for component in self.components.values():
654-
print(component.path)
655-
656-
exit()
653+
all_keys = []
654+
for comp_name in self.components.keys():
655+
all_keys.extend([key for key in Get_Compartment_Batch().keys()
656+
if self.path + "/" + comp_name in key])
657+
return Get_Compartment_Batch(all_keys)

0 commit comments

Comments
 (0)