discrete_generation_population Module
Discrete generation population simulation model.
Overview
The discrete_generation_population module provides a population implementation
without age structure, suitable for simulations that evolve in whole-generation
steps.
Complete Module Reference
natal.discrete_generation_population
Discrete-generation population model.
This module provides a lightweight non-overlapping generation model that keeps n_ages=2: - age 0: offspring/zygotes produced in current tick - age 1: reproducing adults
The simulation flow remains split as: first hook -> reproduction -> early hook -> survival -> late hook -> aging
DiscreteGenerationPopulation
DiscreteGenerationPopulation(species: Species, population_config: PopulationConfig, name: Optional[str] = None, initial_individual_count: Optional[Dict[str, Dict[Union[Genotype, str], Union[List[int], Dict[int, int], int, float]]]] = None, hooks: Optional[Dict[str, List[Tuple[Any, Optional[str], Optional[int]]]]] = None)
Bases: BasePopulation[DiscretePopulationState]
Population with strict non-overlapping generations.
Maintains exactly two age classes: - age 0: newly produced offspring - age 1: reproducing adults
Attributes:
| Name | Type | Description |
|---|---|---|
state |
DiscretePopulationState
|
Current discrete population state. |
config |
PopulationConfig
|
Active normalized configuration with two-age layout. |
history |
List[Tuple[int, ndarray]]
|
Flattened snapshots indexed by tick. |
Source code in src/natal/discrete_generation_population.py
setup
classmethod
setup(species: Species, name: str = 'DiscreteGenerationPop', stochastic: bool = True, use_continuous_sampling: bool = False, use_fixed_egg_count: bool = False) -> DiscreteGenerationPopulationBuilder
Create and preconfigure a discrete-generation population builder.
This is a convenience forwarding entry point. Parameter semantics and
defaults are the same as DiscreteGenerationPopulationBuilder.setup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
species
|
Species
|
Species definition used to initialize the builder. |
required |
name
|
str
|
Population name passed through to |
'DiscreteGenerationPop'
|
stochastic
|
bool
|
Whether to use stochastic sampling. Passed through to |
True
|
use_continuous_sampling
|
bool
|
If True, use Dirichlet; else Binomial/Multinomial sampling.
Passed through to |
False
|
use_fixed_egg_count
|
bool
|
If True, egg count is fixed; if False, Poisson distributed.
Passed through to |
False
|
Returns:
| Type | Description |
|---|---|
DiscreteGenerationPopulationBuilder
|
A configured |
Examples:
DiscreteGenerationPopulation.setup(species).initial_state(...).build()
Source code in src/natal/discrete_generation_population.py
run
run(n_steps: int = 1, record_every: Optional[int] = None, finish: bool = False, clear_history_on_start: bool = False) -> DiscreteGenerationPopulation
Run multi-step evolution using optimized simulation kernels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_steps
|
int
|
Number of steps to evolve. |
1
|
record_every
|
Optional[int]
|
Interval for recording snapshots. If None, uses self.record_every. If 0, no snapshots are recorded. |
None
|
finish
|
bool
|
Whether to mark the population as finished after the run. |
False
|
clear_history_on_start
|
bool
|
Whether to clear existing history before starting. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
DiscreteGenerationPopulation |
DiscreteGenerationPopulation
|
Self for chaining. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the population is already finished and cannot continue. |
Source code in src/natal/discrete_generation_population.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
run_tick
Execute a single simulation tick.
Overrides BasePopulation.run_tick to use the accelerated run() pipeline which correctly handles compiled hooks.
Source code in src/natal/discrete_generation_population.py
reset
Reset the population to its initial state.
Source code in src/natal/discrete_generation_population.py
export_state
Export the current state and optional history.
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
A tuple of |
Optional[NDArray[float64]]
|
tick and individual counts, and |
Tuple[NDArray[float64], Optional[NDArray[float64]]]
|
stacked history array. |
Source code in src/natal/discrete_generation_population.py
export_config
Export the current population configuration.
Returns:
| Type | Description |
|---|---|
PopulationConfig
|
The active |
import_config
Import a population configuration into the discrete model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PopulationConfig
|
Configuration object to install. |
required |
Source code in src/natal/discrete_generation_population.py
import_state
import_state(state: Union[DiscretePopulationState, NDArray[float64], Dict[str, ndarray]], history: Optional[NDArray[float64]] = None) -> None
Import state and optional history records.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Union[DiscretePopulationState, NDArray[float64], Dict[str, ndarray]]
|
|
required |
history
|
Optional[NDArray[float64]]
|
Optional 2D history array previously returned by |
None
|