Open
Conversation
…ethod The default recursive copy.deepcopy can exceed the interpreter's recursion limit on large networks because the object graph (World - Node - Link - Vehicle chains) is very deep. The __deepcopy__ method temporarily raises sys.setrecursionlimit proportional to the number of simulation objects before performing the standard deepcopy logic. Closes #358 Co-authored-by: toruseo <34780089+toruseo@users.noreply.github.com>
Co-authored-by: toruseo <34780089+toruseo@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix failure of run-notebook-demos-extra test due to recursion error
Fix deepcopy RecursionError on World objects
Aug 28, 2026
toruseo
marked this pull request as ready for review
August 28, 2026 07:21
Refactor deepcopy method for World objects to include a safety cap on recursion limit and provide warnings for potential RecursionErrors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
run-notebook-demos-extraCI test fails withRecursionError: maximum recursion depth exceededwhendemo_notebook_03en_pytorchcallscopy.deepcopy(env.W)to save the best World state during RL training. The deeply nested object graph (World ↔ Node ↔ Link ↔ Vehicle chains) exceeds Python's default recursion limit of 1000 during recursivedeepcopytraversal. The failure started from a dependency version bump (not a code change) that pushed the required depth past the limit.World.__deepcopy__that temporarily raisessys.setrecursionlimitproportional to the number of simulation objects before delegating to standard deepcopy logic, restoring the original limit infinally