Skip to content

fix + feat: resolve 10 stale issues in a single PR - #32

Merged
saudzahirr merged 5 commits into
masterfrom
fix-and-features
May 19, 2026
Merged

fix + feat: resolve 10 stale issues in a single PR#32
saudzahirr merged 5 commits into
masterfrom
fix-and-features

Conversation

@saudzahirr

Copy link
Copy Markdown
Collaborator

Summary

This PR addresses the concrete, solvable problems from the backlog of closed stale issues and PRs. Each commit is self-contained and references the original issue(s) it closes.

Commit Fixes What
1c93b1e #20, #22 Gate all stopping messages on debug; add patience param for plateau early-stop
d221828 #5, #6 SciPy-style bounds parameter (backwards-compatible)
1943564 #12, #16 Custom pool parameter; fix resource leak (pool was never closed)
c048faa #21 init parameter for warm-start / fixed initial positions
50a9a42 #14, #17 intvar parameter for mixed-integer PSO

Decisions / trade-offs

Test plan

  • All 10 tests pass (uv run pytest tests/ -v)
  • Ruff lint clean (uv run ruff check pyswarm/pso.py)
  • Each new feature has at least one dedicated test
  • Existing twobar-truss seed=0 regression test still passes

🤖 Generated with Claude Code

saudzahirr and others added 5 commits May 19, 2026 23:36
…gence

All stopping-search print statements now respect the debug flag so that
debug=False (the default) produces no output at all (closes #20).

A new patience parameter (default 0, meaning disabled) counts consecutive
iterations without improvement and stops the search when that count reaches
patience. This lets callers avoid needless iterations when the swarm has
converged to an exact optimum where fp[i_min] == fg indefinitely (closes #22).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Accept bounds as a list of (lo, hi) pairs in addition to the existing
separate lb and ub arrays, matching the convention used by scipy.optimize.
When bounds is provided it takes precedence; lb and ub may be omitted.
Fully backwards-compatible — existing callers using lb/ub are unaffected.

Closes #5, closes #6.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Callers can now pass any object with a map() method (multiprocessing.Pool,
ipyparallel, dask, etc.) via the pool keyword argument. When pool is given,
processes is ignored and the caller manages the pool lifecycle.

When the library creates its own pool (processes > 1, pool=None) it now
correctly terminates and joins it via try/finally, fixing the silent resource
leak in the original implementation where the pool was never closed.

Closes #12, closes #16.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Users can now seed the swarm with known good starting points by passing an
(swarmsize × ndim) array via the init keyword argument. This is useful for
warm-starting from a previous run or for incorporating domain knowledge about
where good solutions are likely to lie. Out-of-bounds values are silently
clipped to [lb, ub].

Closes #21.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Pass a list of dimension indices via intvar to constrain those variables to
integer values. After each position update (and on initial placement) the
selected dimensions are rounded to the nearest integer and clipped to
[lb, ub]. This enables mixed-integer PSO without changing the continuous
variables.

Closes #14, closes #17.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@saudzahirr
saudzahirr merged commit 8fd2964 into master May 19, 2026
17 checks passed
@saudzahirr
saudzahirr deleted the fix-and-features branch May 19, 2026 18:50
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 36 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pyswarm/pso.py 87.50% 12 Missing ⚠️
tests/test_convergence.py 76.00% 6 Missing ⚠️
tests/test_init.py 77.77% 6 Missing ⚠️
tests/test_bounds.py 76.47% 4 Missing ⚠️
tests/test_intvar.py 71.42% 4 Missing ⚠️
tests/test_pool.py 78.94% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

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