CPJKU / partitura

A python package for handling modern staff notation of music
https://partitura.readthedocs.io
Apache License 2.0
228 stars 15 forks source link

Issue when deepcopying a score #304

Closed manoskary closed 11 months ago

manoskary commented 1 year ago

This problem occurs when copy.deepcopy(score) is called. The issue results in a system error:

SystemError: <built-in method __deepcopy__ of numpy.ndarray object at 0x7f23580174b0> returned a result with an error set

To reproduce:

use this score : here and call copy.deepcopy(score).

sildater commented 12 months ago

I don't really know where to start with this. I can reproduce the error and I also get for all randomly picked files from this repo, but not for other kern files. My guess is that either the parsing goes wrong for these files or there's a bug with numpy.

manoskary commented 12 months ago

I will take a closer look at these files today once again and try to pinpoint which elements are causing this cloning error.

manoskary commented 12 months ago

What I found is that the part structure is too deep and that is causing the recursion error, it can be fixed when the recursion limit is increased, like so : sys.setrecursionlimit(10000)

This is probably caused when the TimedObjects keep calling ending and starting objects on the timeline. Since any time objects can have many starting and ending objects which themselves will have other starting and ending objects then copy tries to pickle all these objects one by one but reaches a max recursion which could potentially be up to the number of TimedObjects in the score and therefore it fails. This is my best guess.

A potential fix is before calling copy to count the number of TimedObjects and set the recursion limit to that number. (update that did not work maybe some multiple could work better)