leniax.utils package
- leniax.utils.get_container(omegaConf, main_path)[source]
Retrieve the populated container from an omegaConf
This functions is used to: - Populate missing mandatory value in Leniax configuration - Handle versioning update if necessary
# Use with Hydra as follow @hydra.main(config_path=config_path, config_name=config_name) def run(omegaConf: DictConfig) -> None: config = leniax_utils.get_container(omegaConf, config_path)
- Parameters
omegaConf (omegaconf.dictconfig.DictConfig) – Hydra’s Omega configuration
main_path (str) – Absolute path of the configuration directory
- Returns
A populated python dictionnary
- Return type
Dict
- leniax.utils.update_config_v1_v2(config)[source]
Update a configuration from version 1 to version 2
- Parameters
config (Dict) – A v1 configuration
- Returns
A v2 configuration
- Return type
Dict
- leniax.utils.get_param(dic, key_string)[source]
Retrieve a parameter in a dictionnary using a string
- Parameters
dic (Dict) – Dictionnary
key_string (str) – String representing the parameter path in the dicitonnary
- Returns
The parameter
- Return type
Any
- leniax.utils.set_param(dic, key_string, value)[source]
Set a parameter in a dictionnary using a string
- Parameters
dic (Dict) – Dictionnary
key_string (str) – String representing the parameter path in the dicitonnary
value (Any) – Value to be set
- leniax.utils.st2fracs2float(st)[source]
Convert a string of fraction into an list of floats
String example:
st = '1,2/3,6.7'- Parameters
st (str) – String of fractions.
- Returns
An list of float
- Return type
List[float]
- leniax.utils.merge_cells(cells, other_cells, offset=None)[source]
Merge cells together using addition
- Parameters
cells (jax._src.numpy.ndarray.ndarray) – Base cells
other_cells (jax._src.numpy.ndarray.ndarray) – Cells to be merged into the base cells
offset (Optional[List[int]]) – Offsets in each dimensions
- Returns
Resulting cells
- Return type
jax._src.numpy.ndarray.ndarray
- leniax.utils.center_world(cells, field, potential, shift_idx, axes)[source]
Vectorized version of center_world. Takes similar arguments as center_world but with additional array axes over which center_world is mapped.
Original documentation:
Rool cells, field and potential
- Args:
cells: Lenia state of shape
[bs, other_axes...]field: Lenia field[bs, other_axes...]potential: Lenia potential[bs, other_axes...]shift_idx: Amount to roll of shape[bs, nb_axes]`axes: Axes to roll- Returns:
Updated cells, field and potential
- Parameters
cells (jax._src.numpy.ndarray.ndarray) –
field (jax._src.numpy.ndarray.ndarray) –
potential (jax._src.numpy.ndarray.ndarray) –
shift_idx (jax._src.numpy.ndarray.ndarray) –
axes (Tuple[int, ...]) –
- Return type
Tuple[jax._src.numpy.ndarray.ndarray, jax._src.numpy.ndarray.ndarray, jax._src.numpy.ndarray.ndarray]
- leniax.utils.crop_zero(kernels)[source]
Crop zero values out for 3 and 4 dimensions array
- Parameters
kernels (jax._src.numpy.ndarray.ndarray) – A 3 or 4 dimension kernels
- Returns
The croppped kernels
- Return type
jax._src.numpy.ndarray.ndarray
- leniax.utils.auto_center(cells)[source]
Automatically center cells on its total mass centroid
- Parameters
cells (jax._src.numpy.ndarray.ndarray) – Lenia state
- Returns
The mass centered Lenia state
- Return type
jax._src.numpy.ndarray.ndarray
- leniax.utils.center_and_crop(cells)[source]
Automatically center cells on its total mass centroid and crop zeros values
- Parameters
cells (jax._src.numpy.ndarray.ndarray) – Lenia state
- Returns
The mass centered cropped Lenia state
- Return type
jax._src.numpy.ndarray.ndarray
- leniax.utils.get_image(cells_buffer, pixel_size, colormap)[source]
Convert a numpy array into a PIL image
- Parameters
cells_buffer (numpy.ndarray) – A Lenia state of shape
[C, world_dims...]pixel_size (int) – Size of each state pixels in the image
colormap – A matplotlib compatible colormap
- Returns
A PIL image
- Return type
<module ‘PIL.Image’ from ‘/home/docs/checkouts/readthedocs.org/user_builds/leniax/envs/stable/lib/python3.7/site-packages/PIL/Image.py’>
- leniax.utils.plot_stats(save_dir, stats_dict)[source]
Plot Leniax statistics
- Parameters
save_dir (str) – directory used to save assets.
stats_dict (Dict) – Statistics dictionnary
- leniax.utils.generate_beta_faces(nb_betas, denominator)[source]
- Generate a grid of all the valid beta values given a maximum number
of beta values.
This function makes sense only if we normalize our kernels.
- Parameters
nb_betas (int) – Maximum number of betas values
denominator (int) – Denominator to construct the betas grid
- Returns
The list of possible list of beta values
- Return type
List[List[List[float]]]
- leniax.utils.check_dir(dir)[source]
Ensure a directory exist and is not a file
- Parameters
dir (str) – Checked directory
- leniax.utils.save_config(save_dir, config)[source]
Save a configuration file
- Parameters
save_dir (str) – directory used to save assets.
config (Dict) – Leniax configuration
- leniax.utils.print_config(config)[source]
Pretty print a Leniax configuration
- Parameters
config (Dict) – Leniax configuration
- leniax.utils.load_img(fullpath, resize)[source]
Load an image as a np.array
- Parameters
fullpath (str) – Absolute image path
resize (Tuple[int, int]) – Resize factors for the image dimensions
- Returns
The image as a np.array
- Return type
jax._src.numpy.ndarray.ndarray
- leniax.utils.set_log_level(config)[source]
Set the python logging root level
- Parameters
config (Dict) – Leniax configuration
- leniax.utils.seed_everything(seed)[source]
Seed all the depedencies used by Leniax
- Parameters
seed (int) – A seed integer
- Returns
A JAX PRNG key
- Return type
jax._src.prng.PRNGKeyArray
- leniax.utils.get_needed_memory(config, nb_sols=1)[source]
Compute an approximate of the needed memory by different kind of simulations
- Parameters
config (Dict) – Leniax configuration
nb_sols (int) – How many solutions will be simulated at the same time
- Returns
A dictionnary witth different memory requirements