TypeError: unhashable type: 'list' in signal control examples
Closed this issue · 1 comments
Several Python scripts within the demos_and_examples
directory are failing due to a TypeError
related to hashability. Specifically, the scripts attempt to use a list as a key in a dictionary, which is not permitted in Python as lists are mutable and thus unhashable.
Affected Files:
example_08_signal_reactive_control.py
example_08en_signal_reactive_control.py
example_11en_signal_4legged_intersection_reactive_control.py
Steps to Reproduce:
- Execute the scripts individually or through a test runner like pytest.
- Observe the
TypeError
that occurs when attempting to use a list as a dictionary key.
Expected Behavior:
The scripts should run without errors, managing signal control as designed.
Actual Behavior:
When running the scripts, they fail with the following error output:
TypeError: unhashable type: 'list'
The error is thrown in the following context for each script:
- In
example_08_signal_reactive_control.py
andexample_08en_signal_reactive_control.py
at line 37:vehicles_per_links[l.signal_group] = l.num_vehicles
- In
example_11en_signal_4legged_intersection_reactive_control.py
at line 45:vehicles_per_links = {l.signal_group: 0 for l in II.inlinks.values()}
Error Log:
For example_08_signal_reactive_control.py
:
simulation setting:
...
simulating...
time| # of vehicles| ave speed| computation time
0 s| 0 vehs| 0.0 m/s| 0.00 s
Traceback (most recent call last):
File "/path/to/example_08_signal_reactive_control.py", line 37, in <module>
vehicles_per_links[l.signal_group] = l.num_vehicles
TypeError: unhashable type: 'list'
Similar errors are observed for the other affected files.
Suggested Fix:
A review and potential redesign of the data structure used to track vehicles per link is needed. If l.signal_group
is indeed a list and meant to be used as a key, one could consider converting it to a tuple, which is hashable, provided the list's contents are also hashable. Otherwise, restructure the code to avoid using a list as a dictionary key.
Thanks! I have updated the examples.
This was caused by the recent update on traffic signal modeling.