Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ authors:
family-names: Wieske
affiliation: 'Biopsychology and Neuroergonomics, Technische Universität Berlin, Berlin, Germany'
orcid: 'https://orcid.org/0009-0006-2018-1074'
- given-names: Kanav
family-names: Dhanda
affiliation: 'Department of Computer Science, Thapar Institute of Engineering and Technology'
type: software
repository-code: 'https://github.com/sappelhoff/pyprep'
license: MIT
Expand Down
61 changes: 61 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,76 @@ all required dependencies automatically.
The dependencies are defined in the ``pyproject.toml`` file under the
``dependencies`` and ``project.optional-dependencies`` sections.

GPU Acceleration
================

``pyprep`` includes optional PyTorch-based acceleration for validated
bad-channel deviation and correlation assessments. Install the optional dependency with
``pip``:

.. code-block:: bash

python -m pip install "pyprep[gpu]"

The regular ``python -m pip install pyprep`` installation remains sufficient
for CPU preprocessing. The default ``backend="cpu"`` preserves PyPREP's
established NumPy/SciPy numerical behavior. With the GPU extra, pass
``backend="auto", device="auto"`` to select CUDA, Apple Silicon MPS, Intel XPU,
Habana HPU, or CPU in that order. Unsupported operations automatically rerun
with the CPU implementation:

.. code-block:: python

import mne
from pyprep.prep_pipeline import PrepPipeline

raw = mne.io.read_raw_edf("sample.edf", preload=True)
montage = mne.channels.make_standard_montage("standard_1005")
raw.set_montage(montage)

prep_params = {
"ref_chs": "eeg",
"reref_chs": "eeg",
"line_freqs": [],
}
prep = PrepPipeline(raw, prep_params, montage, backend="auto", device="auto")
prep.fit()

To pin a supported device explicitly, use one of
``device="cuda"`` (NVIDIA CUDA or AMD ROCm builds of PyTorch), ``"mps"``
(Apple Silicon), ``"xpu"`` (Intel), ``"hpu"`` (Habana), or ``"cpu"``.
``torch.device`` objects are accepted as well. For example:

.. code-block:: python

prep = PrepPipeline(raw, prep_params, montage, backend="auto", device="cuda")

Use ``backend="cpu"`` to force the established NumPy/SciPy implementation.
This is the setting for strict numerical reproducibility with prior PyPREP
releases. Optional accelerator results are regression-tested against the CPU
implementation, but floating-point values can differ across hardware; do not
use an accelerator when bit-for-bit reproducibility is required.

Contributing
============


The development of ``pyprep`` is taking place on
`GitHub <https://github.com/sappelhoff/pyprep>`_.

For more information, please see
`CONTRIBUTING.md <https://github.com/sappelhoff/pyprep/blob/main/.github/CONTRIBUTING.md>`_.

Before submitting a change, the local checks used by this repository can be run
with:

.. code-block:: bash

python -m pip install -e ".[test,docs,gpu]"
pre-commit run --all-files
pytest
make -C docs html

Citing
======

Expand Down
1 change: 1 addition & 0 deletions docs/authors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.. _Ayush Agarwal: https://github.com/Ayush-Devs
.. _Christian O'Reilly: https://github.com/christian-oreilly
.. _Jonte Dancker: https://github.com/joDancker/
.. _Kanav Dhanda: https://github.com/kanavdhanda
.. _Mathieu Scheltienne: https://github.com/mscheltienne
.. _Nabil Alibou: https://github.com/nabilalibou
.. _Ole Bialas: https://github.com/OleBialas
Expand Down
7 changes: 6 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ Version 0.8.0 (unreleased)

Changelog
~~~~~~~~~
- Nothing yet
- Added an optional, compatibility-first PyTorch acceleration backend
(:mod:`pyprep.gpu`) for validated multi-channel windowed correlation and
deviation metrics. ``backend="cpu"`` remains the default; ``backend="auto"``
selects CUDA, Apple Silicon MPS, Google TPU (torch_xla), Intel XPU, Habana HPU, then CPU and retries
unsupported operations with the original CPU implementation, by `Kanav Dhanda`_


.. _changes_0_7_1:

Expand Down
7 changes: 7 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# Suppress known Sphinx-Gallery cross-reference warning for sg_execution_times.
# This occurs because sg_execution_times.rst is generated before gallery labels
# are resolved, and is a known upstream sphinx-gallery issue.
suppress_warnings = [
"ref.ref", # sg_execution_times.rst: gallery label not yet resolved
]

# HTML options (e.g., theme)
# see: https://sphinx-bootstrap-theme.readthedocs.io/en/latest/README.html
# Clean up sidebar: Do not show "Source" link
Expand Down
13 changes: 12 additions & 1 deletion examples/run_full_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,25 @@
# https://numpy.org/doc/stable/reference/random/index.html
random_state = 466171092

# ``backend="auto", device="auto"`` selects the fastest available accelerator
# (CUDA, Apple Silicon MPS, Intel XPU, Habana HPU, or CPU). Unsupported
# accelerator operations rerun with PyPREP's standard NumPy/SciPy implementation.

sfreq = raw.info["sfreq"]
prep_params = {
"ref_chs": "eeg",
"reref_chs": "eeg",
"line_freqs": np.arange(60, sfreq / 2, 60),
}

prep = PrepPipeline(raw, prep_params, montage, random_state=random_state)
prep = PrepPipeline(
raw,
prep_params,
montage,
random_state=random_state,
backend="auto",
device="auto",
)
prep.fit()

###############################################################################
Expand Down
10 changes: 8 additions & 2 deletions pyprep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@
from pyprep.prep_pipeline import PrepPipeline # noqa: F401
from pyprep.reference import Reference # noqa: F401

# Lazy import helper for optional pyprep.gpu module
try:
import pyprep.gpu as gpu # noqa: F401
except Exception: # pragma: no cover
gpu = None # pragma: no cover

try:
from importlib.metadata import version

__version__ = version("pyprep")
except Exception:
__version__ = "0.0.0"
except Exception: # pragma: no cover
__version__ = "0.0.0" # pragma: no cover
Loading
Loading