βš™οΈ Configurations

Configuration models and registries for simulator components.

βš›οΈ Roots

Reusable root configuration types for simulation parameters and source.

class phyloom.configs.roots.ContextCfg(*, root: dict[str, DistributionCfg | NumPyExpressionCfg] = {})[source]

Bases: RootModel[dict[str, DistributionCfg | NumPyExpressionCfg]]

Configuration for the sample-specific context variables.

For every sample, the context is materialized into sample-specific parameter values: each entry is either drawn from its prior distribution or evaluated as an expression, such as a fixed constant or a quantity derived from earlier entries.

materialize(rng: Generator) → Context[source]

Materialize the sample-specific values, evaluating or drawing each entry in order.

class phyloom.configs.roots.DistributionCfg(*, type: StrCfg)[source]

Bases: BaseModel

Configuration for a context variable drawn from a prior distribution.

Parameters:
  • type – Name of the numpy.random.Generator distribution method, such as "uniform", "lognormal", or "integers".

  • **extra_data – Keyword arguments accepted by that NumPy distribution method.

draw(context: Context, rng: Generator) → object[source]

Draw a sample from the distribution, evaluating any extra data from materialized context values.

class phyloom.configs.roots.ExpressionCfg(*, root: str)[source]

Bases: RootModel[str]

Base configuration for a Python expression that produces a value.

The expression is syntax-checked during validation and evaluated later, during a simulation. It sees the materialized context, numpy as np, and the keyword bindings passed to evaluate() or evaluate_typed(), which take precedence over context names. Subclasses implement contextualize to return a function that evaluates the expression each time it is called. The source is not sandboxed, so configuration input must be trusted.

evaluate(context: Context, **bindings: object) → object[source]

Evaluate the expression and return its raw value.

evaluate_typed(context: Context, typeguard: NamedTypeguard[T], **bindings: object) → T[source]

Evaluate the expression and check its type.

NumPy results are converted to plain Python values before the value is checked with typeguard.

class phyloom.configs.roots.FloatCfg(*, root: NumPyExpressionCfg)[source]

Bases: RootModel[NumPyExpressionCfg]

Configuration for a float-valued NumPy expression.

contextualize(context: Context) → float[source]

Evaluate the expression to a float from materialized context values.

class phyloom.configs.roots.FloatSequenceCfg(*, root: NumPyExpressionCfg | Sequence[FloatCfg])[source]

Bases: RootModel[NumPyExpressionCfg | Sequence[FloatCfg]]

Configuration for a sequence of floats.

The sequence is given either as a list of float-valued expressions or as a single NumPy expression that evaluates to a sequence of floats.

contextualize(context: Context) → Sequence[float][source]

Evaluate the expression, or each of its elements, to a sequence of floats from materialized context values.

class phyloom.configs.roots.IntCfg(*, root: NumPyExpressionCfg)[source]

Bases: RootModel[NumPyExpressionCfg]

Configuration for an integer-valued NumPy expression.

contextualize(context: Context) → int[source]

Evaluate the expression to an integer from materialized context values.

class phyloom.configs.roots.ModelActionCfg(*, root: str)[source]

Bases: StatementCfg

Configuration for statements acting on the current model.

contextualize(context: Context) → Callable[[Any], None][source]

Return a function of model that runs the source.

class phyloom.configs.roots.ModelExpressionCfg(*, root: str)[source]

Bases: ExpressionCfg

Configuration for an expression of the current model with any result.

contextualize(context: Context) → Callable[[Any], object][source]

Return a function of model that runs the source.

class phyloom.configs.roots.ModelPredicateCfg(*, root: str)[source]

Bases: ExpressionCfg

Configuration for a boolean expression of the current model.

contextualize(context: Context) → Callable[[Any], bool][source]

Return a function of model that runs the source.

class phyloom.configs.roots.NonNegativeModelFnCfg(*, root: str)[source]

Bases: ExpressionCfg

Configuration for a non-negative float expression of the current model.

contextualize(context: Context) → Callable[[Any], float][source]

Return a function of model that runs the source.

class phyloom.configs.roots.NonNegativeTimeFnCfg(*, root: str)[source]

Bases: ExpressionCfg

Configuration for a non-negative float expression of the time.

contextualize(context: Context) → Callable[[Any], float][source]

Return a function of time t that runs the source.

class phyloom.configs.roots.NumPyExpressionCfg(*, root: str)[source]

Bases: ExpressionCfg

Configuration for a NumPy expression.

contextualize(context: Context, typeguard: NamedTypeguard[T]) → T[source]
contextualize(context: Context, typeguard: None = None) → object

Evaluate the expression with an optional typeguard check.

class phyloom.configs.roots.OutputHookCfg(*, root: str)[source]

Bases: StatementCfg

Configuration for statements of the current model and the sample’s output directory.

contextualize(context: Context) → Callable[[Any, Any], None][source]

Return a function of model and output_dir that runs the source.

class phyloom.configs.roots.PostCommandCfg(*, root: str)[source]

Bases: RootModel[str]

Configuration for a context-interpolated shell command run on the output directory of a sample.

Interpolation is performed using standard Python string formatting (str.format()), where {name} placeholders matching context variables are replaced with their corresponding values, and the {output_dir} placeholder with the sample’s output directory. The command runs through the system shell and is not sandboxed, so configuration input must be trusted.

run(context: Context, output_dir: Path) → None[source]

Interpolate the command from materialized context values and output_dir, then run it.

class phyloom.configs.roots.StatementCfg(*, root: str)[source]

Bases: RootModel[str]

Base configuration for Python statements run for their side effects.

The statements are syntax-checked during validation and run later, during a simulation. They see the materialized context, numpy as np, and the keyword bindings passed to execute(), which take precedence over context names. Subclasses implement contextualize to return a function that runs the statements each time it is called. The source is not sandboxed, so configuration input must be trusted.

execute(context: Context, **bindings: object) → None[source]

Run the statements.

class phyloom.configs.roots.StrCfg(*, root: str)[source]

Bases: RootModel[str]

Configuration for a context-interpolated string.

Interpolation is performed using standard Python string formatting (str.format()), where {name} placeholders matching context variables are replaced with their corresponding values.

contextualize(context: Context) → str[source]

Interpolate the string from materialized context values.

class phyloom.configs.roots.StrPairCfg(*, root: tuple[StrCfg, StrCfg])[source]

Bases: RootModel[tuple[StrCfg, StrCfg]]

Configuration for a pair of context-interpolated strings.

contextualize(context: Context) → tuple[str, str][source]

Interpolate both strings from materialized context values.

πŸ›‘οΈ Typeguards

Typeguards for type-safe evaluation of Python source code in configuration.

phyloom.configs.roots.typeguards.is_bool(value: object) → TypeGuard[bool][source]

Check if a value is a bool.

phyloom.configs.roots.typeguards.is_int(value: object) → TypeGuard[int][source]

Check if a value is an int (but not a bool).

phyloom.configs.roots.typeguards.is_float(value: object) → TypeGuard[float][source]

Check if a value is a float (or an int, but not a bool).

phyloom.configs.roots.typeguards.is_sequence(value: object) → TypeGuard[Sequence[object]][source]

Check if a value is a sequence (but not a string).

phyloom.configs.roots.typeguards.is_float_sequence(value: object) → TypeGuard[Sequence[float]][source]

Check if a value is a sequence of floats.

class phyloom.configs.roots.typeguards.NamedTypeguard(name: str, fn: Callable[[object], TypeGuard[T]])[source]

Bases: Generic[T]

A typeguard paired with a human-readable name used in error messages.

Parameters:
  • name – Description of the expected type.

  • fn – Function that checks whether a value has the expected type.

phyloom.configs.roots.typeguards.BOOL_TG = NamedTypeguard(name='bool', fn=<function is_bool>)

Typeguard accepting a bool.

phyloom.configs.roots.typeguards.INT_TG = NamedTypeguard(name='int', fn=<function is_int>)

Typeguard accepting an int, but not a bool.

phyloom.configs.roots.typeguards.FLOAT_TG = NamedTypeguard(name='float', fn=<function is_float>)

Typeguard accepting a float or an int, but not a bool.

phyloom.configs.roots.typeguards.FLOAT_SEQUENCE_TG = NamedTypeguard(name='sequence of floats', fn=<function is_float_sequence>)

Typeguard accepting a sequence of floats.

🎲 Hazards

Configuration models for time-dependent event hazards.

class phyloom.configs.hazards.HazardCfgBase[source]

Bases: ABC, BaseModel

Base configuration for a Hazard.

Subclasses declare the hazard parameters as fields and build the runtime hazard from them in contextualize(). Concrete configurations are registered in HAZARD_REGISTRY and selected by their spec key. Hazards do not depend on the model type, so any registered hazard can be combined with any event rule.

abstract contextualize(context: Context) → Hazard[source]

Build the simulator hazard from materialized context values.

phyloom.configs.hazards.HAZARD_REGISTRY: Registry[HazardCfgBase] = Registry(name='Hazard', base_type='HazardCfgBase', keys=['constant', 'delta', 'exponential', 'skyline', 'numeric'])

Registry of concrete hazard configurations keyed by their spec value. It also supplies the validator used by HazardCfg.

type phyloom.configs.hazards.HazardCfg

Hazard configuration type resolved by HAZARD_REGISTRY. Alias for Annotated[ HazardCfgBase, HAZARD_REGISTRY.validator].

class phyloom.configs.hazards.ConstantHazardCfg(*, rate: FloatCfg)[source]

Bases: HazardCfgBase

Configuration for a ConstantHazard with a constant per-opportunity rate.

Registered under "constant" in HAZARD_REGISTRY.

Parameters:

rate – Positive per-opportunity event rate.

contextualize(context: Context) → ConstantHazard[source]

Build the ConstantHazard from materialized context values.

class phyloom.configs.hazards.DeltaHazardCfg[source]

Bases: HazardCfgBase

Configuration for a DeltaHazard that fires immediately at a point mass.

Registered under "delta" in HAZARD_REGISTRY.

contextualize(context: Context) → DeltaHazard[source]

Build the DeltaHazard from materialized context values.

class phyloom.configs.hazards.ExponentialHazardCfg(*, rate: FloatCfg, decay: FloatCfg)[source]

Bases: HazardCfgBase

Configuration for a ExponentialHazard whose rate changes exponentially with time.

Registered under "exponential" in HAZARD_REGISTRY.

Parameters:
  • rate – Positive rate at simulated time zero.

  • decay – Exponential decay or growth parameter. A positive value gives decay, zero gives a constant rate, and a negative value gives growth.

contextualize(context: Context) → ExponentialHazard[source]

Build the ExponentialHazard from materialized context values.

class phyloom.configs.hazards.SkylineHazardCfg(*, rates: FloatSequenceCfg, break_times: FloatSequenceCfg)[source]

Bases: HazardCfgBase

Configuration for a SkylineHazard with piecewise-constant rates.

Registered under "skyline" in HAZARD_REGISTRY.

Parameters:
  • rates – Non-negative per-interval rates, ordered from earliest to latest interval.

  • break_times – Positive, strictly increasing times separating adjacent intervals. Provide one fewer value than rates.

contextualize(context: Context) → SkylineHazard[source]

Build the SkylineHazard from materialized context values.

class phyloom.configs.hazards.NumericHazardCfg(*, rate_fn: NonNegativeTimeFnCfg, max_bracketing_steps: IntCfg = IntCfg(root=NumPyExpressionCfg(root='16')), initial_dt: FloatCfg = FloatCfg(root=NumPyExpressionCfg(root='1.0')))[source]

Bases: HazardCfgBase

Configuration for a NumericHazard whose rate is numerically inverted over time.

Registered under "numeric" in HAZARD_REGISTRY.

Parameters:
  • rate_fn – Expression for the non-negative event rate as a function of simulated time.

  • max_bracketing_steps – Maximum number of interval expansions used to bracket the numerical inversion.

  • initial_dt – Initial interval width used when searching for a bracket.

contextualize(context: Context) → NumericHazard[source]

Build the NumericHazard from materialized context values.

🧱 Core

Core configuration types and registries for simulator models and events.

class phyloom.configs.core.EventRuleCfg[source]

Bases: ABC, BaseModel, Generic[ModelT_contra]

Base configuration for a model-specific EventRule.

Subclasses declare the parameters of an event rule as fields and build the runtime rule from them in contextualize(). Event rules act on a specific model type, so concrete configurations are registered in the event-rule Registry of that model.

abstract contextualize(context: Context) → EventRule[ModelT_contra][source]

Build the simulator event rule from materialized context values.

class phyloom.configs.core.EventCfg(*, rule: RuleCfgT_co, hazard: HazardCfg, rate_multiplier: NonNegativeModelFnCfg | None = None)[source]

Bases: BaseModel, Generic[RuleCfgT_co]

Configuration for a model-specific Event.

Concrete model configurations specialize it with their own registry-backed rule type.

Parameters:
  • rule – Event-rule configuration that determines which state transitions are eligible and how one is applied.

  • hazard – Time-dependent per-opportunity hazard used to sample firing times.

  • rate_multiplier – Optional model expression that scales the event’s overall rate based on the current model state. It must return a non-negative numeric multiplier; zero disables the event.

contextualize(context: Context) → Event[ModelT][source]

Build the Event from materialized context values.

class phyloom.configs.core.ScheduledEventCfg(*, action: ModelActionCfg, times: FloatSequenceCfg)[source]

Bases: BaseModel

Configuration for an action executed at one or more fixed times.

Parameters:
  • action – Model statements run at each scheduled time.

  • times – Non-negative simulated times at which to run the action.

contextualize(context: Context) → list[tuple[float, Callable[[Any], None]]][source]

Build one (time, action) pair per scheduled time from materialized context values.

class phyloom.configs.core.ModelCfgBase[source]

Bases: ABC, BaseModel

Base configuration for a Model.

Subclasses declare the model parameters, together with the model’s events and schedule, as fields and build a new runtime model from them in contextualize(). Concrete configurations are registered in MODEL_REGISTRY and selected by their spec key.

abstract contextualize(context: Context) → Model[source]

Build a simulator model from materialized context values.

phyloom.configs.core.MODEL_REGISTRY: Registry[ModelCfgBase] = Registry(name='Model', base_type='ModelCfgBase', keys=[])

Registry of concrete model configurations keyed by their spec value. It also supplies the validator used by ModelCfg.

type phyloom.configs.core.ModelCfg

Model configuration type resolved by MODEL_REGISTRY. Alias for Annotated[ ModelCfgBase, MODEL_REGISTRY.validator].

🌱 BDSH

Configuration models and event rules for BDSH simulations.

phyloom.configs.bdsh.BDSH_EVENT_RULE_REGISTRY: Registry[EventRuleCfg[BDSHModel]] = Registry(name='BDSH event rule', base_type='EventRuleCfg[BDSHModel]', keys=['birth', 'death', 'migration', 'sampling', 'ldh', 'lnh', 'lgh'])

Registry of concrete BDSH event-rule configurations keyed by their spec value. It also supplies the validator used by BDSHEventRuleCfg.

type phyloom.configs.bdsh.BDSHEventRuleCfg

BDSH event-rule configuration type resolved by BDSH_EVENT_RULE_REGISTRY. Alias for Annotated[ EventRuleCfg, BDSH_EVENT_RULE_REGISTRY.validator].

class phyloom.configs.bdsh.BirthCfg(*, parent_state: StrCfg | None = None, child_states: tuple[StrCfg | None, StrCfg | None] = (None, None))[source]

Bases: EventRuleCfg[BDSHModel]

Configuration for a Birth event that replaces one active lineage with two descendants.

Registered under "birth" in BDSH_EVENT_RULE_REGISTRY.

Parameters:
  • parent_state – Optional state restricting eligible parent lineages.

  • child_states – Optional pair of states assigned to the descendant lineages. A None entry inherits the parent’s state.

contextualize(context: Context) → Birth[source]

Build the Birth event rule from materialized context values.

class phyloom.configs.bdsh.DeathCfg(*, state: StrCfg | None = None)[source]

Bases: EventRuleCfg[BDSHModel]

Configuration for a Death event that finalizes one active lineage without sampling it.

Registered under "death" in BDSH_EVENT_RULE_REGISTRY.

Parameters:

state – Optional state restricting eligible lineages.

contextualize(context: Context) → Death[source]

Build the Death event rule from materialized context values.

class phyloom.configs.bdsh.MigrationCfg(*, source_state: StrCfg, target_state: StrCfg)[source]

Bases: EventRuleCfg[BDSHModel]

Configuration for a Migration event that replaces one active lineage with a continuing child.

Registered under "migration" in BDSH_EVENT_RULE_REGISTRY.

Parameters:
  • source_state – State restricting eligible parent lineages.

  • target_state – State assigned to the child lineage.

contextualize(context: Context) → Migration[source]

Build the Migration event rule from materialized context values.

class phyloom.configs.bdsh.SamplingCfg(*, removal: bool, state: StrCfg | None = None)[source]

Bases: EventRuleCfg[BDSHModel]

Configuration for a Sampling event that records one eligible active lineage.

Registered under "sampling" in BDSH_EVENT_RULE_REGISTRY.

Parameters:
  • state – Optional state restricting eligible lineages.

  • removal – Whether to end the sampled lineage. If False, the lineage first branches; one descendant is recorded as the sample at the current time, and the other remains active.

contextualize(context: Context) → Sampling[source]

Build the Sampling event rule from materialized context values.

class phyloom.configs.bdsh.LDHCfg(*, parent_states: StrPairCfg | None = None, hybrid_state: StrCfg | None = None)[source]

Bases: EventRuleCfg[BDSHModel]

Configuration for a LDH (lineage-degenerative hybridization) event that replaces two active lineages with one hybrid child.

Registered under "ldh" in BDSH_EVENT_RULE_REGISTRY.

Parameters:
  • parent_states – Optional pair of states restricting the two parent lineages.

  • hybrid_state – Optional state assigned to the hybrid child. If omitted, the parents must share the same state, which the child inherits.

contextualize(context: Context) → LDH[source]

Build the LDH event rule from materialized context values.

class phyloom.configs.bdsh.LNHCfg(*, continuing_parent_state: StrCfg | None = None, terminating_parent_state: StrCfg | None = None, new_parent_state: StrCfg | None = None, hybrid_state: StrCfg | None = None)[source]

Bases: EventRuleCfg[BDSHModel]

Configuration for a LNH (lineage-neutral hybridization) event.

Registered under "lnh" in BDSH_EVENT_RULE_REGISTRY.

Parameters:
  • continuing_parent_state – Optional state restricting the primary (birth-giving) parent lineage.

  • terminating_parent_state – Optional state restricting the secondary (hybridizing) parent lineage.

  • new_parent_state – Optional state assigned to the continuing primary (birth-giving) parent lineage. If omitted, the continuing lineage inherits the parent’s state.

  • hybrid_state – Optional state assigned to the resulting hybrid lineage. If omitted, the parents must share the same state, which the child inherits.

contextualize(context: Context) → LNH[source]

Build the LNH event rule from materialized context values.

class phyloom.configs.bdsh.LGHCfg(*, parent_states: StrPairCfg | None = None, hybrid_state: StrCfg | None = None, new_parent_states: tuple[StrCfg | None, StrCfg | None] = (None, None))[source]

Bases: EventRuleCfg[BDSHModel]

Configuration for a LGH (lineage-generative hybridization) event.

Registered under "lgh" in BDSH_EVENT_RULE_REGISTRY.

Parameters:
  • parent_states – Optional pair of states restricting the two parent lineages.

  • hybrid_state – Optional state assigned to the resulting hybrid lineage. If omitted, the parents must share the same state, which the child inherits.

  • new_parent_states – Optional pair of states assigned to the continuing parent lineages, in the same order as parent_states. A None entry inherits the parent’s state.

contextualize(context: Context) → LGH[source]

Build the LGH event rule from materialized context values.

class phyloom.configs.bdsh.BDSHModelCfg(*, init_state: StrCfg, events: tuple[EventCfg[BDSHEventRuleCfg], ...] = (), schedule: tuple[ScheduledEventCfg, ...] = ())[source]

Bases: ModelCfgBase

Configuration for a BDSHModel.

Registered under "bdsh" in MODEL_REGISTRY. Each event selects its rule by spec from BDSH_EVENT_RULE_REGISTRY.

Parameters:
  • init_state – State assigned to the initial active lineage.

  • events – Stochastic events governing continuous-time state transitions.

  • schedule – Deterministic actions executed at configured simulated times. Actions scheduled for the same time are shuffled before execution.

contextualize(context: Context) → BDSHModel[source]

Build the BDSHModel from materialized context values.

πŸ”— Coalescent

Configuration models and event rules for coalescent simulations.

phyloom.configs.coalescent.COALESCENT_EVENT_RULE_REGISTRY: Registry[EventRuleCfg[CoalescentModel]] = Registry(name='Coalescent event rule', base_type='EventRuleCfg[CoalescentModel]', keys=['retrace', 'coalesce'])

Registry of concrete coalescent event-rule configurations keyed by their spec value. It also supplies the validator used by CoalescentEventRuleCfg.

type phyloom.configs.coalescent.CoalescentEventRuleCfg

Coalescent event-rule configuration type resolved by COALESCENT_EVENT_RULE_REGISTRY. Alias for Annotated[ EventRuleCfg, COALESCENT_EVENT_RULE_REGISTRY.validator].

class phyloom.configs.coalescent.RetraceCfg(*, ancestral_state: StrCfg, current_state: StrCfg | None = None)[source]

Bases: EventRuleCfg[CoalescentModel]

Configuration for a Retrace event that replaces one active lineage with an ancestral parent.

Registered under "retrace" in COALESCENT_EVENT_RULE_REGISTRY.

Parameters:
  • ancestral_state – State assigned to the new parent.

  • current_state – Optional state restricting eligible lineages.

contextualize(context: Context) → Retrace[source]

Build the Retrace event rule from materialized context values.

class phyloom.configs.coalescent.CoalesceCfg(*, current_states: StrPairCfg | None = None, ancestral_state: StrCfg | None = None)[source]

Bases: EventRuleCfg[CoalescentModel]

Configuration for a Coalesce event that replaces two active lineages with one ancestral parent.

Registered under "coalesce" in COALESCENT_EVENT_RULE_REGISTRY.

Parameters:
  • current_states – Optional pair of states restricting the child pair.

  • ancestral_state – Optional state assigned to the ancestral parent. If omitted, the child lineages must share the same state, which the parent inherits.

contextualize(context: Context) → Coalesce[source]

Build the Coalesce event rule from materialized context values.

class phyloom.configs.coalescent.CoalescentModelCfg(*, init_population: dict[str, IntCfg], events: tuple[EventCfg[CoalescentEventRuleCfg], ...] = (), schedule: tuple[ScheduledEventCfg, ...] = ())[source]

Bases: ModelCfgBase

Configuration for a CoalescentModel.

Registered under "coalescent" in MODEL_REGISTRY. Each event selects its rule by spec from COALESCENT_EVENT_RULE_REGISTRY.

Parameters:
  • init_population – Positive number of initial active lineages for each state.

  • events – Stochastic events governing continuous-time state transitions.

  • schedule – Deterministic actions executed at configured simulated times. Actions scheduled for the same time are shuffled before execution.

contextualize(context: Context) → CoalescentModel[source]

Build the CoalescentModel from materialized context values.

🦠 Epidemic

Configuration models and event rules for compartmental epidemic simulations.

phyloom.configs.epidemic.EPIDEMIC_EVENT_RULE_REGISTRY: Registry[EventRuleCfg[EpidemicModel]] = Registry(name='Epidemic event rule', base_type='EventRuleCfg[EpidemicModel]', keys=['infection', 'recovery', 'migration', 'flow'])

Registry of concrete epidemic event-rule configurations keyed by their spec value. It also supplies the validator used by EpidemicEventRuleCfg.

type phyloom.configs.epidemic.EpidemicEventRuleCfg

Epidemic event-rule configuration type resolved by EPIDEMIC_EVENT_RULE_REGISTRY. Alias for Annotated[ EventRuleCfg, EPIDEMIC_EVENT_RULE_REGISTRY.validator].

class phyloom.configs.epidemic.InfectionCfg(*, recipient_pool: StrCfg, source_state: StrCfg | None = None, child_states: tuple[StrCfg | None, StrCfg | None] = (None, None))[source]

Bases: EventRuleCfg[EpidemicModel]

Configuration for an Infection event that replaces one active lineage with two descendants and decrements a pool.

Registered under "infection" in EPIDEMIC_EVENT_RULE_REGISTRY.

Parameters:
  • recipient_pool – Pool from which the infected individual is removed.

  • source_state – Optional state used to restrict eligible source lineages.

  • child_states – Optional pair of states assigned to the descendant lineages. A None entry inherits the parent’s state.

contextualize(context: Context) → Infection[source]

Build the Infection event rule from materialized context values.

class phyloom.configs.epidemic.RecoveryCfg(*, destination_pool: StrCfg, source_state: StrCfg | None = None, sample: bool = False)[source]

Bases: EventRuleCfg[EpidemicModel]

Configuration for a Recovery event that finalizes a lineage and increments a pool.

Registered under "recovery" in EPIDEMIC_EVENT_RULE_REGISTRY.

Parameters:
  • destination_pool – Pool that receives the recovered individual.

  • source_state – Optional state restricting eligible lineages.

  • sample – Whether to record the finalized lineage as a sample.

contextualize(context: Context) → Recovery[source]

Build the Recovery event rule from materialized context values.

class phyloom.configs.epidemic.MigrationCfg(*, source_state: StrCfg, target_state: StrCfg)[source]

Bases: EventRuleCfg[EpidemicModel]

Configuration for a Migration event that replaces one active lineage with a continuing child.

Registered under "migration" in EPIDEMIC_EVENT_RULE_REGISTRY.

Parameters:
  • source_state – State restricting eligible parent lineages.

  • target_state – State assigned to the child lineage.

contextualize(context: Context) → Migration[source]

Build the Migration event rule from materialized context values.

class phyloom.configs.epidemic.FlowCfg(*, source_pool: StrCfg, destination_pool: StrCfg)[source]

Bases: EventRuleCfg[EpidemicModel]

Configuration for a Flow event that moves one individual from a source pool to a destination pool.

Registered under "flow" in EPIDEMIC_EVENT_RULE_REGISTRY.

Parameters:
  • source_pool – Pool to decrement.

  • destination_pool – Pool to increment.

contextualize(context: Context) → Flow[source]

Build the Flow event rule from materialized context values.

class phyloom.configs.epidemic.EpidemicModelCfg(*, init_state: StrCfg, init_pools: dict[str, IntCfg], events: tuple[EventCfg[EpidemicEventRuleCfg], ...] = (), schedule: tuple[ScheduledEventCfg, ...] = ())[source]

Bases: ModelCfgBase

Configuration for a EpidemicModel.

Registered under "epidemic" in MODEL_REGISTRY. Each event selects its rule by spec from EPIDEMIC_EVENT_RULE_REGISTRY.

Parameters:
  • init_state – State assigned to the initial infectious lineage.

  • init_pools – Initial non-negative count for each population pool.

  • events – Stochastic events governing continuous-time state transitions.

  • schedule – Deterministic actions executed at configured simulated times. Actions scheduled for the same time are shuffled before execution.

contextualize(context: Context) → EpidemicModel[source]

Build the EpidemicModel from materialized context values.

πŸƒ Runner

Configuration and execution entrypoint for the dataset-generation pipeline.

class phyloom.configs.runner.Runner(*, output_dir: str = 'phyloom-outputs', n_samples: int | dict[str, int] = 1, n_jobs: int = -1, seed: int | None = None, context: ContextCfg = ContextCfg(root={}), model: ModelCfg, max_time: FloatCfg | None = None, stop_criterion: ModelPredicateCfg | None = None, acceptance_criterion: ModelPredicateCfg | None = None, stop_hook: ModelActionCfg | None = None, max_rejections: int | None = None, timeout: float | None = None, logs: dict[str, ModelExpressionCfg] = {}, output_hooks: tuple[OutputHookCfg, ...], post_commands: tuple[PostCommandCfg, ...] = ())[source]

Bases: BaseModel

Entry point for the dataset-generation pipeline.

For every sample, the runner materializes sample-specific values from the context priors, builds and advances a model, evaluates the stopping and acceptance criteria, and records the accepted sample. An unsplit run writes its output to output_dir, and a split run writes each split to output_dir/<split> with the same layout:

  • data/<sample_id>/: the files written by output_hooks and post_commands for each accepted sample;

  • metadata.csv: one row per sample, with its materialized context values, its logs, the number of rejected trials (n_rejections), and the wall-clock run time (total_time);

  • timed_out_contexts.csv and max_rejections_exceeded_contexts.csv: the materialized context values abandoned after a timeout or after too many rejections, if any.

Parameters:
  • output_dir – Root directory for generated data. An unsplit run writes its output directly here; split runs create one subdirectory per split.

  • n_samples – Number of samples, or a mapping from split names to sample counts. Mapping keys name the output split directories.

  • n_jobs – Number of worker processes passed to joblib.Parallel(). -1 uses all available CPUs.

  • seed – Optional seed for the random number generator used to derive per-sample seeds. If None, a non-deterministic seed source is used.

  • context – Priors of the parameters, as named random draws, constants, and derived expressions. Sample-specific values are drawn from these priors, and can be used in the model configuration, stopping and acceptance criteria, logs, hooks and post-commands. Rejected trials are rerun with the same values; values whose trials time out or exceed the maximum rejection threshold are replaced by a new draw from the priors. The values of each accepted sample are recorded in metadata.csv.

  • model – Registered model configuration to materialize for each trial.

  • max_time – Optional inclusive upper bound on simulated time.

  • stop_criterion – Optional model predicate evaluated after each successful simulation step. A true result ends the trial.

  • acceptance_criterion – Optional model predicate evaluated after a trial. A false result rejects the trial and starts another one.

  • stop_hook – Optional model action evaluated after an accepted trial stops.

  • max_rejections – Maximum number of rejected trials permitted for one context. When the limit is exceeded, the context is replaced and recorded in max_rejections_exceeded_contexts.csv in the relevant output directory.

  • timeout – Optional wall-clock limit in seconds for one trial. A timed-out context is replaced and recorded in timed_out_contexts.csv in the relevant output directory.

  • logs – Mapping from metadata column names to model expressions evaluated after an accepted trial. Their results become columns in metadata.csv.

  • output_hooks – Output-hook statements run in order after each accepted trial. They can write files to the sample’s output directory.

  • post_commands – Shell commands run in order, last, after the output hooks of each accepted trial, such as external simulators of sequence or trait evolution that read the files written by the hooks.

run()[source]

Generate samples according to the configuration.

Existing split directories are skipped, allowing completed splits to be retained when a multi-split run is resumed.

phyloom.run(config_path: PathLike)[source]

Run a simulation from a configuration file or directory of configuration files.

πŸ› οΈ Utils

class phyloom.configs.utils.Contextualizable[source]

Bases: Protocol[T_co]

Protocol for a configuration value resolved against a context.

contextualize(context: Context) → T_co[source]

Resolve the configuration value from materialized context values.

phyloom.configs.utils.contextualize_optional(cfg: None, context: Context) → None[source]
phyloom.configs.utils.contextualize_optional(cfg: Contextualizable[T], context: Context) → T

Resolve cfg against context while preserving None.