Skip to content

Add pjit#109

Open
mschwoer wants to merge 5 commits intomainfrom
add_pjit
Open

Add pjit#109
mschwoer wants to merge 5 commits intomainfrom
add_pjit

Conversation

@mschwoer
Copy link
Copy Markdown
Contributor

@mschwoer mschwoer commented Jan 28, 2026

add pjit and threadpool code from alphatims b18e1553f

Adressed only basic linting, noqaed the rest.

Note: chose to put it here as the TimsTOF class that will also moved here from alphatims depends on it and because alphabase felt not like the right place.

@mschwoer mschwoer requested review from GeorgWa and Copilot January 28, 2026 14:05
Copy link
Copy Markdown

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

This PR adds parallel processing utilities (pjit and threadpool) ported from the AlphaTims library, enabling efficient multi-threaded execution of functions with progress tracking support. The implementation includes utilities for thread management, conditional Numba JIT compilation, and progress callbacks.

Changes:

  • Added alpharaw/utils/pjit.py with thread pool decorators and Numba-based parallelization utilities
  • Removed deprecated type annotation rules from the ruff configuration
  • Fixed a typo in the ruff ignore rule identifier (TCH003TC003)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
alpharaw/utils/pjit.py New module providing pjit and threadpool decorators for parallelizing functions with thread pools and progress callbacks
ruff-lint-strict.toml Removed deprecated ANN101/ANN102 rules and corrected typo in TC003 rule identifier

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Default is True.
return_results : bool
If True, it returns the results in the same order as the iterable.
This can be much slower than not returning results. Iti is better to
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

Corrected spelling of 'Iti' to 'It'.

Suggested change
This can be much slower than not returning results. Iti is better to
This can be much slower than not returning results. It is better to

Copilot uses AI. Check for mistakes.
If True, it returns the results in the same order as the iterable.
This can be much slower than not returning results. Iti is better to
store them in a buffer results array instead
(be carefull to avoid race conditions).
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

Corrected spelling of 'carefull' to 'careful'.

Suggested change
(be carefull to avoid race conditions).
(be careful to avoid race conditions).

Copilot uses AI. Check for mistakes.
def wrapper(iterable, *args) -> None: # noqa: ANN001
"""A wrapper function that parallelizes the numba.njit function.

The first argument of the wrapped function is seperately stored as `iterable` and its elements are
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

Corrected spelling of 'seperately' to 'separately'.

Suggested change
The first argument of the wrapped function is seperately stored as `iterable` and its elements are
The first argument of the wrapped function is separately stored as `iterable` and its elements are

Copilot uses AI. Check for mistakes.
Comment on lines +111 to +117
results = []
for result in _progress_callback(
pool.imap(starfunc, iterable),
total=len(iterable),
include_progress_callback=include_progress_callback,
):
results.append(result) # noqa: PERF402
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The # noqa: PERF402 comment suppresses a performance warning about using append in a loop. Consider using a list comprehension instead: results = list(_progress_callback(...)) to improve performance.

Suggested change
results = []
for result in _progress_callback(
pool.imap(starfunc, iterable),
total=len(iterable),
include_progress_callback=include_progress_callback,
):
results.append(result) # noqa: PERF402
results = list(
_progress_callback(
pool.imap(starfunc, iterable),
total=len(iterable),
include_progress_callback=include_progress_callback,
)
)

Copilot uses AI. Check for mistakes.
while progress_bar >= progress_count:
time.sleep(0.01) # this will be done by the main thread
progress_count = granularity * np.sum(progress_counter) / len(iterable)
progress_bar += 1 # noqa: SIM113
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The # noqa: SIM113 comments suppress warnings about using += instead of the increment operator. These suppressions appear unnecessary since += is the preferred Python idiom. Consider removing these noqa comments.

Suggested change
progress_bar += 1 # noqa: SIM113
progress_bar += 1

Copilot uses AI. Check for mistakes.
steps = current_progress_callback.max / 1000
progress = 0
for element in iterable:
progress += 1 # noqa: SIM113
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The # noqa: SIM113 comments suppress warnings about using += instead of the increment operator. These suppressions appear unnecessary since += is the preferred Python idiom. Consider removing these noqa comments.

Suggested change
progress += 1 # noqa: SIM113
progress += 1

Copilot uses AI. Check for mistakes.
@mschwoer mschwoer requested a review from jalew188 March 6, 2026 10:52
Copy link
Copy Markdown
Collaborator

@GeorgWa GeorgWa left a comment

Choose a reason for hiding this comment

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

I did not review this in detail. Why did alphabase not feel like the right place for this?
I think this is fine but alphabase would be equally fine for me.

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.

3 participants