22from ngcsimlib ._src .global_state .manager import global_state_manager as gState
33from ngcsimlib ._src .logger import warn
44import ast
5- from typing import TypeVar , Union , Set
5+ from typing import TypeVar , Union , Set , Callable
66from ngcsimlib ._src .operations .BaseOp import BaseOp
77from 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
0 commit comments