Multi-objective problems¶
BLADE supports multi-objective optimisation through the Fitness
class. When a problem returns multiple objectives, its evaluate() method sets
solution.fitness to a Fitness object instead of a plain float.
Overview¶
Fitness wraps a dict[str, float] mapping objective names to objective values.
It defines Pareto-dominance comparisons so that standard Python operators work
intuitively:
Expression |
Meaning (minimisation) |
|---|---|
|
|
|
|
|
|
|
Identical objective values on every objective. |
|
Scalar summary: mean of all objectives ( |
Note
Do not use Python’s built-in sort on Fitness objects. Sorting
requires a total order, which multi-objective dominance cannot guarantee.
Use dedicated Pareto-sorting utilities instead.
Quick Example¶
from iohblade import Fitness
a = Fitness({"f1": 1.0, "f2": 3.0}) # good on f1, weak on f2
b = Fitness({"f1": 3.0, "f2": 1.0}) # weak on f1, good on f2
# Neither dominates the other (incomparable → both on the Pareto front)
print(a < b) # False
print(b < a) # False
# Scalar summary (mean)
print(float(a)) # 2.0
print(float(b)) # 2.0
# Serialise / deserialise (e.g. for JSON logging)
d = a.to_dict() # {"f1": 1.0, "f2": 3.0}
a2 = Fitness.from_dict(d) # reconstructed Fitness
Writing a Multi-Objective Problem¶
Return a Fitness object from evaluate():
from iohblade import Fitness, Solution
from iohblade.problem import Problem
class MyBiObjectiveProblem(Problem):
def evaluate(self, solution: Solution) -> Solution:
# ... run the generated algorithm ...
best_f1, best_f2 = run_algorithm(solution.code)
# BLADE maximises: negate so lower raw values → higher fitness
fitness = Fitness({"f1": -best_f1, "f2": -best_f2})
return solution.set_scores(fitness=fitness, feedback="...")
Toy Benchmark¶
A ready-to-use toy bi-objective problem is provided for testing:
from iohblade.benchmarks.toy_multiobjective import ToyMultiObjective
problem = ToyMultiObjective(budget=100)
The problem asks the LLM to generate an algorithm (BiSphereSearcher) that
simultaneously minimises:
f1 = \(x^2\) (distance to 0)
f2 = \((x - 2)^2\) (distance to 2)
These objectives conflict: the optimal x for f1 is 0, while for f2 it is 2. The Pareto front lies on \(x \in [0, 2]\).
Plotting¶
Use plot_pareto_front() to visualise the discovered Pareto
front:
from iohblade.plots import plot_pareto_front
plot_pareto_front(
logger=exp_logger,
objective_x="f1",
objective_y="f2",
)
The plot highlights non-dominated solutions (the empirical Pareto front) and connects them with a step curve for visual clarity.
Convergence plots (via plot_convergence()) remain available
for multi-objective runs: they use the mean of all objectives as the scalar
convergence metric.
Logging¶
Fitness objects are serialised as plain JSON dicts in log.jsonl:
{"fitness": {"f1": -0.04, "f2": -1.96}, "name": "BiSphereSearcher", ...}
When get_problem_data() reads this file
it automatically adds a fitness_scalar column containing the mean objective
value, which is what the convergence and speedup plots consume.
API reference¶
Fitness and the multi-objective toy problem are
documented in Fitness; the plotting functions in Plotting functions.