Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pickling error. #2100

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Copy and pasting the git commit messages is __NOT__ enough.
### Deprecated
### Fixed
- Fixed issue where `SumoTrafficSimulation` could get locked up on reset if a scenario had only 1 map but multiple scenario variations.
- Fixed an issue where an out-of-scope method reference caused a pickling error.
### Removed
### Security

Expand Down
9 changes: 5 additions & 4 deletions envision/client_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class SingleAttributeOverride(NamedTuple):
"""The maximum number of elements an iterable attribute can contain."""


def _default_override():
return SingleAttributeOverride(True, None)


@dataclass(frozen=True)
class EnvisionStateFilter:
"""A state filtering tool."""
Expand All @@ -49,7 +53,4 @@ class EnvisionStateFilter:
def default(cls):
"""Give a new default filter."""

def default_override():
return SingleAttributeOverride(True, None)

return cls(defaultdict(default_override), defaultdict(default_override))
Comment on lines -52 to -55
Copy link
Collaborator Author

@Gamenot Gamenot Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core of this is that locally defined method like this becomes an out of scope reference when the standard Python pickler attempts to deserialize it so the standard pickler just does not allow the serialization in the first place.

return cls(defaultdict(_default_override), defaultdict(_default_override))
8 changes: 5 additions & 3 deletions envision/tests/test_data_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@
TIMESTEP_SEC = 0.1


class KeepLaneAgent(Agent):
def act(self, obs):
return "keep_lane"


@pytest.fixture
def agent_spec():
class KeepLaneAgent(Agent):
def act(self, obs):
return "keep_lane"

return AgentSpec(
interface=AgentInterface.from_type(
Expand Down
Loading