Skip to content

Fake cupyx.scipy: copy and deepcopy of proxy objects - #97

Merged
max-models merged 1 commit into
develfrom
fake-cupyx-proxy-deepcopy
Oct 10, 2026
Merged

max-models merged 1 commit into
develfrom
fake-cupyx-proxy-deepcopy

Conversation

@max-models

Copy link
Copy Markdown
Owner

Summary

Objects of the fake cupyx.scipy (splines, interpolators, ...) are _Proxy objects that hold the fake CuPy module, so copy.deepcopy failed with TypeError: cannot pickle 'module' object. Real CuPy splines can be copied.

This shows up in struphy: Tokamak.__init__ stores copy.deepcopy(locals()), which includes the MHD equilibrium. Since struphy-hub/struphy#714 fits its splines on the active backend with xp.scipy.interpolate, the fake-CuPy tests of the two Tokamak-domain cases fail there.

_Proxy gets __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's test_equils_cupy.py passes on the fake CuPy (20 passed).

🤖 Generated with Claude Code

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>
@max-models
max-models merged commit b62b2b7 into devel Oct 10, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant