babylon.engine.formula_registry

Formula registry for hot-swappable mathematical functions.

This module provides a FormulaRegistry class that stores named callables, enabling runtime replacement of formulas for testing and modding.

Sprint 3: Central Committee (Dependency Injection)

Classes

FormulaRegistry()

Registry for named mathematical formulas.

class babylon.engine.formula_registry.FormulaRegistry[source]

Bases: object

Registry for named mathematical formulas.

Provides a central lookup for all simulation formulas, enabling: - Hot-swapping formulas for testing with mocks - Modding support for custom formula implementations - Centralized formula management

Example

>>> registry = FormulaRegistry.default()
>>> rent = registry.get("imperial_rent")
>>> result = rent(alpha=0.5, periphery_wages=0.4, periphery_consciousness=0.2)
__init__()[source]

Initialize an empty formula registry.

Return type:

None

register(name, func)[source]

Register or replace a formula by name.

Parameters:
  • name (str) – Unique identifier for the formula

  • func (Callable[..., Any]) – Callable implementing the formula

Return type:

None

get(name)[source]

Retrieve a formula by name.

Parameters:

name (str) – The formula identifier

Return type:

Callable[..., Any]

Returns:

The registered formula callable

Raises:

KeyError – If no formula is registered with the given name

list_formulas()[source]

List all registered formula names.

Return type:

list[str]

Returns:

List of formula names in arbitrary order

classmethod default()[source]

Create a registry pre-populated with all standard formulas.

Registers all 12 formulas from babylon.systems.formulas: - imperial_rent - labor_aristocracy_ratio - is_labor_aristocracy - consciousness_drift - acquiescence_probability - revolution_probability - crossover_threshold - loss_aversion - exchange_ratio - exploitation_rate - value_transfer - prebisch_singer

Return type:

FormulaRegistry

Returns:

FormulaRegistry with all standard formulas registered