Skip to content

fix: wrap p_imap result with list() to prevent TypeError#677

Open
thakoreh wants to merge 1 commit intoSALib:mainfrom
thakoreh:fix/p-tqdm-typeerror
Open

fix: wrap p_imap result with list() to prevent TypeError#677
thakoreh wants to merge 1 commit intoSALib:mainfrom
thakoreh:fix/p-tqdm-typeerror

Conversation

@thakoreh
Copy link
Copy Markdown

Summary

Fixes #676

When p_tqdm is available and multiple cores are used for parallel evaluation, p_imap returns a generator that cannot be properly consumed by _collect_results().

Change

Wrap the p_imap() call with list() in evaluate_parallel() (line 238 of src/SALib/util/problem.py).

# Before
res = p_imap(tmp_f, chunks, num_cpus=nprocs)

# After
res = list(p_imap(tmp_f, chunks, num_cpus=nprocs))

Test Plan

Added tests/test_ptqdm_fix.py with 3 tests:

  • test_evaluate_with_ptqdm_returns_consumable_results — mocks p_imap as a generator, verifies results are consumed correctly
  • test_evaluate_without_ptqdm_still_works — regression test for non-p_tqdm path
  • test_evaluate_single_core_no_ptqdm — single-core fallback

All tests pass.

Verification

$ python -m pytest tests/test_ptqdm_fix.py -v
3 passed

…evaluation

When p_tqdm is available and multiple cores are used, p_imap returns
a generator that cannot be properly consumed by _collect_results().

Fixes SALib#676
@tupui
Copy link
Copy Markdown
Member

tupui commented Apr 11, 2026

That's a first I think. Before doing anything, I think we need a AI policy. I suggest taking the one from SymPy and LLVM. What we need is some official disclosure on all PRs. Otherwise we are at risk of breaking our licensing and copyright guarantees. And of course quality.

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.

TypeError with p_tqdm available and multiple cores

2 participants