Skip to main content
each step: propose → score → accept if ΔE ≤ 0, else with prob e^(−ΔE / T)energy0step · high T explores, low T convergesenergycurrent state
each step: propose → score → accept if ΔE ≤ 0, else with prob e^(−ΔE / T)energy0step · high T explores, low T convergesenergycurrent state

This optimizer is open source. Any third-party models, product names, or trademarks referenced are the property of their respective owners, and Proto is not affiliated with them.


Source
proto-bio/proto-language/proto_language/optimizer/mcmc_optimizer.py
View source
Metropolis-Hastings MCMC optimizer for constraint-driven sequence optimization. This optimizer implements Metropolis-Hastings sampling with simulated annealing to optimize sequences against constraint-based energy functions. It uses mutation generators as proposal distributions and accepts/rejects proposals based on energy changes and temperature. At each step, the optimizer generates num_results x proposals_per_result proposals by mutating each of the K sequences proposals_per_result times. Each trajectory (result index) is independent. For each trajectory, the best proposal (lowest energy) is selected, then MH acceptance is applied to decide whether to accept or reject that proposal. If rejected, the trajectory keeps its previous state.
  • Typically used with mutation generators (category="mutation")
  • Uses Metropolis-Hastings acceptance: always accepts improvements, accepts worse proposals with probability exp(-ΔE/T)
  • Simulated annealing via configurable temperature_schedule
  • Lower energy scores are better (minimization objective)
  • When proposals_per_result > 1, generates multiple proposals per trajectory, selects the best one, then applies a single MH accept/reject decision

How It Works

MCMC walks a single trajectory: each step proposes a mutation, then accepts it outright if it lowers the energy or, when worse, with a temperature-dependent probability that cools over the run. Each step replicates every tracked sequence into a pool of P proposals (P = proposals_per_result), mutates them with a randomly chosen generator, scores the pool, and takes the lowest-energy proposal x′. A Metropolis-Hastings test then decides whether to move there:
α = min(1, exp(−(E(x′) − E(x)) / T))          accept x′ when  u ~ U(0,1) < α
T(t) = T_max · (T_min / T_max)^((t−1)/(N−1))   temperature anneals T_max → T_min
Improving moves (ΔE ≤ 0) are always accepted; a worse move is still taken with probability exp(−ΔE/T), so hot early steps explore and cold late steps exploit. An infeasible proposal (E = ∞) is always rejected, and num_results independent trajectories run in parallel.

API Reference

ConfigMCMCOptimizerConfig Source
Configuration object for MCMCOptimizer.This class defines configuration parameters for the Metropolis-Hastings MCMC optimizer, which explores sequence space through iterative mutation with probabilistic acceptance based on energy improvements.
  • The field default is None (inherits the program-level num_results).
  • When num_results=1, behaves like standard single-chain MCMC.
  • When num_results > 1, maintains that many independent trajectories and generates proposals_per_result (default: 1) proposals per result sequence each step.
num_steps
integer
required
Number of Metropolis-Hastings steps. Each step proposes, evaluates, and accept/reject samples.
num_results
integer
Independent MCMC trajectories run in parallel; each yields one candidate. Overrides program count.
proposals_per_result
integer
default:"1"
Proposals per trajectory each step; the best by energy is chosen, then accept/reject is applied.
max_temperature
number
default:"1.0"
Starting temperature for simulated annealing; higher accepts worse proposals more readily.
min_temperature
number
default:"0.001"
Ending dimensionless temperature for simulated annealing; must be greater than 0 and below the max.
temperature_schedule
enum
default:"exponential"
Annealing schedule from max to min temperature.Options: constant, cosine, exponential, hinge, linear, quadratic
seed
integer
Random seed for reproducible optimization, generator, and constraint tool streams.
tracking_interval
integer
default:"1"
Save history and log progress every N steps. Step 0 and final step always saved.
track_proposals
boolean
default:"False"
Save granular per-proposal results (accept/reject) in history snapshots.
verbose
boolean
default:"False"
Emit per-step debug information about proposals, scores, and acceptance through the logger.

Usage

python
>>> constructs = [Construct([segment1, segment2])]
>>> config = MCMCOptimizerConfig(num_results=1, num_steps=100, max_temperature=0.5, min_temperature=0.001)
>>> mcmc = MCMCOptimizer(
...     constructs=constructs, generators=[mutation_gen], constraints=[gc_constraint], config=config
... )
>>> mcmc.run()
>>> final_sequences = mcmc.constructs[0].joined_sequences

Metadata

PropertyValue
Keymcmc
ClassMCMCOptimizer
Targets Single SegmentFalse
Uses GPUFalse