Skip to content

Implementation of Fortran API for PSO#34

Merged
saudzahirr merged 4 commits into
masterfrom
f77-api
May 24, 2026
Merged

Implementation of Fortran API for PSO#34
saudzahirr merged 4 commits into
masterfrom
f77-api

Conversation

@saudzahirr

Copy link
Copy Markdown
Collaborator

No description provided.

…thon

- Add src/pso.f: ONE Fortran 77 subroutine PSO that performs a complete
  PSO iteration step (personal-best update, global-best update, velocity
  update, position update + clamping, integer rounding)
- Add src/_pyswarm.pyf: f2py interface with intent(hide) dimension args
  giving clean Python call signature with no exposed size arguments
- Add src/meson.build: builds _pyswarm extension module via f2py/meson,
  installs into pyswarm/ package directory (subdir: 'pyswarm')
- Add meson.build: root meson project (fortran+c), version from setuptools_scm
- Add pyswarm/meson.build: installs pure-Python package sources
- Replace pyproject.toml build-system: hatchling → meson-python +
  setuptools_scm; add [tool.cibuildwheel] and [tool.setuptools_scm]
- Delete pyswarm/pso.py: no separate PSO Python module needed
- Rewrite pyswarm/__init__.py: scipy.optimize-style OptimizeResult,
  pso() wrapper drives outer loop + obj evaluation, delegates every PSO
  math step to the single Fortran kernel (_pso_step)
- Update all tests: import from pyswarm (not pyswarm.pso), use
  result.x / result.fun instead of tuple unpacking
- Add bin/build.py, bin/get_version.py (from f2py-tpl reference)
- Update .github/workflows/dist_build.yml: cibuildwheel multi-platform
  wheel builds (Linux x86_64, macOS arm64, Windows AMD64)
- Update .gitignore: add meson build artefact patterns

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@saudzahirr saudzahirr self-assigned this May 22, 2026
@saudzahirr saudzahirr force-pushed the f77-api branch 4 times, most recently from f00313c to b604458 Compare May 22, 2026 12:57
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tests/test_pool.py 85.71% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@saudzahirr saudzahirr force-pushed the f77-api branch 2 times, most recently from 7a516a3 to 5516f16 Compare May 22, 2026 13:06
- src/pso.f: rewrite as ONE complete Fortran 77 subroutine that runs
  the entire PSO algorithm (init, MAXITER loop, convergence checks).
  Uses an f2py EXTERNAL callback EVAL that Fortran calls per particle —
  zero Python loops in pso(); feasibility encoded as return >= 1.0D300.
  All dummy arrays use adjustable dimensions (valid F77), workspace
  arrays FX and XTMP are hidden dummy args allocated by f2py.

- src/_pyswarm.pyf: add __user__routines module for callback signature;
  MAXITER/NSWARM/NDIM/NIVAR hidden via intent(hide)+depend; FX/XTMP
  hidden workspace; X/V intent(in,out); G/FG/P/FP/NITERS/STATUS out.

- pyswarm/__init__.py: remove the while-loop entirely; Python only
  validates inputs, builds _eval closure (obj + feasibility sentinel),
  pre-generates rnd_p/rnd_g, calls _fortran_pso() once, unpacks result.

- pyswarm/meson.build: remove pso.py from install_sources (it was
  deleted in the first commit); fixes 'File pso.py does not exist' error.

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

Ensure __init__.py is packaged into the pyswarm package so the compiled extension and package import correctly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@saudzahirr saudzahirr force-pushed the f77-api branch 3 times, most recently from 778e79d to 51ab07f Compare May 24, 2026 02:59
@saudzahirr saudzahirr force-pushed the f77-api branch 6 times, most recently from 4d74dea to 1a87a70 Compare May 24, 2026 11:31
@sonarqubecloud

Copy link
Copy Markdown

@saudzahirr saudzahirr merged commit f405eb6 into master May 24, 2026
23 checks passed
@saudzahirr saudzahirr deleted the f77-api branch May 24, 2026 11:37
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.

3 participants