pyxem / kikuchipy

Toolbox for analysis of electron backscatter diffraction (EBSD) patterns
https://kikuchipy.org
GNU General Public License v3.0
79 stars 30 forks source link

Require PyOpenCL context for HI of LazyEBSD #615

Closed hakonanes closed 1 year ago

hakonanes commented 1 year ago

Description of the change

This PR should fix #614 by requiring PyOpenCL and a ~compatible driver~ context to be available when trying to perform Hough indexing of a Dask array with PyEBSDIndex. By doing this check early, we ensure that PyEBSDIndex can use PyOpenCL and that it will not fall back to its CPU implementation, which then calls Numba and errors.

Will make a v0.8.1 release as soon as this PR is merged.

Progress of the PR

Minimal example of the bug fix or new feature

Error message that should be raised when PyOpenCL is installed but no compatible driver is available (error message copy/pasted):

>>> import pyopencl as cl
>>> cl.get_platforms()
[]
>>> import kikuchipy as kp
>>> s = kp.data.nickel_ebsd_small()
>>> s.hough_indexing(None, None)
UserWarning("Hough indexing of lazy signals must use PyOpenCL and a compatible driver. 
    See https://documen.tician.de/pyopencl/misc.html for details")

For reviewers

hakonanes commented 1 year ago

@ericpre: I would be very greatful if you could give your opinion on whether the following fixes #614:

https://github.com/pyxem/kikuchipy/pull/615/files#diff-3bd901a3b67244c36540d9734e61606033674b7e3ee2d92761ac14d6a6937aebR45-R58

Relevant part of PyEBSDIndex' PyOpenCL context setup: https://github.com/USNavalResearchLaboratory/PyEBSDIndex/blob/main/pyebsdindex/opencl/openclparam.py#L67.

hakonanes commented 1 year ago

One way to check is to push a branch of the https://github.com/hyperspy/hyperspy-extensions-list repo on github

Thanks for the tip, the kikuchipy test suite passes in the "dev" runs when this PR's branch is used: https://github.com/hakonanes/hyperspy-extensions-list/actions/runs/4204973562/jobs/7296399979