Metadata-Version: 2.4
Name: epiecs
Version: 1.0.0
Summary: NumPy-backed epidemiological agent-based simulation framework
Requires-Python: <3.15,>=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=2.4.6
Requires-Dist: pandas>=3.0.3
Requires-Dist: matplotlib>=3.8
Dynamic: license-file

# EpiECS

EpiECS is an epidemiological agent-based modeling framework built on an Entity-Component-System design. It combines a fast NumPy hot path `PopulationArray` with an internal ECS component store for rich agent metadata, custom systems, and flexible model composition.

## Features

- `EpiWorld` engine with synchronized NumPy / ECS agent state
- `EpiModel` blueprint for reusable, reproducible simulations
- Flexible custom compartment enums via `EpiState` or user-defined `IntEnum`
- Fluent rich-agent builder and direct `add_agent()` support
- Core contact sampling abstractions and generic ECS / array synchronisation
- Collector systems for time-series output and Rt estimation
- Tagging, seeding, environment abstractions, and time-varying parameters

## Installation

```bash
python -m pip install .
```

`requirements.txt` lists runtime dependencies only; installing it does not
install EpiECS. For editable development from this checkout, use
`python -m pip install -e .` instead.

## Quick start

```python
from epiecs.core import EpiWorld
from epiecs.core.population import EpiState
from epiecs.systems import RandomContactSampler, TransmissionSystem, StateTransitionSystem
from epiecs.collectors import SIRCollector

world = EpiWorld(capacity=50_000, seed=42)
world.add_system(TransmissionSystem(RandomContactSampler(k=10), beta=0.3))
world.add_system(StateTransitionSystem(incubation_days=3, infectious_days=7))
world.add_system(SIRCollector())

for _ in range(49_990):
    world.add_agent(state=EpiState.S, age=30)
for _ in range(10):
    world.add_agent(state=EpiState.I, age=30)

world.run(max_steps=365)
print(world.summary())
```

## Example model — SEIRS with a user-defined extension

This repository includes `examples/seirs_custom_model.py`, which demonstrates:

1. Custom compartment enum extending the base epidemic states
2. Extra hot-path fields through `extra_fields`
3. Fluent agent creation with `world.agent()`
4. A user-defined `BehaviorComponent` stored in the ECS component store
5. Custom systems inserted between built-in priorities
6. A stopping condition via `world.stop()`

Run the example:

```bash
python examples/seirs_custom_model.py
```

A plot of the epidemic curve is written to `examples/seirs_custom_model.png`.

## Custom model usage

The `EpiModel` base class makes it easy to build a reusable custom model:

```python
from epiecs.core import EpiModel
from epiecs.core.population import EpiState
from epiecs.systems import RandomContactSampler, TransmissionSystem, StateTransitionSystem
from epiecs.collectors import SIRCollector

class SEIRModel(EpiModel):
    def configure(self):
        return {
            'capacity': self.params['n'] + 100,
            'state_enum': EpiState,
            'seed': self.params.get('seed'),
        }

    def setup(self):
        self.world.add_system(TransmissionSystem(
            RandomContactSampler(k=self.params.get('contacts_per_agent', 10)),
            beta=self.params['beta'],
        ))
        self.world.add_system(StateTransitionSystem(
            incubation_days=self.params['incubation_days'],
            infectious_days=self.params['infectious_days'],
        ))
        self._collector = SIRCollector()
        self.world.add_system(self._collector)

        for _ in range(self.params['n'] - 10):
            self.world.add_agent(state=EpiState.S)
        for _ in range(10):
            self.world.add_agent(state=EpiState.I)

    @property
    def results(self):
        return {
            'records': self._collector.records,
            'peak_I': max(r['I'] for r in self._collector.records),
            'final_state': self.world.summary(),
        }

model = SEIRModel(
    n=10_000,
    beta=0.3,
    incubation_days=3,
    infectious_days=7,
    seed=42,
)
model.run(max_steps=365)
print(model.results['peak_I'])
```

## Notes

- Use `extra_fields` to add custom agent attributes like `days_since_vax`.
- Use `world.add_component()` and `world.query()` to attach and inspect rich ECS components.
- Custom `BaseSystem` subclasses can implement any domain-specific dynamics.
