Skip to content

Commit

Permalink
Merge pull request #615 from hakonanes/fix-614
Browse files Browse the repository at this point in the history
Require PyOpenCL context for HI of LazyEBSD
  • Loading branch information
hakonanes authored Feb 20, 2023
2 parents f8af0fb + c5c6f39 commit 1872830
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 251 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ jobs:
include:
- os: ubuntu-latest
python-version: 3.7
OLDEST_SUPPORTED_VERSION: true
DEPENDENCIES: dask==2021.8.1 diffsims==0.5.0 hyperspy==1.7.3 matplotlib==3.3 numba==0.55 numpy==1.19 orix==0.11.0 scikit-image==0.16.2
LABEL: -oldest
- os: ubuntu-latest
python-version: 3.10
LABEL: -minimum_requirement
steps:
- uses: actions/checkout@v3

Expand All @@ -79,14 +81,16 @@ jobs:
pip install -U -e .'[tests]'
- name: Install oldest supported version
if: ${{ matrix.OLDEST_SUPPORTED_VERSION }}
if: contains(matrix.LABEL, 'oldest')
run: |
pip install ${{ matrix.DEPENDENCIES }}
- name: Install optional dependencies
if: ${{ contains(matrix.LABEL, 'minimum_requirement') == false }}
shell: bash
run: |
pip install -e .'[all]'
pip install pyopencl
- name: Display Python, pip and package versions
run: |
Expand All @@ -105,10 +109,6 @@ jobs:
if: ${{ matrix.os == 'windows-latest' }}
uses: pyvista/setup-headless-display-action@v1

- name: Display package versions
run: |
pip list
- name: Run docstring tests
if: ${{ matrix.os == 'ubuntu-latest' }}
continue-on-error: true
Expand Down
6 changes: 3 additions & 3 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"affiliation": "Norwegian University of Science and Technology"
},
{
"name": "Zhou Xu",
"affiliation": "Monash Centre for Electron Microscopy"
"name": "Eric Prestat"
},
{
"name": "Eric Prestat"
"name": "Zhou Xu",
"affiliation": "Monash Centre for Electron Microscopy"
},
{
"name": "Magnus Nord",
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ its best to adhere to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>
List entries are sorted in descending chronological order. Contributors to each release
were listed in alphabetical order by first name until version 0.7.0.

0.8.1 (2023-02-20)
==================

Fixed
-----
- Hough indexing with PyEBSDIndex of a lazy EBSD signal requires not only PyOpenCL to be
installed, but also for PyOpenCL to be able to create a context.
(`#615 <https://github.com/pyxem/kikuchipy/pull/615>`_)
- Missing progressbars for ``EBSD`` methods ``average_neighbour_patterns()`` and
``fft_filter()`` reintroduced. (`#615 <https://github.com/pyxem/kikuchipy/pull/615>`_)

0.8.0 (2023-02-11)
==================

Expand Down
122 changes: 65 additions & 57 deletions doc/tutorials/hybrid_indexing.ipynb

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions doc/tutorials/pc_extrapolate_plane.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[########################################] | 100% Completed | 101.33 ms\n",
"[########################################] | 100% Completed | 101.19 ms\n"
"[########################################] | 100% Completed | 101.17 ms\n",
"[########################################] | 100% Completed | 101.52 ms\n"
]
}
],
Expand Down Expand Up @@ -453,14 +453,14 @@
"output_type": "stream",
"text": [
"Hough indexing with PyEBSDIndex information:\n",
" GPU: True\n",
" PyOpenCL: True\n",
" Projection center: (0.4208, 0.2182, 0.4999)\n",
" Indexing 9 pattern(s) in 1 chunk(s)\n",
"Radon Time: 0.03806788400106598\n",
"Convolution Time: 0.0031347900003311224\n",
"Peak ID Time: 0.0016060470006777905\n",
"Band Label Time: 0.040003152997087454\n",
"Total Band Find Time: 0.0828367710018938\n"
"Radon Time: 0.03481806100171525\n",
"Convolution Time: 0.004420306999236345\n",
"Peak ID Time: 0.0024418800021521747\n",
"Band Label Time: 0.04934866500116186\n",
"Total Band Find Time: 0.09106226299991249\n"
]
},
{
Expand All @@ -477,8 +477,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Band Vote Time: 0.01957559899892658\n",
" Indexing speed: 31.14729 patterns/s\n"
"Band Vote Time: 0.020639727998059243\n",
" Indexing speed: 30.69000 patterns/s\n"
]
}
],
Expand Down Expand Up @@ -511,8 +511,8 @@
" Trust region (+/-): [5. 5. 5. 0.05 0.05 0.05]\n",
" Relative tolerance: 1e-07\n",
"Refining 9 orientation(s) and projection center(s):\n",
"[########################################] | 100% Completed | 78.42 ss\n",
"Refinement speed: 0.11476 patterns/s\n"
"[########################################] | 100% Completed | 79.66 ss\n",
"Refinement speed: 0.11297 patterns/s\n"
]
}
],
Expand Down Expand Up @@ -966,8 +966,8 @@
" Trust region (+/-): [5 5 5]\n",
" Relative tolerance: 1e-07\n",
"Refining 9 orientation(s):\n",
"[########################################] | 100% Completed | 14.60 ss\n",
"Refinement speed: 0.61588 patterns/s\n"
"[########################################] | 100% Completed | 13.64 ss\n",
"Refinement speed: 0.65973 patterns/s\n"
]
}
],
Expand Down Expand Up @@ -996,11 +996,11 @@
"output_type": "stream",
"text": [
"Finding bands that are in some pattern:\n",
"[########################################] | 100% Completed | 101.56 ms\n",
"[########################################] | 100% Completed | 101.26 ms\n",
"Finding zone axes that are in some pattern:\n",
"[########################################] | 100% Completed | 102.22 ms\n",
"[########################################] | 100% Completed | 101.34 ms\n",
"Calculating detector coordinates for bands and zone axes:\n",
"[########################################] | 100% Completed | 104.01 ms\n"
"[########################################] | 100% Completed | 101.74 ms\n"
]
}
],
Expand Down Expand Up @@ -1039,8 +1039,8 @@
" Trust region (+/-): [5 5 5]\n",
" Relative tolerance: 1e-07\n",
"Refining 9 orientation(s):\n",
"[########################################] | 100% Completed | 14.23 ss\n",
"Refinement speed: 0.63225 patterns/s\n"
"[########################################] | 100% Completed | 14.40 ss\n",
"Refinement speed: 0.62480 patterns/s\n"
]
}
],
Expand Down Expand Up @@ -1069,11 +1069,11 @@
"output_type": "stream",
"text": [
"Finding bands that are in some pattern:\n",
"[########################################] | 100% Completed | 101.42 ms\n",
"[########################################] | 100% Completed | 101.55 ms\n",
"Finding zone axes that are in some pattern:\n",
"[########################################] | 100% Completed | 102.23 ms\n",
"[########################################] | 100% Completed | 101.89 ms\n",
"Calculating detector coordinates for bands and zone axes:\n",
"[########################################] | 100% Completed | 101.58 ms\n"
"[########################################] | 100% Completed | 101.80 ms\n"
]
}
],
Expand Down Expand Up @@ -1112,8 +1112,8 @@
" Trust region (+/-): [5 5 5]\n",
" Relative tolerance: 1e-07\n",
"Refining 9 orientation(s):\n",
"[########################################] | 100% Completed | 13.71 ss\n",
"Refinement speed: 0.65594 patterns/s\n"
"[########################################] | 100% Completed | 13.73 ss\n",
"Refinement speed: 0.65522 patterns/s\n"
]
}
],
Expand Down Expand Up @@ -1142,11 +1142,11 @@
"output_type": "stream",
"text": [
"Finding bands that are in some pattern:\n",
"[########################################] | 100% Completed | 101.96 ms\n",
"[########################################] | 100% Completed | 101.97 ms\n",
"Finding zone axes that are in some pattern:\n",
"[########################################] | 100% Completed | 102.18 ms\n",
"[########################################] | 100% Completed | 101.36 ms\n",
"Calculating detector coordinates for bands and zone axes:\n",
"[########################################] | 100% Completed | 103.92 ms\n"
"[########################################] | 100% Completed | 102.20 ms\n"
]
}
],
Expand Down
60 changes: 30 additions & 30 deletions doc/tutorials/pc_fit_plane.ipynb

Large diffs are not rendered by default.

64 changes: 32 additions & 32 deletions doc/tutorials/pc_orientation_dependence.ipynb

Large diffs are not rendered by default.

23 changes: 22 additions & 1 deletion kikuchipy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,47 @@
from kikuchipy.release import version as __version__


# Attempt import only once
# Attempt (and fail) import of optional dependencies only once
try:
import pyvista

_pyvista_installed = True
except ImportError: # pragma: no cover
_pyvista_installed = False

try:
import nlopt

_nlopt_installed = True
except ImportError: # pragma: no cover
_nlopt_installed = False

try:
from pyebsdindex import pcopt, ebsd_index

_pyebsdindex_installed = True
except ImportError: # pragma: no cover
_pyebsdindex_installed = False

# PyOpenCL context available for use with PyEBSDIndex? Required for
# Hough indexing of Dask arrays.
# PyOpenCL is an optional dependency of PyEBSDIndex, so it should not be
# an optional kikuchipy dependency.
try: # pragma: no cover
import pyopencl as cl

platform = cl.get_platforms()[0]
gpu = platform.get_devices(device_type=cl.device_type.GPU)
ctx = cl.Context(devices=gpu)
if ctx is None:
_pyopencl_context_available = False
else:
_pyopencl_context_available = True
except: # pragma: no cover
# Have to use bare except because PyOpenCL might raise its own
# LogicError, but we also want to catch import errors here
_pyopencl_context_available = False


def set_log_level(level: Union[int, str]): # pragma: no cover
"""Set level of kikuchipy logging messages.
Expand Down
4 changes: 2 additions & 2 deletions kikuchipy/indexing/_hough_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,11 @@ def _indexer_is_compatible_with_kikuchipy(


def _get_info_message(nav_size: int, chunksize: int, indexer: "EBSDIndexer") -> str:
from pyebsdindex import _pyopencl_installed
from kikuchipy import _pyopencl_context_available

info = (
"Hough indexing with PyEBSDIndex information:\n"
f" GPU: {_pyopencl_installed}\n"
f" PyOpenCL: {_pyopencl_context_available}\n"
" Projection center"
)

Expand Down
5 changes: 1 addition & 4 deletions kikuchipy/indexing/tests/test_merge_crystal_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,7 @@ def test_merge_crystal_maps_2d(
for v1, v2 in zip(
merged_xmap._coordinates.values(), xmaps[0]._coordinates.values()
):
if v1 is None:
assert v1 is v2
else:
np.allclose(v1, v2)
assert np.allclose(v1, v2)

assert np.allclose(merged_xmap.phase_id, desired_phase_ids)
assert np.allclose(merged_xmap.prop[scores_prop], desired_scores)
Expand Down
4 changes: 2 additions & 2 deletions kikuchipy/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"Lars Andreas Hastad Lervik",
"Ole Natlandsmyr",
"Tina Bergh",
"Zhou Xu",
"Eric Prestat",
"Zhou Xu",
"Magnus Nord",
]
license = "GPLv3+"
Expand All @@ -36,4 +36,4 @@
name = "kikuchipy"
platforms = ["Linux", "MacOS X", "Windows"]
status = "Development"
version = "0.8.0"
version = "0.8.1"
38 changes: 15 additions & 23 deletions kikuchipy/signals/ebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from scipy.ndimage import correlate, gaussian_filter
from skimage.util.dtype import dtype_range

from kikuchipy import _pyebsdindex_installed
from kikuchipy import _pyebsdindex_installed, _pyopencl_context_available
from kikuchipy.detectors import EBSDDetector
from kikuchipy.filters.fft_barnes import _fft_filter, _fft_filter_setup
from kikuchipy.filters.window import Window
Expand Down Expand Up @@ -900,7 +900,7 @@ def fft_filter(

return_lazy = lazy_output or (lazy_output is None and self._lazy)
register_pbar = show_progressbar or (
show_progressbar is not None and hs.preferences.General.show_progressbar
show_progressbar is None and hs.preferences.General.show_progressbar
)
if not return_lazy and register_pbar:
pbar = ProgressBar()
Expand Down Expand Up @@ -1066,7 +1066,7 @@ def average_neighbour_patterns(

return_lazy = lazy_output or (lazy_output is None and self._lazy)
register_pbar = show_progressbar or (
show_progressbar is not None and hs.preferences.General.show_progressbar
show_progressbar is None and hs.preferences.General.show_progressbar
)
if not return_lazy and register_pbar:
pbar = ProgressBar()
Expand Down Expand Up @@ -1661,16 +1661,12 @@ def hough_indexing(
"pip install pyebsdindex. See "
"https://kikuchipy.org/en/stable/user/installation.html for details"
)
if self._lazy:
from pyebsdindex import _pyopencl_installed

if not _pyopencl_installed: # pragma: no cover
raise ValueError(
"Hough indexing of lazy signals must use the GPU, which requires "
"pyopencl to be installed. See "
"https://documen.tician.de/pyopencl/misc.html for installation "
"instructions"
)
if self._lazy and not _pyopencl_context_available: # pragma: no cover
raise ValueError(
"Hough indexing of lazy signals must use PyOpenCL, which must be able "
"to create a context. See https://documen.tician.de/pyopencl/misc.html "
"for details"
)

am = self.axes_manager
nav_shape = am.navigation_shape[::-1]
Expand Down Expand Up @@ -1767,16 +1763,12 @@ def hough_indexing_optimize_pc(
"pip install pyebsdindex. See "
"https://kikuchipy.org/en/stable/user/installation.html for details"
)
if self._lazy:
from pyebsdindex import _pyopencl_installed

if not _pyopencl_installed: # pragma: no cover
raise ValueError(
"Hough indexing of lazy signals must use the GPU, which requires "
"pyopencl to be installed. See "
"https://documen.tician.de/pyopencl/misc.html for installation "
"instructions"
)
if self._lazy and not _pyopencl_context_available: # pragma: no cover
raise ValueError(
"Hough indexing of lazy signals must use PyOpenCL, which must be able "
"to create a context. See https://documen.tician.de/pyopencl/misc.html "
"for details"
)

pc0 = np.asarray(pc0)
if pc0.size != 3:
Expand Down
Loading

0 comments on commit 1872830

Please sign in to comment.