Skip to content

Make e3PIE dispatch on the array module instead of forcing cupy - #93

Merged
ShantanuKodgirwar merged 1 commit into
mainfrom
fix-e3pie-gpu-dispatch
Aug 3, 2026
Merged

Make e3PIE dispatch on the array module instead of forcing cupy#93
ShantanuKodgirwar merged 1 commit into
mainfrom
fix-e3pie-gpu-dispatch

Conversation

@ShantanuKodgirwar

Copy link
Copy Markdown
Contributor

Third in the series building a safety net before performance work. Follows #90, #91.

The problem

e3PIE could not run at all, on either backend. Three independent causes.

1. cupy was hardcoded

initializeReconstructionParams() built the multislice transfer function like this:

ifFalse:
# ... numpy versionifTrue:
importcupyasxp# ... cupy version

So a CPU run produced a cupyH, which then met numpy arrays inside the position loop:

TypeError: Unsupported type <class 'numpy.ndarray'>

On a machine without CuPy it was an ImportError instead. Now uses
getArrayModule(self.reconstruction.probe), like every other engine.

2. betaProbe was set on the wrong object

self.params.betaProbe=0.25# set here
...
self.betaProbe# read here (e3PIE.py:172)
AttributeError: 'e3PIE' object has no attribute 'betaProbe'

Now set on the engine, matching ePIE and the rest.

3. H never moved to the GPU

H was missing from Reconstruction.possible_GPU_fields, so it stayed on the host while
everything else moved to the device.

It is built from __init__, before _checkGPU runs, so it is created on the host either way
and now travels with the rest of the state.

Verification

Each cause was reverted on its own to confirm it is actually load-bearing:

revertedCPU goldenGPU-vs-CPU
all three (i.e. main today)TypeErrorTypeError
only #3 (H not in GPU fields)TypeError
only #2 (betaProbe on params)AttributeErrorAttributeError
nothing — this PR

Adds an e3PIE multislice golden (nslice=3), the configuration the transfer function exists
for. Suite goes 30 → 32 passing.

Version

0.2.60.2.7. This publishes automatically on merge (#92).

e3PIE could not run at all. Three separate causes, each verified independently
by reverting just that part and watching the e3PIE golden fail.
1. initializeReconstructionParams() built the transfer function under a
hardcoded `if True: import cupy as xp`, with the numpy version of the same
block sitting above it behind `if False:`. On CPU that produced a cupy H
which then met numpy arrays in the position loop:
TypeError: Unsupported type <class 'numpy.ndarray'>.
Without cupy installed it was an ImportError instead. It now uses
getArrayModule(self.reconstruction.probe), like every other engine.
2. It set self.params.betaProbe / betaObject, but reconstruct() and
objectPatchUpdate() read self.betaProbe / self.betaObject:
AttributeError: 'e3PIE' object has no attribute 'betaProbe'.
Setting them on the engine matches ePIE and the rest.
3. H was not in Reconstruction.possible_GPU_fields, so it stayed on the host
when the engine moved to the GPU. With (1) and (2) fixed the CPU run passes
and the GPU run still fails; adding H fixes it.
H is built from __init__, before _checkGPU runs, so it is created on the host
either way and travels with the rest of the state.
Adds an e3PIE multislice golden (nslice=3), the configuration the transfer
function exists for.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ShantanuKodgirwar
ShantanuKodgirwar merged commit 259ac2e into mainAug 3, 2026
3 checks passed
@ShantanuKodgirwar
ShantanuKodgirwar deleted the fix-e3pie-gpu-dispatch branch August 3, 2026 11:33
Sign up for freeto 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

@ShantanuKodgirwar