fx-durable-ga
A durable, auditable genetic algorithm optimization library built on PostgreSQL.
What is this?
fx-durable-ga is designed for long-running genetic algorithm optimizations where durability and auditability matter more than framework speed. It's built for scenarios where fitness evaluations are expensive (seconds to hours) and you need:
- Crash recovery: Resume optimizations exactly where they left off
- Full audit trails: Every evaluation, generation, and decision is recorded
- Concurrent execution: Multiple workers can contribute to the same optimization
When to use
Well suited for:
- AI model hyperparameter optimization
- Neural architecture search
- Feature selection for ML models
- Any optimization where evaluation takes much longer than the GA framework overhead and where parameters can be represented as discrete numbers.
Not ideal for:
- Fast, in-memory optimizations (use traditional GA libraries)
- Real-time applications requiring sub-second responses
How does it work?
The library uses PostgreSQL for both storage and coordination:
- Durable state: All populations, genotypes, and evaluations persist in the database
- Event-driven: Optimizations progress through database events, enabling crash recovery
- Deduplication: Identical genomes are never evaluated twice for the same request
- Smart initialization: Latin Hypercube Sampling for better space coverage
- Fitness-based termination: Automatic stopping when target fitness thresholds are reached
Network latency to the database is the primary overhead, but this is negligible when fitness evaluations take seconds or longer.
Quick start
use ;
use BoxFuture;
// 2. Implement genetic encoding
// 3. Implement fitness evaluation
;
// 4. Start optimization
let service = bootstrap.await?
..await?
.build;
service.new_optimization_request.await?;
Documentation and examples
- API documentation: https://docs.rs/fx-durable-ga/0.1.5/fx_durable_ga/index.html or run
cargo doc --open - Examples:
examples/point_search.rs- basic exampleexamples/regression_model.rs- hyperparameter optimization for a regression model
Migrations
Run migrations using the provided sqlx migrator.
- To run the migrations of this crate only, use
fx_durable_ga::migrations::run_migrations - To run migrations of dependencies and the migrations of this crate, use
fx_durable_ga::migrations::run_migrations. Note that this will use the default schema name forfx-mq-jobs, if you wish to use another schema, you will need call each migrator.
Running migrations for development
Set DATABASE_URL in your env and create the database. If you're using sqlx cli call sqlx database create. Then do:
SQLX_OFFLINE=true cargo run --bin migrate --features migration
That runs migrations for this crate and its dependencies fx-event-bus and fx-mq-jobs. The migration binary uses the feature flag "migration" to exclude all code that is statically typechecked by sqlx. Once it has been run you may set SQLX_OFFLINE=false and everything should work as normally.
Set DATABASE_URL in your environment and create the database (e.g., sqlx database create). Run migrations with:
SQLX_OFFLINE=true
Contributing
Contributions are welcome! Please feel free to submit pull requests for bug fixes, improvements, or new features.