-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Resolve a FIXME in mesa_signals/core.py #3481
Copy link
Copy link
Closed
Description
I propose a 1-line fix to resolve this fixme
mesa/mesa/experimental/mesa_signals/core.py
Lines 69 to 74 in 4af8e24
| # fixme this makes signaling list part of computed | |
| if CURRENT_COMPUTED is not None: | |
| # there is a computed dependent on this Observable, so let's add | |
| # this Observable as a parent | |
| CURRENT_COMPUTED._add_parent(instance, self.public_name, value) | |
Currently, mutable lists(such as SignalingList) fail the current_val != old_val cache-invalidation check
mesa/mesa/experimental/mesa_signals/core.py
Lines 225 to 229 in 4af8e24
| for attr, old_val in observations.items(): | |
| current_val = getattr(parent, attr) | |
| if current_val != old_val: | |
| changed = True | |
| break |
because they compare the exact same memory address against itself. By explicitly passing None into the dependency graph for mutable sequences, we can fix this
def __get__(self, instance: HasEmitters, owner):
value = getattr(instance, self.private_name)
if CURRENT_COMPUTED is not None:
# Do not store mutable sequences in the computed graph.
value = value if not isinstance(value, MutableSequence) else None
...Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels