Skip to content

Evolve

The evolve block ties everything together - it is the “run” button that tells the engine which body, world, perception, action, and fitness definition to use, and how many generations to run. Every other construct is just a definition until an evolve block references it. You can have multiple evolve blocks in a project to run different experiments with different configurations, selecting between them via the --run flag.

A Quale project is either a single file or a directory of .quale files.

Terminal window
quale evolve experiment.quale -- single file
quale evolve my_experiment/ -- directory (all .quale files merged)
quale check experiment.quale -- validate without running
quale inspect checkpoint.quale-ckpt -- inspect evolved topology

Every .quale file contains one or more of these constructs:

body <Name> { ... } -- Agent state layout and brain interface
world <Name> { ... } -- Simulation environment with entities
perception <Name> { ... } -- World/agent state to brain sensor values
action <Name> { ... } -- Brain actuator outputs to world changes
dynamics <Name> { ... } -- Per-tick state cascade rules
fitness <Name> { ... } -- Gates, metrics, and optimization objectives
evolve <Name> { ... } -- Evolution experiment configuration

Configures the evolution experiment. References all named constructs. Machines are automatically included via their parent body or world blocks.

evolve HumanFactorsDemo {
body: Operator
world: OperatorRoute
perception: OperatorSenses
action: OperatorActions
fitness: OperatorAssessment
dynamics: OperatorPhysiology
population: 200
generations: 1000
scenarios: 3
ticks: 6000
seed: 42
agents: 1
}

Block references (link the experiment to its component definitions):

FieldRequiredDescription
bodyYesReference to a body definition (includes agent machines)
worldYesReference to a world definition (includes world machines and entities)
perceptionYesReference to a perception definition
actionYesReference to an action definition
fitnessYesReference to a fitness definition
dynamicsNoReference to a dynamics definition

Experiment parameters:

FieldTypeDefaultDescription
populationint200Genomes in the population
generationsint5000Maximum generations
scenariosint5Random scenarios per evaluation
ticksint300Steps per scenario
seedintrandomRandom seed (0 = rand.Uint64() from Go’s auto-seeded global RNG)
agentsint1Brain instances per scenario (1 or 2)
seed_fromstringnoneSeed population from a previous checkpoint path

Optional sub-blocks:

Sub-blockDescription
mutation { ... }Mutation rate configuration
speciation { ... }Speciation parameters
convergence { ... }Convergence (early stop) criteria
checkpoint { ... }Checkpoint save configuration

The dynamics field is optional. The Network Security demo omits it entirely since the IDS agent has no physiological state that changes over time independent of actions.

The compiler validates that all blocks are consistent:

  • Perception sensor assignments match body sensor declarations
  • Action actuator reads match body actuator declarations
  • Perception and action spatial query calls match world query declarations
  • All agent.* references across all blocks match body state declarations
  • Fitness record references match record types emitted by entity interaction handlers
  • Machine scope visibility rules are enforced

The evolve block supports optional sub-blocks for fine-tuning evolution parameters. These have sensible defaults and can be omitted.

evolve Tuned {
body: Operator
world: OperatorRoute
perception: OperatorSenses
action: OperatorActions
fitness: OperatorAssessment
dynamics: OperatorPhysiology
population: 300
generations: 2000
scenarios: 5
ticks: 6000
seed: 42
agents: 1
mutation {
weight_shift: 0.8
bias_shift: 0.5
add_connection: 0.15
remove_connection: 0.05
add_node: 0.03
remove_node: 0.01
rewire: 0.02
change_activation: 0.02
}
speciation {
threshold: 3.0
target_species: 15
stagnation: 25 generations
}
convergence {
plateau: 200 generations
threshold: 0.001
}
checkpoint {
every: 1 generations
keep: 99999
}
}

Controls the probability of each mutation type per offspring.

FieldTypeDefaultDescription
weight_shiftfloat0.8Probability of perturbing a connection weight
bias_shiftfloat0.5Probability of perturbing a node bias
add_connectionfloat0.15Probability of adding a new connection
remove_connectionfloat0.05Probability of removing an existing connection
add_nodefloat0.03Probability of splitting a connection with a new hidden node
remove_nodefloat0.01Probability of removing a hidden node
rewirefloat0.02Probability of moving one end of a connection
change_activationfloat0.02Probability of changing a node’s activation function

Controls how the population is divided into species for diversity preservation.

FieldTypeDefaultDescription
thresholdfloat3.0Compatibility distance threshold for same-species membership
target_speciesint15Target number of species (threshold auto-adjusts toward this)
stagnationint + unit25 generationsGenerations without improvement before a species is dissolved

Controls when evolution stops automatically.

FieldTypeDefaultDescription
plateauint + unit200 generationsGenerations without global fitness improvement before stopping
thresholdfloat0.001Minimum improvement delta to count as progress

Controls how checkpoints are saved during evolution.

FieldTypeDefaultDescription
everyint + unit1 generationSave a checkpoint every N generations
keepint99999Maximum number of checkpoints to retain on disk

Seeds the initial population from a previous experiment’s checkpoint.

evolve Phase2 {
seed_from: "checkpoints/phase1/best.quale-ckpt"
...
}

-- Line comment
--! Note
--!! Critical note
--[ Block comment
can span multiple lines ]--
SyntaxTypeBehavior
--Line commentDiscarded by the parser
--!NotePreserved in AST; shown by quale check
--!!CriticalPreserved in AST; fails quale check --strict
--[ ... ]--Block commentMulti-line; discarded by the parser

The simulation tick loop is defined by the blocks referenced in the evolve block:

StepSourceDescription
1World machinesscope: world machines update world state
2PerceptionTransforms world + agent state into brain sensor values
3Brain firesSignal propagation through the connectome (engine, fixed)
4ActionInterprets actuator outputs through physics, moves agent, triggers entity interactions
5Agent machinesscope: agent machines handle state transitions
6DynamicsPer-tick state cascade (fatigue, stress, boredom)
7AccumulatorsPer-tick fitness metric running sums (engine, automatic)

Terminal window
-- Run evolution
quale evolve experiment.quale
quale evolve experiment.quale --seed 123 -- override seed
quale evolve experiment.quale --run Phase2 -- specific evolve block
quale evolve experiment.quale --resume checkpoints/checkpoint_gen100.quale-ckpt
-- Validate without running
quale check experiment.quale
-- Inspect checkpoint
quale inspect checkpoint.quale-ckpt
-- Directory projects (all .quale files merged)
quale evolve my_experiment/
quale check my_experiment/