openelm.environments package
OpenELM Environments module
- class openelm.environments.environments.ArrayGenotype(input_array)[source]
Bases:
Genotype,ndarray
- class openelm.environments.environments.BaseEnvironment[source]
Bases:
ABC,Generic[GenoType]- property behavior_ndim: int
- property behavior_space: ndarray
- property max_fitness: int
- class openelm.environments.environments.FunctionOptim(ndim=2)[source]
Bases:
BaseEnvironment[ArrayGenotype]- mutate(x)[source]
- Return type:
list[ArrayGenotype]
- random()[source]
- Return type:
list[ArrayGenotype]
- class openelm.environments.environments.ImageGeneration(program_str, result_obj)[source]
Bases:
GenotypeGenotype for generated images.
- class openelm.environments.environments.ImageOptim(seed, config, target_img, diff_model, behavior_mode='3-channel', run_name=None)[source]
Bases:
BaseEnvironment[ImageGeneration]Mutate programs that return images.
Fitness is simply the absolute difference between the returning image and the target image. To map into the behavior space, if behavior_mode==”3-channel”, the image will be divided into blocks (specified in block_size), and average values of RGB channels in each block will be put together as a point in the behavior space (average-pooling).
- __init__(seed, config, target_img, diff_model, behavior_mode='3-channel', run_name=None)[source]
Mutate programs that return images.
Fitness is simply the absolute difference between the returning image and the target image. To map into the behavior space, if behavior_mode==”3-channel”, the image will be divided into blocks (specified in block_size), and average values of RGB channels in each block will be put together as a point in the behavior space (average-pooling).
- Parameters:
seed (
dict) – the seed dict.config (
Union[str,dict,DictConfig]) – the config file path or dict.target_img (
ndarray) – the target image.diff_model – the diff model (or alternatives).
behavior_mode (
str) – (Optional) a string indicating the way an individualspace. (is mapped into behavior) –
run_name (
Optional[str]) – (Optional) override the run_name in config.
- behavior_mode_spec = {'3-channel-avg': {'genotype_ndim': 3}}
- default_diff_model_cls
alias of
PromptMutationForImgTask
- generate_program(code_batch)[source]
Call LM to generate a new program and run it.
- Return type:
list[ImageGeneration]- Returns:
An ImageGeneration object containing the code, the resulting image and the error code.
- mutate(images_list)[source]
Randomly mutate a batch of codes and evaluate their outputs.
- Parameters:
x – the individual to be mutated.
- Return type:
list[ImageGeneration]- Returns:
a tuple of the code string and the returning result (None if there is an error).
- random()[source]
Randomly generate a batch of codes and evaluate their outputs.
- Return type:
list[ImageGeneration]- Returns:
a tuple of the code string and the returning result (None if there is error).
- class openelm.environments.environments.MatchString(target)[source]
Bases:
BaseEnvironment[StringArrayGenotype]- mutate(x)[source]
- Return type:
list[StringArrayGenotype]
- random()[source]
- Return type:
list[StringArrayGenotype]
- class openelm.environments.environments.Sodarace(seed, config, diff_model, eval_ms, max_height=1000, max_width=1000, max_mass=2000, ndim=3, run_name=None)[source]
Bases:
BaseEnvironment[Sodaracer]- __init__(seed, config, diff_model, eval_ms, max_height=1000, max_width=1000, max_mass=2000, ndim=3, run_name=None)[source]
Sodarace environment.
- Parameters:
seed (
dict) – the seed dict.config (
Union[str,dict,DictConfig,BaseConfig]) – the config file path or dict.diff_model – the diff model (or alternatives).
eval_ms (
int) – The time in ms for sodaracer evaluation.max_height (
int) – (Optional) the maximal height.max_width (
int) – (Optional) the maximal width.max_mass (
int) – (Optional) the maximal mass.ndim (
int) – (Optional) the dimension of behavior space.run_name (
Optional[str]) – (Optional) override the run_name in config.
- default_diff_model_cls
alias of
PromptMutationForSodarace
- class openelm.environments.environments.Sodaracer(program_str, result_obj)[source]
Bases:
Genotype- __init__(program_str, result_obj)[source]
The Sodaracer genotype.
- Parameters:
program_str (
str) – the string for the original code.result_obj (
dict) – the dict of sodaracer.
- property fitness: Optional[float]
- class openelm.environments.environments.StringArrayGenotype(input_array)[source]
Bases:
ArrayGenotype