matching
matching copied to clipboard
RecursionError for `deepcopy` with 400x400 matching task
I bumped into RecursionError
in the deepcopy
reproduced by
import sys
from matching.games import StableMarriage
# fix by enlarging the size of recursionlimit
# sys.setrecursionlimit(10000)
num_x = 400
num_y = 400
x2y = {x:list(range(num_y)) for x in range(num_x)}
y2x = x2y
game = StableMarriage.create_from_dictionaries(x2y, y2x)
It cased by the deepcopy
of players
.
By setting recursionlimit
to a higher value can reduce the problem in this case with 400x400 matching task, I found. But it may be not reduced fundamentally.
Hi @james016. Thanks for raising this. That is certainly annoying but the call to copy.deepcopy()
is pretty integral to how the players get created and adjusted.
I will try to set aside some time to think about an alternative solution but, for now, I think your workaround will have to do. I don't know if I'm comfortable making global changes to the system recursion limit as part of matching
.
Sorry to disappoint and thanks again for opening this up.
I stumbled on this issue and explored a bit more about the Python recursion limit and found a StackOverflow answer giving an elegant way of wrapping the setting of recursionlimit
using with
. The article has a bunch of other interesting advice and solutions regarding deep recursion in Python too.