gras-0.1.3 has been yanked.
gras
Genetic Programming for Neural Architecture Search in Rust.
Evolves neural network topologies using genetic algorithms. The engine builds, trains, and scores populations of random architectures in parallel, then selects, crosses over, and mutates the best — repeating until convergence.
Table of Contents
Features
- Evolutionary NAS — evolve hidden layer count, dims, activations, combine ops, standardize ops per node
- Variable hidden dims — each node draws its own output width; projections bridge mismatched dims automatically
- Dual fitness — separate training loss (backward) from evolution ranking (fitness) via
from_loss_with_diff - Parallel evaluation — rayon-powered population scoring
- Deterministic — one seed reproduces the entire run: population, weights, batches
- Flat builder —
EngineOptions::builder().set_*()routes into engine, topology, GP pools, network - Built-in metrics — MSE, MAE, RMSE, R2, accuracy, F1, precision, cross-entropy (4 continuous + 4 categorical)
- Custom fitness — drop-in closures for any metric
- Checkpointing — engine.json + per-generation best/worst snapshots with full topology + rebuild snippet
- Deduplication — removes duplicate topologies via full Spec comparison
- Selection — tournament with elitism (best always survives)
- Crossover — two-point (matching-node pivot) or uniform (per-node swap)
- Mutation — one random type per individual: activation, combine op, standardize, hidden dim
- Dropout — configurable per-hidden-node regularization
- Proportional batching — class-balanced sampling for categorical data
Installation
[]
= "0.1.2"
Optional CUDA support:
= { = "0.1.2", = ["cuda"] }
Quick Start
use Device;
use ;
Run with: source env_setup.sh && cargo run --example quick_showcase
Architecture
Engine::new(options, data_path, fitness)
validate_and_fill_options — fill empty pools, check constraints
resolve_seed — user-provided or random
load_data — read tensors, bind input_dim/output_dim
create_population — random topologies from seed
dedup_population — remove duplicates (if enabled)
log_initialization — print all resolved options
Engine::run()
for each generation:
evaluate_population — parallel: build net, train, score
save_snapshots — best + worst to improvements/
next_generation
select — tournament with elitism
crossover — two-point or uniform
dedup_population — remove crossover duplicates
mutate — one random type per individual
log_run_summary — winner, artifacts, rebuild snippet
API Overview
Engine Options
builder
// Engine
.set_seed
.set_pop_size
.set_num_generations
.set_num_threads // 0 = auto-detect
.set_results_dir
.set_progress_interval // print every N individuals
.set_dedup_pop // remove duplicate topologies
// Selection
.set_selection
// Crossover
.set_crossover
// .set_crossover(CrossoverKind::Uniform { action_prob: 0.7, swap_prob: 0.5 })
// Mutation
.set_mutation
// GP pools (empty = all built-in ops)
.set_hidden_dim_pool
.set_combine_op_pool
.set_activation_pool
.set_standardize_op_pool
// Topology
.set_min_hidden_num_nodes
.set_max_hidden_num_nodes
.set_min_hidden_inputs_per_node
.set_max_hidden_inputs_per_node
.set_min_hidden_outputs_per_node
.set_max_hidden_outputs_per_node
// Budget
.set_num_batches
.set_batch_size
.set_num_epochs
.set_y_proportional_batches // class-balanced sampling
// Training
.set_learning_rate
.set_optimizer
.set_grad_clip
.set_dropout_prob
// Network
.set_device
.set_dtype
Fitness
Same function for training and ranking:
from_loss
Separate training loss from evolution fitness:
from_loss_with_diff
Rebuild from checkpoint
use ;
let v: Value = from_str.unwrap;
let topo = from_json.unwrap;
let net = build.unwrap;
Any engine.json or improvements/*.json file works — same format.
Examples
| Example | What it shows |
|---|---|
quick_showcase |
Minimal end-to-end run |
main |
Full MNIST test with F1 + crossover + mutation (not published) |
&&
&&
License
MIT