Skip to content

Commit 102dd70

Browse files
committed
states: Don't require a name
simplifies the API
1 parent badc3a3 commit 102dd70

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

mesa/experimental/states.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
class State:
2323
"""Base class for all states."""
2424

25-
def __init__(self, name: str, initial_value: Any):
25+
def __init__(self, initial_value: Any):
2626
"""Create a new state."""
27-
self.name = name
2827
self._value = initial_value
2928
self._last_update_time = 0
3029
self.model = None # Set when state is added to agent
@@ -61,12 +60,11 @@ class ContinuousState(State):
6160

6261
def __init__(
6362
self,
64-
name: str,
6563
initial_value: float,
6664
rate_function: Callable[[float, float], float],
6765
):
6866
"""Create a new continuous state."""
69-
super().__init__(name, initial_value)
67+
super().__init__(initial_value)
7068
self.rate_function = rate_function
7169

7270
@property
@@ -89,14 +87,13 @@ class CompositeState(State):
8987

9088
def __init__(
9189
self,
92-
name: str,
9390
dependent_states: list[State],
9491
computation_function: Callable[..., Any],
9592
):
9693
"""Create a new composite state."""
9794
self.dependent_states = dependent_states
9895
self.computation_function = computation_function
99-
super().__init__(name, None) # Value computed on first access
96+
super().__init__(None) # Value computed on first access
10097

10198
@property
10299
def value(self) -> Any:
@@ -144,11 +141,6 @@ def __setattr__(self, name: str, value: Any) -> None:
144141
states = object.__getattribute__(self, "states")
145142
# If setting a State object, add or update the states dictionary
146143
if isinstance(value, State):
147-
# The state's name should match the attribute name
148-
if value.name != name:
149-
raise ValueError(
150-
f"State name '{value.name}' does not match attribute name '{name}'"
151-
)
152144
states[name] = value
153145
value.model = self.model
154146
else:

0 commit comments

Comments
 (0)