Skip to content

Comments

refactor: reorganize optimizers into subfolders and migrate to uv#30

Merged
Anselmoo merged 11 commits intomainfrom
refactor/uv-migration-and-subfolders
Dec 21, 2025
Merged

refactor: reorganize optimizers into subfolders and migrate to uv#30
Anselmoo merged 11 commits intomainfrom
refactor/uv-migration-and-subfolders

Conversation

@Anselmoo
Copy link
Owner

Summary

This PR modernizes the project structure and tooling:

🗂️ Reorganize Optimizers into Categorical Subfolders

Moved 54 optimizer files from flat opt/ directory into 7 logical categories:

Category Count Description
gradient_based/ 11 AdaDelta, AdaGrad, Adam, AdamW, etc.
swarm_intelligence/ 12 PSO, ACO, Bat, Bee, Firefly, etc.
evolutionary/ 6 GA, DE, CMA-ES, etc.
classical/ 9 BFGS, Nelder-Mead, Powell, etc.
metaheuristic/ 12 Harmony Search, Cross-Entropy, etc.
constrained/ 2 Augmented Lagrangian, SLP
probabilistic/ 2 TPE, LDA

Backward compatible - all existing imports still work:

# New categorical imports
from opt.swarm_intelligence import ParticleSwarm

# Old imports still work!
from opt import ParticleSwarm

📦 Migrate from Poetry to uv

  • Converted pyproject.toml to PEP 621 standard
  • Using hatchling as build backend
  • Replaced poetry.lock with uv.lock
  • Much faster dependency resolution and installation

New commands:

uv sync           # Install dependencies
uv run python ... # Run Python
uv run ruff check # Run linting  
uv build          # Build package

🧪 Add Comprehensive Test Suite

Added opt/test/test_optimizers.py with 116 tests covering:

  • Optimizer instantiation for all 52+ optimizers
  • Search functionality validation
  • Benchmark function tests
  • Categorical import tests
  • Backward compatibility tests

🔄 CI/CD Updates

  • Updated python-publish.yaml to use uv build
  • Added new tests.yaml workflow with:
    • Python 3.10, 3.11, 3.12 matrix testing
    • Ruff linting and format checks

Other Changes

  • Updated .pre-commit-config.yaml with latest versions
  • Removed deprecated ANN101 lint ignore
  • Auto-sorted __all__ exports

Testing

uv sync
uv run pytest opt/test/ -v
# 116 passed ✅

- Move 54 optimizer files into 7 categorical subfolders:
  - gradient_based/ (11): AdaDelta, AdaGrad, Adam, etc.
  - swarm_intelligence/ (12): PSO, ACO, Bat, Bee, etc.
  - evolutionary/ (6): GA, DE, CMA-ES, etc.
  - classical/ (9): BFGS, Nelder-Mead, etc.
  - metaheuristic/ (12): Harmony Search, etc.
  - constrained/ (2): Augmented Lagrangian, SLP
  - probabilistic/ (2): TPE, LDA

- Add __init__.py with exports to each subfolder
- Update root opt/__init__.py for backward compatibility
- All existing imports still work (from opt import X)"
Copilot AI review requested due to automatic review settings December 20, 2025 21:32
Copy link
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

This PR modernizes the useful-optimizer project by migrating from Poetry to uv for dependency management and reorganizing 54 optimizer files into 7 logical categorical subfolders. The changes improve project structure and add comprehensive testing.

Key changes:

  • Migration from Poetry to uv with PEP 621-compliant pyproject.toml using hatchling as the build backend
  • Reorganization of optimizers into categorical subdirectories (gradient_based, swarm_intelligence, evolutionary, classical, metaheuristic, constrained, probabilistic)
  • Addition of 116 comprehensive tests covering optimizer instantiation, search functionality, and backward compatibility

Reviewed changes

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

Show a summary per file
File Description
uv.lock New lock file replacing poetry.lock with uv dependency resolution
pyproject.toml Converted to PEP 621 standard, migrated from Poetry to hatchling build backend
poetry.lock Removed in favor of uv.lock
opt/test/test_optimizers.py New comprehensive test suite with 116 tests for all optimizer categories
opt/test/__init__.py Test module initialization
opt/swarm_intelligence/*.py Moved swarm intelligence optimizers to subdirectory with 12 algorithms
opt/probabilistic/*.py Moved probabilistic optimizers (LDA, ParzenTreeEstimator) to subdirectory
opt/metaheuristic/*.py Moved metaheuristic optimizers to subdirectory with 12 algorithms
opt/gradient_based/__init__.py New categorical module for gradient-based optimizers
opt/evolutionary/__init__.py New categorical module for evolutionary algorithms

Comment on lines 8 to 64
from opt import BFGS
from opt import LBFGS
from opt import SGD
from opt import ADAGrad
from opt import ADAMOptimization
from opt import AMSGrad
from opt import AbstractOptimizer
from opt import AdaDelta
from opt import AdaMax
from opt import AdamW
from opt import AntColony
from opt import ArtificialFishSwarm
from opt import AugmentedLagrangian
from opt import CMAESAlgorithm
from opt import CatSwarmOptimization
from opt import CollidingBodiesOptimization
from opt import ConjugateGradient
from opt import CrossEntropyMethod
from opt import CuckooSearch
from opt import CulturalAlgorithm
from opt import DifferentialEvolution
from opt import EagleStrategy
from opt import EstimationOfDistributionAlgorithm
from opt import FireflyAlgorithm
from opt import GeneticAlgorithm
from opt import GlowwormSwarmOptimization
from opt import GreyWolfOptimizer
from opt import HarmonySearch
from opt import HillClimbing
from opt import ImperialistCompetitiveAlgorithm
from opt import LDAnalysis
from opt import Nadam
from opt import NelderMead
from opt import NesterovAcceleratedGradient
from opt import ParticleFilter
from opt import ParticleSwarm
from opt import ParzenTreeEstimator
from opt import Powell
from opt import RMSprop
from opt import SGDMomentum
from opt import ShuffledFrogLeapingAlgorithm
from opt import SimulatedAnnealing
from opt import SineCosineAlgorithm
from opt import SquirrelSearchAlgorithm
from opt import StochasticDiffusionSearch
from opt import StochasticFractalSearch
from opt import SuccessiveLinearProgramming
from opt import TabuSearch
from opt import TrustRegion
from opt import VariableDepthSearch
from opt import VariableNeighborhoodSearch
from opt import VeryLargeScaleNeighborhood
from opt import WhaleOptimizationAlgorithm
from opt.benchmark.functions import shifted_ackley
from opt.benchmark.functions import sphere


Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

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

Import of 'BatAlgorithm' is not used.
Import of 'BeeAlgorithm' is not used.

Copilot uses AI. Check for mistakes.
@Anselmoo
Copy link
Owner Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Contributor

Copilot AI commented Dec 20, 2025

@Anselmoo I've opened a new pull request, #31, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits December 20, 2025 21:48
…r BatAlgorithm and BeeAlgorithm

Co-authored-by: Anselmoo <13209783+Anselmoo@users.noreply.github.com>
fix: resolve BeeAlgorithm typo and add missing test coverage for BatAlgorithm/BeeAlgorithm
@Anselmoo Anselmoo merged commit 78dab9b into main Dec 21, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants