Skip to content

task: module CLI patching methods#319

Open
jharlow-intel wants to merge 4 commits into
masterfrom
task/SAT-8469
Open

task: module CLI patching methods#319
jharlow-intel wants to merge 4 commits into
masterfrom
task/SAT-8469

Conversation

@jharlow-intel
Copy link
Copy Markdown
Contributor

@jharlow-intel jharlow-intel commented May 8, 2026

adds python -m mkl_fft patch install/uninstall/status methods, and also python -m mkl_fft with_patch
Convenience CLI functions that will make it way easier to let users have automagic mkl_fft optimizations in their workflows, such as if they want to run npbench suites but with mkl_fft optimizations.

Tested locally pretty exhaustively, everything worked pretty well. A lot of documentation is claude code and it was way too verbose. I deleted and edited a lot of it, but please take a look at it all and make sure it's correct.

If this gets merged, I'll do the same for mkl_random and mkl_umath

@jharlow-intel jharlow-intel self-assigned this May 8, 2026
Copilot AI review requested due to automatic review settings May 8, 2026 17:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a user-facing CLI for enabling/disabling mkl_fft’s NumPy FFT patch, aiming to support both persistent patching (python -m mkl_fft patch ...) and one-shot execution (python -m mkl_fft with_patch ...) alongside updated README guidance.

Changes:

  • Introduces python -m mkl_fft patch install|uninstall|status for persistent patch management via a .pth file.
  • Introduces python -m mkl_fft with_patch <command> ... intended to run a single command with temporary patching.
  • Adds README documentation and unit tests for the persistent patch helper functions.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
README.md Documents persistent patching, one-shot execution, and programmatic patch APIs.
mkl_fft/main.py Adds python -m mkl_fft ... dispatcher for patch and with_patch subcommands.
mkl_fft/patch.py Implements persistent patch install/uninstall/status via writing/removing a .pth file.
mkl_fft/with_patch.py Implements “one-shot” patch execution by spawning a subprocess with modified environment.
mkl_fft/tests/test_cli.py Adds tests for install_patch, uninstall_patch, and check_status using a mocked .pth path.

Comment thread README.md Outdated
Comment thread mkl_fft/with_patch.py Outdated
Comment thread mkl_fft/with_patch.py Outdated
Comment thread mkl_fft/patch.py Outdated
Comment thread mkl_fft/patch.py Outdated
Comment thread mkl_fft/patch.py Outdated
Comment thread mkl_fft/patch.py Outdated
Comment thread mkl_fft/__main__.py Outdated
Comment thread README.md
Comment thread mkl_fft/__main__.py
@jharlow-intel
Copy link
Copy Markdown
Contributor Author

@antonwolfy @ndgrigorian ready for review, I'll open this for the other 2 mkl packages once this gets merged.

Tried to get thorough CLI testing added to the meta.yaml, but conda seems to do something weird with the PYTHONPATH while running the tests so I had to run a lot of integration tests by hand

Comment thread mkl_fft/__main__.py

"""Command-line interface for mkl_fft."""

import sys
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should use argparse here, dpctl is a good example
https://github.com/IntelPython/dpctl/blob/master/dpctl/__main__.py

it's a bit cleaner

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agree, then it would be something like: python -m mkl_fft --patch [args]

@antonwolfy antonwolfy added this to the 2.3.0 release milestone May 20, 2026
Comment thread mkl_fft/patch.py
pth_path = get_pth_path()

if pth_path.exists():
print(f"Persistent patch already installed at {pth_path}")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I guess it would be proper to have that as a warning, rather then default trace to the console.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

agreed, that does make more sense

Comment thread mkl_fft/patch.py
Comment on lines +57 to +61
print(f"Persistent patch installed at {pth_path}")
print()
print("NumPy FFT will now use MKL-accelerated implementations in all")
print("Python sessions. To disable, run:")
print(" python -m mkl_fft patch uninstall")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I believe it should be only traced under verbose mode

Comment thread mkl_fft/tests/test_cli.py
def test_install_patch_already_installed(mock_pth_path, capsys):
"""Test installing patch when already installed."""
install_patch()
install_patch()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It should be warning raised at second installation and then we will verify that here through appropriate pytest i/f.

Comment thread mkl_fft/__main__.py

"""Command-line interface for mkl_fft."""

import sys
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agree, then it would be something like: python -m mkl_fft --patch [args]

Comment thread mkl_fft/__main__.py
print()
print("Examples:")
print(" python -m mkl_fft patch install")
print(" python -m mkl_fft with_patch python script.py")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we need the second python in the command? Is there any use case when we will run something different from python file?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It might be helpful also to support something like:
python -m mkl_fft with_patch "import numpy as np; ...; res = np.fft.fft(data); ..."

Comment thread mkl_fft/tests/test_cli.py
install_patch()

captured = capsys.readouterr()
assert "already installed" in captured.out
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we have a better way to check the patch is enabled through importing mkl_fft and checking mkl_fft.is_patched() result?

Comment thread mkl_fft/_patch_startup.py
@@ -0,0 +1,33 @@
# Copyright (c) 2017, Intel Corporation
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we use the current year for new files?

Suggested change
# Copyright (c) 2017, Intel Corporation
# Copyright (c) 2026, Intel Corporation

Comment thread mkl_fft/patch.py
print("Python sessions. To disable, run:")
print(" python -m mkl_fft patch uninstall")
except OSError as e:
print(f"Error installing patch: {e}")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would it be better to handle through raising an exception?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants