leniax.qd package

leniax.qd.build_eval_lenia_config_mem_optimized_fn(qd_config, fitness_coef=1.0, fft=True)[source]

Construct the evaluation function for the mem_optimized runner function

Parameters
  • qd_config (Dict) – QD configuration

  • fitness_coef (float) – Multiply all returned fitness by this coefficient before ranking (mainly used to negate raw fitness values)

  • fft (bool) – Set to True to use FFT optimization

Returns

The evaluation function.

Return type

Callable

leniax.qd.get_dynamic_args(qd_config, leniax_sols, fft=True)[source]

Prepare dynamic arguments to be used in parrallel simulations

Parameters
  • qd_config (Dict) – Leniax QD configuration

  • leniax_sols (List[leniax.lenia.LeniaIndividual]) – Candidate Leniax solutions

  • fft (bool) – Set to True to use FFT optimization

Returns

A 2-tuple representing a JAX PRNG key and a 5-tuple of the batch of simulation parameters of shape [N_sols, N_init, nb_channels, world_dims...]

Return type

Tuple[jax._src.prng.PRNGKeyArray, Tuple[jax._src.numpy.ndarray.ndarray, jax._src.numpy.ndarray.ndarray, jax._src.numpy.ndarray.ndarray, jax._src.numpy.ndarray.ndarray, jax._src.numpy.ndarray.ndarray]]

leniax.qd.update_individuals(inds, stats, fitness_coef=1.0)[source]

Update Lenia individuals

Warning

In the statistics dictionnary, the N statistic is of shape [N_sols, N_init].

Parameters
  • inds (List[leniax.lenia.LeniaIndividual]) – Evaluated Lenia individuals

  • stats (Dict[str, jax._src.numpy.ndarray.ndarray]) – Dict[str, [N_sols, nb_iter, N_init]]

  • fitness_coef – Multiply all returned fitness by this coefficient before ranking (mainly used to negate raw fitness values)

Returns

Lpdate Lenia individuals

Return type

List[leniax.lenia.LeniaIndividual]

Run a Quality-diveristy search

Warning

  • n_workers == -1 means that your evaluation functions handles parallelism

  • n_workers == 0 means that you want to use a sinple python loop function

  • n_workers > 0 means that you want to use python spawn mechanism

Parameters
  • rng_key (jax._src.prng.PRNGKeyArray) – jax PRNGKey

  • qd_config (Dict) – QD configuration

  • optimizer (ribs.optimizers._optimizer.Optimizer) – pyribs Optimizer

  • fitness_domain (Tuple[int, int]) – a 2-tuple of ints representing the fitness bounds

  • eval_fn (Callable) – The evaluation function

  • log_freq (int) – Logging frequency

  • n_workers (int) – Number of workers used to eval a set of candidate solutions

Returns

Qd metrics

Return type

Dict[str, Dict[str, list]]

leniax.qd.load_qd_grid_and_config(grid_fullpath)[source]

Helper function to load the QD grid and configuration

Parameters

grid_fullpath (str) – The absolute path the pickled grid.

Returns

A 2-tuple representing the QD grid and configuration.

Return type

Tuple[ribs.archives._archive_base.ArchiveBase, Dict]

leniax.qd.render_best(grid, fitness_threshold)[source]

Helper function to render configurations above the threshold

Parameters
  • grid (ribs.archives._archive_base.ArchiveBase) – QD grid.

  • fitness_threshold (float) – Threshold definie what is among the best fitness values

leniax.qd.render_found_lenia(enum_lenia)[source]

Render one Lenia

Parameters

enum_lenia (Tuple[int, leniax.lenia.LeniaIndividual]) – A 2-tuple representing and index and a Lenia individual.

leniax.qd.save_ccdf(archive, fullpath)[source]

Saves a CCDF showing the distribution of the archive’s objective values.

Note

CCDF = Complementary Cumulative Distribution Function

The CCDF plotted here is not normalized to the range (0,1).

This may help when comparing CCDF’s among archives with different amounts of coverage (i.e. when one archive has more cells filled).

Parameters
  • archive (ribs.archives._archive_base.ArchiveBase) – Archive containing the experiment results.

  • fullpath (str) – Absolute path to an image file.

leniax.qd.save_metrics(metrics, save_dir)[source]

Plot and save QD metrics.

Parameters
  • metrics (Dict[str, Dict[str, list]]) – Dictionnary of metrics.

  • save_dir (str) – Absolute path of the saving directory.

leniax.qd.save_heatmap(archive, fitness_domain, fullpath)[source]

Save QD heatmap

Parameters
  • archive (ribs.archives._archive_base.ArchiveBase) – Archive containing the experiment results.

  • fitness_domain (Tuple) – Bounds of fitness values.

  • fullpath (str) – Absolute path of the file.

leniax.qd.save_parallel_axes_plot(archive, fitness_domain, fullpath)[source]

Save parallel axes plot.

Parameters
  • archive (ribs.archives._archive_base.ArchiveBase) – Archive containing the experiment results.

  • fitness_domain (Tuple) – Bounds of fitness values.

  • fullpath (str) – Absolute path of the file.

leniax.qd.save_emitter_samples(archive, fitness_domain, sols, fits, bcs, fullpath, title)[source]

Save emitter sampling points.

Parameters
  • archive (ribs.archives._archive_base.ArchiveBase) – Archive containing the experiment results.

  • fitness_domain (Tuple) – Bounds of fitness values.

  • sols (List) – Solutions parameters.

  • fits (List) – Fitness measurements.

  • bcs (List) – Behaviours measurements.

  • fullpath (str) – Absolute path of the file.

  • title (str) – Title of the image.

leniax.qd.save_all(current_iter, optimizer, fitness_domain, sols, fits, bcs)[source]

Helper function to all kind of vizualisation for a QD iteration.

Parameters
  • current_iter (int) – Current QD iteration.

  • optimizer – Pyribs compatible optimizer.

  • fitness_domain (Tuple) – Bounds of fitness values.

  • sols (List) – Solutions parameters.

  • fits (List) – Fitness measurements.

  • bcs (List) – Behaviours measurements.