Plotting functions

iohblade.plots.add_method_labels(data: DataFrame, column: str = 'method_label') → DataFrame

Add a label per method that names the LLM when a method used several.

The label is method when a method name was used with one LLM, and method (llm) when the same method name was run with several LLMs.

Parameters:
  • data (pd.DataFrame) – Rows with method_name (and llm_name).

  • column (str) – The name of the column to add.

Returns:

data with the label column (modified in place).

Return type:

pd.DataFrame

iohblade.plots.aggregate_best_so_far(curves: DataFrame, aggregation: str = 'mean', variance_aggregation: str = 'std', run_cols: list[str] | None = None, max_eval: int | None = None) → DataFrame

Aggregate best-so-far curves of several runs per evaluation.

Each run’s curve is carried forward (its last best value) to the common maximum evaluation count, so runs that stopped early still count and the mean of best-so-far curves stays monotone. Before a run’s first valid evaluation its curve is missing and it is left out of the aggregate.

Parameters:
  • curves (pd.DataFrame) – Output of best_so_far() (for one group).

  • aggregation (str) – Aggregation over runs (mean, median, …).

  • variance_aggregation (str) – Spread over runs (std, sem, …).

  • run_cols (list[str], optional) – Columns identifying a run.

  • max_eval (int, optional) – Extend the curves to this evaluation count (default: the longest run).

Returns:

Columns eval, aggregation, variance_aggregation and n_runs (runs with a valid value).

Return type:

pd.DataFrame

iohblade.plots.best_so_far(data: DataFrame, minimisation: bool = False, fitness_col: str | None = None, run_cols: list[str] | None = None) → DataFrame

Per-run best-so-far curves of the evaluated solutions.

Failed evaluations (±inf, NaN, strings such as "-inf") are treated as missing: they never improve the curve and are never shown as 0. The curve is NaN until the first valid evaluation of a run.

Parameters:
  • data (pd.DataFrame) – One row per evaluation with a fitness column, the run-identity columns and _id (evaluation order).

  • minimisation (bool) – True when lower fitness is better (curve is a cumulative minimum), otherwise a cumulative maximum.

  • fitness_col (str, optional) – The fitness column; by default fitness_scalar if present, else fitness.

  • run_cols (list[str], optional) – Columns identifying a run; by default run_columns().

Returns:

A copy of data sorted by run and _id, with fitness_value (cleaned float fitness), best_so_far and eval (the 1-based evaluation index within the run).

Return type:

pd.DataFrame

iohblade.plots.clean_fitness(values) → Series

Convert fitness values to floats with failures (±inf, NaN, junk) as NaN.

Parameters:

values (pd.Series | list) – Fitness values.

Returns:

Float series of the same index, NaN for failures.

Return type:

pd.Series

iohblade.plots.final_best_per_run(curves: DataFrame, run_cols: list[str] | None = None) → DataFrame

The last row of each run’s best-so-far curve (its best fitness).

Parameters:
  • curves (pd.DataFrame) – Output of best_so_far().

  • run_cols (list[str], optional) – Columns identifying a run.

Returns:

One row per run; best_so_far is NaN for a run in which every evaluation failed.

Return type:

pd.DataFrame

iohblade.plots.fitness_table(logger: ExperimentLogger, alpha=0.05, smaller_is_better: bool | None = None, minimisation: bool | None = None)

Creates a LaTeX table with rows = methods, columns = problems. Each cell shows mean ± std (p=…). Cells are bolded if that method is significantly better than all others (p < alpha) for the given problem.

Runs whose final fitness is a failure (±inf or NaN) are left out of the statistics and counted in the cell (k failed).

Parameters:
  • logger (ExperimentLogger) – the experiment logger to process.

  • alpha (float) – Significance level for p-value cutoff.

  • smaller_is_better (bool, optional) – If True, we treat lower fitness as “better”, if False higher is “better”. Defaults to the direction logged for each problem.

  • minimisation (bool, optional) – Alias of smaller_is_better.

iohblade.plots.normalize_key(key)

Converts any feature key to a standardized format (e.g., ‘mean_complexity’ -> ‘mean complexity’).

iohblade.plots.plot_boxplot_fitness(logger: ExperimentLogger, y_label='Fitness', x_label='Method', problems=None)

Plots boxplots of fitness grouped by problem_name (subplots) and method_name (categories). Each problem has its own subplot, grouped by method_name.

Parameters:
  • logger

  • y_label

  • x_label

  • problems

Failed runs (a final fitness of ±inf or NaN) are left out; a method used with several LLMs gets one box per LLM.

iohblade.plots.plot_boxplot_fitness_hue(logger: ExperimentLogger, y_label='Fitness', x_label='Problem', hue='method_name', x='problem_name', problems=None)

Plots boxplots of fitness grouped by hue and method_name x. Produces one plot with grouped boxplots per x. Failed runs (a final fitness of ±inf or NaN) are left out.

Parameters:

logger

iohblade.plots.plot_code_evolution_graphs(run_data, expfolder=None, plot_features=None, markersize=None, save=True, ax=None, minimisation: bool = False)

Plots optimization progress and relationships between successive solutions in an evolutionary run based on AST metrics. Can plot multiple features or a single feature on a provided axis.

Parameters:
  • run_data (pandas.DataFrame) – DataFrame containing code and fitness values.

  • expfolder (str, optional) – Folder path where the plots are saved. If None, plots are shown.

  • plot_features (list, optional) – The features to plot. If None, plots multiple default features.

  • markersize (int. optional) – The size of the markers, if not set it will be dynamic based on the degree.

  • save (bool) – If True, saves the plots otherwise shows them.

  • ax (matplotlib.axes.Axes, optional) – The axis to plot on. If None, creates new plots.

  • minimisation (bool) – Whether lower fitness is better; the marker colour shows the best fitness brightest either way, failed evaluations get the colour of the worst.

iohblade.plots.plot_convergence(logger: ExperimentLogger, metric: str = 'Fitness', aggregation: str = 'mean', variance_aggregation: str = 'std', methods: list = None, budget: int = 100, save: bool = True, return_fig: bool = False, separate_lines: bool = False, show_std: bool = True, minimisation: bool | None = None)

Plots the convergence of all methods for each problem from an experiment log.

Each run’s best-so-far fitness (cumulative maximum, or minimum for a minimisation problem) is plotted against the 1-based evaluation index. Failed evaluations never improve the curve. Runs are told apart by their run folder (or method, LLM and seed); a method used with several LLMs gets one line per LLM. For the aggregate, shorter runs are carried forward with their final best value.

For multi-objective problems the scalar summary (mean of all objectives) is used as the convergence metric. Use plot_pareto_front() to visualise the Pareto front directly.

Parameters:
  • logger (ExperimentLogger) – The experiment logger object.

  • metric (str, optional) – The metric to show as y-axis label.

  • aggregation (str, optional) – The aggregation method to use (‘mean’, ‘median’, etc.).

  • variance_aggregation (str, optional) – The method to aggregate variance (‘std’, ‘sem’, etc.).

  • methods (list, optional) – List of method names to include. If None, includes all methods.

  • budget (int, optional) – The maximum number of evaluations to display on the x-axis.

  • save (bool, optional) – Whether to save or show the plot.

  • return_fig (bool, optional) – Whether to return the figure object.

  • separate_lines (bool, optional) – If True, plots each run using separate line.

  • show_std (bool, optional) – If True, shows standard deviation as shaded area.

  • minimisation (bool, optional) – Whether lower fitness is better. Defaults to the direction logged for each problem.

iohblade.plots.plot_experiment_CEG(logger: ExperimentLogger, metric: str = 'total_token_count', methods=None, markersize=None, budget: int = 100, save: bool = True, max_seeds=5, minimisation: bool | None = None)

Plot the Code evolution graphs for each run in an experiment, splitted by problem.

Parameters:
  • logger (ExperimentLogger) – The experiment logger object.

  • metric (str, optional) – The metric to show as y-axis label (should be a statistic from AST / Complexity).

  • methods (list, optional) – An optional list of method names to plot, if None, all methods are included.

  • markersize (int. optional) – The size of the markers, if not set it will be dynamic based on the degree.

  • budget (int) – The number of evaluations to plot.

  • save (bool, optional) – Whether to save or show the plot.

  • max_seeds (int, optional) – The maximum number of runs to plot.

  • minimisation (bool, optional) – Whether lower fitness is better (used for the marker colours). Defaults to the logged direction.

iohblade.plots.plot_pareto_front(logger: ExperimentLogger, objective_x: str, objective_y: str, methods: list = None, problems: list = None, save: bool = True, return_fig: bool = False)

Plot the Pareto front discovered by each method for each multi-objective problem.

Each point in the scatter plot represents one evaluated solution. Non-dominated solutions (i.e. the empirical Pareto front) are highlighted.

Parameters:
  • logger (ExperimentLogger) – The experiment logger object.

  • objective_x (str) – Name of the objective to plot on the x-axis.

  • objective_y (str) – Name of the objective to plot on the y-axis.

  • methods (list, optional) – Methods to include. None includes all.

  • problems (list, optional) – Problems to include. None includes all.

  • save (bool, optional) – If True, saves the figure to the log directory.

  • return_fig (bool, optional) – If True, returns the Figure object.

Returns:

matplotlib.figure.Figure | None

iohblade.plots.plot_speedup(logger: ExperimentLogger, method_fast: str, method_slow: str, aggregation: str = 'mean', variance_aggregation: str = 'std', budget: int = 100, save: bool = True, return_fig: bool = False, minimisation: bool | None = None)

Plots speed-up of method_fast over method_slow.

Speed-up definition: If method_fast reaches fitness x at n evaluations and method_slow reaches fitness x at m evaluations, speed-up = m / n.

Parameters:
  • logger (ExperimentLogger)

  • method_fast (str) – numerator algorithm

  • method_slow (str) – denominator algorithm

  • aggregation (str) – mean / median

  • variance_aggregation (str) – std / sem

  • budget (int) – max evaluations

  • save (bool)

  • return_fig (bool)

  • minimisation (bool, optional) – Whether lower fitness is better. Defaults to the direction logged for each problem.

iohblade.plots.plot_token_usage(logger: ExperimentLogger, save: bool = True, return_fig: bool = False, return_df: bool = False)

Plot total tokens used per method/problem from an experiment logger.

iohblade.plots.plotly_code_evolution(run_data: DataFrame, feature: str = 'total_token_count', minimisation: bool = False) → Figure

Create an interactive code evolution graph using Plotly.

Parameters:
  • run_data (pd.DataFrame) – The evaluations of one run.

  • feature (str) – The code feature on the y-axis.

  • minimisation (bool) – Whether lower fitness is better; the colour scale shows the best fitness brightest, failures as the worst.

iohblade.plots.run_columns(data: DataFrame) → list[str]

The columns that identify a run in a DataFrame of evaluations.

run (the run folder, see ExperimentLogger.get_problem_data) when present; otherwise the available columns of method, LLM, problem and seed.

iohblade.plots.safe_parse_parent_ids(x)