Repository navigation
Fake cupyx.scipy: copy and deepcopy of proxy objects - #97
Merged
Merged
Conversation
Splines of the fake cupyx.scipy are proxies that hold the fake CuPy module, so copy.deepcopy (e.g. of an object that stores its constructor arguments) failed with "cannot pickle 'module' object", while real CuPy splines can be copied. Copies now wrap a copy of the SciPy object and share the fake CuPy module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Objects of the fake
cupyx.scipy(splines, interpolators, ...) are_Proxyobjects that hold the fake CuPy module, socopy.deepcopyfailed withTypeError: cannot pickle 'module' object. Real CuPy splines can be copied.This shows up in struphy:
Tokamak.__init__storescopy.deepcopy(locals()), which includes the MHD equilibrium. Since struphy-hub/struphy#714 fits its splines on the active backend withxp.scipy.interpolate, the fake-CuPy tests of the two Tokamak-domain cases fail there._Proxygets__copy__and__deepcopy__: the copy wraps a (deep) copy of the SciPy object and shares the fake CuPy module.Tests
New
test_splines_can_be_copied:copy.copy,copy.deepcopy, and a deep copy inside a dict give device-evaluating splines equal to the original, and a deep copy is independent of the original.tests/unit/test_fake_cupyx.py: 9 passed. With this patch, struphy'stest_equils_cupy.pypasses on the fake CuPy (20 passed).🤖 Generated with Claude Code