A Python package for hill climbing optimization with replica exchange and simulated annealing
Project description
Hill Climber
A Python package for hill climbing optimization of user-supplied objective functions with simulated annealing. Designed for flexible multi-objective optimization with support for multi-column datasets.
1. Documentation
View Full Documentation on GitHub Pages
2. Features
- Replica Exchange (Parallel Tempering): Multiple replicas at different temperatures exchange configurations for improved global optimization
- Real-Time Monitoring Dashboard: Streamlit-based modular dashboard for live progress visualization with SQLite backend
- Simulated Annealing: Temperature-based acceptance of suboptimal solutions to escape local minima
- Flexible Objectives: Support for any objective function with multiple metrics
- Multi-Column Support: Optimize datasets with any number of features/columns
- Checkpoint/Resume: Save and resume long-running optimizations with configurable checkpoint intervals
- JIT Compilation: Numba-optimized core functions for performance
3. Quick Start
3.1. Installation
Install the package directly from PyPI to use it in your own projects:
pip install parallel-hill-climber
For detailed usage, configuration options, and advanced features, see the full documentation.
3.2. Example climb
Simple hill climb to maximize the Pearson correlation coefficient between two random uniform features:
import numpy as np
import pandas as pd
from hill_climber import HillClimber
# Create sample data
data = pd.DataFrame({
'x': np.random.rand(100),
'y': np.random.rand(100)
})
# Define objective function
def my_objective(x, y):
correlation = pd.Series(x).corr(pd.Series(y))
metrics = {'correlation': correlation}
return metrics, correlation
# Create optimizer with replica exchange
climber = HillClimber(
data=data,
objective_func=my_objective,
max_time=1, # minutes
mode='maximize',
n_replicas=4 # Use 4 replicas for parallel tempering
)
# Run optimization
best_data, history_df = climber.climb()
3.3. Real-Time Monitoring Dashboard
Monitor optimization progress in real-time with the Streamlit dashboard:
from hill_climber import HillClimber
# Enable database logging
climber = HillClimber(
data=data,
objective_func=my_objective,
max_time=30,
n_replicas=8,
db_enabled=True, # Enable real-time monitoring
db_path='optimization.db',
checkpoint_interval=10 # Checkpoint every 10 batches
)
# Run optimization
best_data, history = climber.climb()
Launch the dashboard in a separate terminal:
pip install "parallel-hill-climber[dashboard]"
hill-climber-dashboard
The dashboard provides:
- Replica leaderboard showing top performers
- Exploration rate (total perturbations/sec) and progress rate (accepted steps/sec)
- Interactive time series plots for all metrics across replicas
- Temperature exchange event markers
- Plot normalization and layout options
- Run information including objective function name, dataset size, and hyperparameters
See DASHBOARD_README.md for complete dashboard documentation.
3.4. Example Notebooks
The notebooks/ directory contains demonstration of key concepts and complete worked examples demonstrating various use cases:
- Simulated Annealing: Introduction to simulated annealing algorithm
- Pearson & Spearman: Optimizing for different correlation measures
- Mean & Std: Creating distributions with matching statistics but diverse structures
- Entropy & Correlation: Low correlation with internal structure
- Feature Interactions: Machine learning feature engineering demonstrations
- Checkpointing: Long-running optimization with save/resume
4. Development Environment Setup
To explore the examples, modify the code, or contribute:
4.1. Setup Option 1: GitHub Codespaces (No local setup required)
- Fork this repository
- Open in GitHub Codespaces
- The development environment will be configured automatically
- Documentation will be built and served at http://localhost:8000 automatically
4.2. Setup Option 2: Local Development
-
Clone or fork the repository:
git clone https://github.com/gperdrizet/hill_climber.git cd hill_climber
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
4.3. Building Documentation
You can build and view a local copy of the documentation as follows:
cd docs
make html
# View docs by opening docs/build/html/index.html in a browser
# Or serve locally with: python -m http.server 8000 --directory build/html
4.4. Running Tests
To run the test suite:
# Run all tests
python tests/run_tests.py
# Or with pytest if installed
python -m pytest tests/
# Run specific test file
python -m pytest tests/test_hill_climber.py
# Run with coverage
python -m pytest tests/ --cov=hill_climber
5. Contributing
Contributions welcome! Please ensure all tests pass before submitting pull requests.
6. License
This project is licensed under the GNU General Public License v3.0 (GPL-3.0). See the LICENSE file for full details.
In summary, you are free to use, modify, and distribute this software, but any derivative works must also be released under the GPL-3.0 license.
7. Citation
If you use this package in your research, please use the "Cite this repository" button at the top of the GitHub repository page to get properly formatted citations in APA, BibTeX, or other formats.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file parallel_hill_climber-2.1.2.tar.gz.
File metadata
- Download URL: parallel_hill_climber-2.1.2.tar.gz
- Upload date:
- Size: 52.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82216462a3772b49a218679da3c43d84d7d4051aa6594736ea2ea8464a8b2572
|
|
| MD5 |
4735ff12f2d2d96e7e85eabd92776ed5
|
|
| BLAKE2b-256 |
9977763301ff9869112a58cf175e70414e7de41896ce4eefece077fb8a68c39d
|
Provenance
The following attestation bundles were made for parallel_hill_climber-2.1.2.tar.gz:
Publisher:
publish-to-pypi.yml on gperdrizet/hill_climber
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
parallel_hill_climber-2.1.2.tar.gz -
Subject digest:
82216462a3772b49a218679da3c43d84d7d4051aa6594736ea2ea8464a8b2572 - Sigstore transparency entry: 731865401
- Sigstore integration time:
-
Permalink:
gperdrizet/hill_climber@ca64842f69ee24c3106b5faecb34fdc77d8e59a9 -
Branch / Tag:
refs/tags/v2.1.2 - Owner: https://github.com/gperdrizet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@ca64842f69ee24c3106b5faecb34fdc77d8e59a9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file parallel_hill_climber-2.1.2-py3-none-any.whl.
File metadata
- Download URL: parallel_hill_climber-2.1.2-py3-none-any.whl
- Upload date:
- Size: 54.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e62435f9fef1a4b82f5dd385ce466e57751f27ee66a19dd090cdd0f830bd6ec0
|
|
| MD5 |
0e1b156cb3ef57f239c0f01790f1d8ff
|
|
| BLAKE2b-256 |
31fea6daf239dd57467a05553df743447f277aad598a2c230265dc9767fd8b72
|
Provenance
The following attestation bundles were made for parallel_hill_climber-2.1.2-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on gperdrizet/hill_climber
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
parallel_hill_climber-2.1.2-py3-none-any.whl -
Subject digest:
e62435f9fef1a4b82f5dd385ce466e57751f27ee66a19dd090cdd0f830bd6ec0 - Sigstore transparency entry: 731865405
- Sigstore integration time:
-
Permalink:
gperdrizet/hill_climber@ca64842f69ee24c3106b5faecb34fdc77d8e59a9 -
Branch / Tag:
refs/tags/v2.1.2 - Owner: https://github.com/gperdrizet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@ca64842f69ee24c3106b5faecb34fdc77d8e59a9 -
Trigger Event:
release
-
Statement type: