Skip to content

Commit 1a75606

Browse files
committed
cleanup
added the ability to check if a process is compiled. added plot method to compartment for future use
1 parent c12d2b9 commit 1a75606

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

ngcsimlib/_src/compartment/compartment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Compartment(metaclass=CompartmentMeta):
2828
fixed (default=False): sets the flag for if this compartment is fixed.
2929
"""
3030
def __init__(self, initial_value: T, fixed: bool = False,
31-
display_name=None, units=None):
31+
display_name=None, units=None, plot_method=None):
3232
self._initial_value = initial_value
3333

3434
self.name = None
@@ -38,6 +38,7 @@ def __init__(self, initial_value: T, fixed: bool = False,
3838

3939
self.display_name = display_name
4040
self.units = units
41+
self.plot_method = plot_method
4142

4243
@property
4344
def root(self):

ngcsimlib/_src/context/contextAwareObjectMeta.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ def __call__(cls, *args, **kwargs):
5050
error(f"Created context objects must have a name. "
5151
f"Error occurred when making an object of class {cls.__name__}")
5252

53-
# if contextRef is None:
54-
# warn(f"An instance of a context aware object was initialized while "
55-
# f"the current context is None. Did you forget to place it in "
56-
# f"a \"with\" block?")
57-
# return obj
58-
59-
6053
if hasattr(obj, "compartments") and isinstance(obj.compartments, Iterable) and not isinstance(obj.compartments, (str, bytes)):
6154
for (comp_name, comp) in obj.compartments:
6255
if hasattr(comp, "_setup") and callable(comp._setup):

ngcsimlib/_src/global_state/manager.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
from typing import Union, Any, Dict
1+
from typing import Union, Any, Dict, TYPE_CHECKING
2+
3+
if TYPE_CHECKING:
4+
from ngcsimlib._src.compartment.compartment import Compartment
25

36

47
class __global_state_manager:
58
def __init__(self):
6-
self.__state = {}
7-
self.__compartments = {}
9+
self.__state: Dict[str, any] = {}
10+
self.__compartments: Dict[str: "Compartment"] = {}
811

9-
def add_compartment(self, compartment):
12+
def add_compartment(self, compartment: "Compartment"):
1013
self.__compartments[compartment.root] = compartment
1114

12-
def get_compartment(self, root):
15+
def get_compartment(self, root: str) -> "Compartment":
1316
return self.__compartments[root]
1417

1518
@staticmethod

ngcsimlib/_src/process/baseProcess.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def __init__(self, name):
2121
self._keyword_order: List[str] = []
2222
self._watch_list: List[Compartment] = []
2323

24+
@property
25+
def watch_list(self):
26+
return self._watch_list
27+
2428
def view_compiled_method(self) -> str:
2529
"""
2630
Returns: The compiled method as a human-readable code block to assist
@@ -101,6 +105,9 @@ def pack_rows(self, length: int,
101105
seed_generator = lambda x: x
102106
return [self.pack_keywords(seed_generator(i), **kwargs) for i in range(length)]
103107

108+
def is_compiled(self) -> bool:
109+
return hasattr(self.run, "compiled")
110+
104111
def run(self, state=None, keywords=None, update=True, row_seed=None, **kwargs):
105112
"""
106113
Runs the compiled process.
@@ -122,7 +129,7 @@ def run(self, state=None, keywords=None, update=True, row_seed=None, **kwargs):
122129
Returns: The final state, watched values as a tuple
123130
124131
"""
125-
if hasattr(self.run, "compiled"):
132+
if self.is_compiled():
126133
if state is None:
127134
state = global_state_manager.state
128135
if keywords is None:

0 commit comments

Comments
 (0)