Skip to content

MKL build updates - #28

Merged
jcapriot merged 17 commits into
simpeg:mainfrom
jcapriot:mkl_build_updates
Sep 8, 2026
Merged

jcapriot merged 17 commits into
simpeg:mainfrom
jcapriot:mkl_build_updates

Conversation

@jcapriot

@jcapriot jcapriot commented Sep 7, 2026

Copy link
Copy Markdown
Member

Accomplishes a few things,

  1. Bumps minimum to Python 3.12
  2. Makes the build and run requirements a bit more precise.
  3. Moves conda-build tests to MKL 2025 and 2026 (still 2023 for intel MacOS)
  4. Adds support for building (and running) against Intel's MKL distributions on pypi.

This commit enables `pydiso` to be built and installed successfully against Intel MKL
packages sourced directly from PyPI. Previously, building with PyPI-distributed MKL
was challenging due to difficulties in locating build components and runtime libraries.

Key changes address these issues:
*   **Build system (Meson):** Automatically configures `pkg_config_path` to locate
    `mkl-devel` and `mkl-include` files when installed by pip.
*   **Runtime linking:** Implements platform-specific fixes to ensure the compiled
    extension can find MKL shared libraries on Windows (via `add_dll_directory`)
    and Linux/macOS (via `RPATH`).
*   **CI updates:** Introduces dedicated CI jobs to validate the PyPI MKL build and
    test path, alongside existing conda-based tests.
*   **Dependencies:** Adds `mkl`, `mkl-devel`, `mkl-include`, and `pkgconf` to
    `pyproject.toml`, allowing pip to resolve these MKL components.
*   **Documentation:** Updates `README.md` to provide clear instructions for building
    against PyPI MKL.

These changes significantly broaden `pydiso`'s accessibility for users who prefer
installing with pip in standard virtual environments.
Moves the `os.add_dll_directory` logic for MKL runtime libraries into a
dedicated `_init_helper.py` module, mirroring the approach used by
`mkl-service`. This ensures reliable discovery of MKL DLLs in standard
Python virtual environments on Windows (e.g., `venv`, `virtualenv`) while
avoiding conflicts with conda environments.

Adds pytest configuration to use `--import-mode=importlib`. This prevents
pytest from shadowing the installed `pydiso` package with the source tree,
ensuring tests accurately validate the compiled extensions and MKL runtime
path resolution.
@codecov

codecov Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 35.41667% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.46%. Comparing base (51dc35c) to head (7313407).

Files with missing lines Patch % Lines
pydiso/_init_helper.py 32.60% 30 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #28      +/-   ##
==========================================
- Coverage   89.66%   85.46%   -4.21%     
==========================================
  Files           3        4       +1     
  Lines         571      619      +48     
  Branches       69       78       +9     
==========================================
+ Hits          512      529      +17     
- Misses         32       62      +30     
- Partials       27       28       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The previous `pkg_config_path` heuristic, based on `sysconfig.get_path("data")`, was unreliable for `mkl-devel` packages installed by pip, particularly in isolated build environments. `sysconfig` reflects the build interpreter's prefix, not the actual installation path of `mkl-devel`'s pkg-config files, which might be in an overlaid directory.

This update uses `importlib.metadata` to query the `mkl-devel` package directly for the location of its `.pc` files, ensuring accurate discovery irrespective of the build environment's specifics.
Meson's default CMake search heuristics fail to find `MKLConfig.cmake`
from pip-installed `mkl-devel` in certain virtual environments,
especially on Windows. This change explicitly configures `cmake_prefix_path`
using `importlib.metadata` to guarantee correct MKL location.

Additionally, the `mkl-devel` PyPI wheel for macOS (frozen at 2023.2)
is missing a symlink needed by CMake, causing MKL import failures.
macOS builds are now excluded from CI, with documentation clarifying
the issue and recommending conda-forge for macOS users.
… DLL discovery

Introduce `mkl-link` as a new build option, enabling static or per-component dynamic MKL linking. Static linking allows for building a fully self-contained extension, removing the runtime `mkl` dependency when using sequential threading.

Enhance Windows MKL DLL discovery to prioritize `MKLROOT` and package metadata, ensuring robustness across various MKL installation methods (e.g., oneAPI toolkit, pip/conda `mkl` package).
with:
verbose: true # optional (default = false)
token: ${{ secrets.CODECOV_TOKEN }} # required
- uses: actions/checkout@v5

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor tip, since it fits the context of GitHub Actions: it might be good to update versions of different actions to remove the warnings about Node.js 20 deprecation. E.g., actions/checkout@v4 -> actions/checkout@v5 or v6

@jcapriot
jcapriot merged commit 25df640 into simpeg:main Sep 8, 2026
28 of 30 checks passed
@jcapriot
jcapriot deleted the mkl_build_updates branch September 8, 2026 23:34
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.

2 participants