Skip to content

Commit 34156b1

Browse files
committed
update to compartment
removed the "fixed" property as it no longer fits with the definition of a compartment.
1 parent a878f10 commit 34156b1

File tree

2 files changed

+13
-28
lines changed

2 files changed

+13
-28
lines changed

ngcsimlib/_src/compartment/compartment.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from ngcsimlib._src.global_state.manager import global_state_manager as gState
33
from ngcsimlib._src.logger import warn
44
import ast
5-
from typing import TypeVar, Union, Set
5+
from typing import TypeVar, Union, Set, Callable
66
from ngcsimlib._src.operations.BaseOp import BaseOp
77
from ngcsimlib._src.context.context_manager import global_context_manager as gcm
88

@@ -19,54 +19,51 @@ class Compartment(metaclass=CompartmentMeta):
1919
the global state will no longer change (it will still exist but just
2020
nothing will access it unless the user manually goes looking for it). The
2121
compartment should be reflected in the global state immediately after it is
22-
initialized. Compartments can be flagged as fixed which means that they
23-
exist in the global state and can be used in compiled methods, but they can
24-
not be changed after creation.
22+
initialized.
2523
2624
Args
2725
initial_value: the initial value to set in the global state
2826
29-
fixed (default=False): sets the flag for if this compartment is fixed.
30-
3127
display_name (default=None): sets the display name of the compartment
3228
3329
units (default=None): sets the units of the compartment
3430
3531
plot_method (default=None): sets the plot method of the compartment,
3632
this method is to be used by the processes when monitoring this
3733
compartment to integrate with the plotting system.
34+
35+
auto_save (default=True): a flag for if the compartment should
36+
be picked up by other systems for auto saving. Not used specifically
37+
by simlib but adds a hook for future use.
3838
"""
3939
def __init__(self, initial_value: T,
40-
fixed: bool = False,
4140
display_name: str | None = None,
4241
units: str | None = None,
43-
plot_method: str | None = None):
42+
plot_method: Union[Callable, None] = None,
43+
auto_save: bool = True):
4444

4545
self._initial_value: T = initial_value
4646

4747
self.name = None
4848
self._root_target = None
4949
self._target = self._root_target
50-
self._fixed = fixed
5150

5251
self.display_name = display_name
5352
self.units = units
5453
self.plot_method = plot_method
54+
self._auto_save = auto_save
5555

5656
@property
5757
def root(self) -> str | None:
5858
return self._root_target
5959

6060
@property
61-
def targeted(self) -> bool:
62-
return not isinstance(self._target, str) or (self._target != self._root_target)
61+
def auto_save(self) -> bool:
62+
return self._auto_save
6363

6464
@property
65-
def fixed(self) -> bool:
66-
"""
67-
Returns: if this compartment is a fixed value.
68-
"""
69-
return self._fixed
65+
def targeted(self) -> bool:
66+
return not isinstance(self._target, str) or (self._target != self._root_target)
7067

7168
def _setup(self, compName, path):
7269
self.name = compName
@@ -90,9 +87,6 @@ def set(self, value: T) -> None:
9087
self._initial_value = value
9188
return
9289

93-
if self._fixed and gState.check_key(self.target):
94-
warn(f"Attempting to set {self._root_target} which is a fixed compartment. Aborting!")
95-
return
9690
if self.target != self._root_target:
9791
warn(f"Attempting to set {self.target} in {self._root_target}. Aborting!")
9892
return

ngcsimlib/_src/parser/contextTransformer.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,6 @@ def visit_Expr(self, node):
137137
if isinstance(call.func, ast.Attribute) and call.func.attr == "set":
138138
target = call.func.value
139139
target.ctx = ast.Store()
140-
if isinstance(target, ast.Subscript) and isinstance(target.value, ast.Name) and target.value.id == "ctx" and isinstance(target.slice, ast.Constant):
141-
atr = target.slice.value.split(":")[-1]
142-
val = getattr(self.obj, atr, None)
143-
if val is not None and isinstance(val, Compartment):
144-
if val.fixed:
145-
error(f"Trying to compile "
146-
f"\"{self.method.__name__}\" "
147-
f"on {self.obj.name} and fixed compartment "
148-
f"{atr} is marked as fixed but has a set call")
149140

150141
value = call.args[0]
151142
return ast.copy_location(ast.Assign(targets=[target], value=value), node)

0 commit comments

Comments
 (0)