77class Compartment :
88 """
99 Compartments in ngcsimlib are container objects for storing the stateful
10- values of components. Compartments are
11- tracked globaly and are automatically linked to components and methods
12- during compiling to allow for stateful
13- mechanics to be run without the need for the class object. Compartments
14- also provide an entry and exit point for
15- values inside of components allowing for cables to be connected for
16- sending and receiving values.
10+ values of components. Compartments are tracked globally and are
11+ automatically linked to components and methods during compiling to allow
12+ for stateful mechanics to be run without the need for the class object.
13+ Compartments also provide an entry and exit point for values inside of
14+ components allowing for cables to be connected for sending and receiving
15+ values.
1716 """
1817
1918 @classmethod
@@ -31,19 +30,18 @@ def is_compartment(cls, obj):
3130 """
3231 return hasattr (obj , "_is_compartment" )
3332
34- def __init__ (self , initial_value = None , static = False , is_input = False ):
33+ def __init__ (self , initial_value = None , static = False , is_input = False ,
34+ display_name = None , units = None ):
3535 """
3636 Builds a compartment to be used inside a component. It is important
37- to note that building compartments
38- outside of components may cause unexpected behavior as components
39- interact with their compartments during
40- construction to finish initializing them.
37+ to note that building compartments outside of components may cause
38+ unexpected behavior as components interact with their compartments
39+ during construction to finish initializing them.
4140 Args:
4241 initial_value: The initial value of the compartment. As a general
43- practice it is a good idea to
44- provide a value that is similar to the values that will
45- normally be stored here, such as an array of
46- zeros of the correct length. (default: None)
42+ practice it is a good idea to provide a value that is similar to
43+ the values that will normally be stored here, such as an array of
44+ zeros of the correct length. (default: None)
4745
4846 static: a flag to lock a compartment to be static (default: False)
4947 """
@@ -56,6 +54,8 @@ def __init__(self, initial_value=None, static=False, is_input=False):
5654 self .path = None
5755 self .is_input = is_input
5856 self ._is_destination = False
57+ self ._display_name = display_name
58+ self ._units = units
5959
6060 def _setup (self , current_component , key ):
6161 """
@@ -103,10 +103,9 @@ def __str__(self):
103103 def __lshift__ (self , other ) -> None :
104104 """
105105 Overrides the left shift operation to be used for wiring compartments
106- into one another
107- if other is not an Operation it will create an overwrite operation
108- with other as the argument,
109- otherwise it will use the provided operation
106+ into one another if other is not an Operation it will create an
107+ overwrite operation with other as the argument, otherwise it will use
108+ the provided operation
110109
111110 Args:
112111 other: Either another component or an instance of BaseOp
@@ -131,3 +130,12 @@ def is_wired(self):
131130 return True
132131
133132 return self ._is_destination
133+
134+ @property
135+ def display_name (self ):
136+ return self ._display_name if self ._display_name is not None else (
137+ self .name )
138+
139+ @property
140+ def units (self ):
141+ return self ._units if self ._units is not None else "dimensionless"
0 commit comments