Configuration
Configuration
FinchGE can be configured using plain Python dictionaries or external configuration files (INI or YAML). FinchGE uses a structured configuration system to describe experiments in a clear, reproducible, and extensible way.
Principle
FinchGE follows these principles for project configuration:
- FinchGE configuration is explicit, modular, and optional
- Users can choose between:
- programmatic configuration (Python dicts)
- file-based configuration (INI / YAML)
- Configuration can be copied and modified, enabling adaptive or meta-evolutionary experiments.
Configuration Overview
The configuration is centered around three top-level sections:
experiment- run-level concerns (how long, how big, logging, caching, randomness)ge- all Grammatical Evolution-specific parameters (grammar, initialisation, operators)parallel- configuration related to parallelised fitness evaluation.
This design avoids artificial separation between tightly coupled GE components (grammar, initialisation, operators) and ensures consistent parameter sharing.
The experiment section controls how an experiment is executed.
Typical parameters include:
random_seed- global seed for reproducibilitypopulation_size- number of individualsnum_generations- evolution lengthverbose- logging verbositycache_type,cache_size- optional fitness caching
The ge section defines the Grammatical Evolution system itself.
Typical parameters include:
-
Grammar and mapping:
grammar_filecodon_sizemax_wrapsmax_recursion_depthgenome_length
-
Initialisation:
init_type(e.g.random_genome,pi_grow,rhh)min_depth,max_depth(tree-based initialisers)
- Operators:
mutation_probabilitycrossover_probabilityelite_size
All GE components (grammar, mapper, initialisers, operators) read from this same ge section, ensuring consistency.
The parallel section defines the configuration related to parallelization of the fitness evaluation.
The parameters include:
parallel_enabled- flag to enable/disable parallel evaluationexecutor_type-threadorprocessmax_workersbatch_size
Example Configuration in YAML and INI
The algorithm supports two distinct operational modes based on the presence of structural constraints.
YAML example:
experiment:
random_seed: 42
num_generations: 200
verbose: true
cache_type: lru
cache_size: 128
ge:
population_size: 100
grammar_file: grammar.bnf
codon_size: 127
max_wraps: 6
max_recursion_depth: 20
genome_length: 100
init_type: pi_grow
max_depth: 6
mutation_probability: 0.01
crossover_probability: 0.5
elite_size: 1
parallel:
parallel_enabled: true
executor_type: process
max_workers: 4
batch_size: 25
INI example:
[experiment]
random_seed = 42
num_generations = 200
verbose = true
cache_type = "lru"
cache_size = 128
[ge]
population_size = 100
grammar_file = grammar.bnf
codon_size = 127
max_wraps = 6
max_recursion_depth = 20
genome_length = 100
init_type = pi_grow
max_depth = 6
mutation_probability = 0.01
crossover_probability = 0.5
elite_size = 1
[parallel]
parallel_enabled = true
executor_type = process
max_workers = 4
batch_size = 25
Required vs Optional Parameters
FinchGE distinguishes between two kinds of configuration parameters to ensure both safety and flexibility.
Required (no defaults)
Structural parameters that define the problem space and evolutionary system:
population_sizegrammar_filecodon_sizegenome_length
Missing required parameters raise immediate errors to prevent silent misconfiguration and undefined behavior.
Optional (safe defaults)
Behavioral or convenience parameters that influence execution but have sensible defaults:
cache_sizeverboseelite_size
Defaults are documented and consistently applied across the library.
Loading Configuration with FinchConfig
FinchGE provides an optional helper class, FinchConfig, for loading and managing configuration files.
The file format is detected automatically based on extension (.ini, .yaml, .yml).
Configuration sections are accessed as dictionaries:
Note: FinchConfig is a convenience layer.
FinchGE classes also accept configs in the form of plain Python dictionaries.
Using dictionary as config
For notebooks or scripts, we can bypass FinchConfig entirely
by creating configs in the form of dictionaries, as shown below.
config = {
"experiment": {
"random_seed": 42,
"num_generations": 10,
"verbose": True,
"cache_type": "lru",
"cache_size": 128,
},
"ge": {
"population_size": 100,
"grammar_file": "grammar.bnf",
"codon_size": 127,
"max_wraps": 6,
"max_recursion_depth": 10,
"genome_length": 100,
"init_type": "random_genome",
"mutation_probability": 0.01,
"crossover_probability": 0.5,
"elite_size": 3,
},
"parallel": {
"parallel_enabled": True,
"executor_type": "process",
"max_workers": 4,
"batch_size": 25,
},
}
Configuration Copying and Adaptation
FinchConfig supports copying with updates, which is useful for:
- parameter control
- self-adaptive strategies
- experiment branching
Inspecting Configuration
For logging and debugging, configurations can be rendered in multiple formats:
This makes experiments easy to reproduce and compare.