pykappa.system¶
Classes
|
A Kappa system containing agents, rules, observables, and variables for simulation. |
- class pykappa.system.System(mixture=None, rules=None, observables=None, variables=None, monitor=True, seed=None)[source]¶
A Kappa system containing agents, rules, observables, and variables for simulation.
- Parameters:
- classmethod read_ka(filepath, seed=None)[source]¶
Read and parse a Kappa .ka file to create a System.
- Parameters:
filepath (str) – Path to the Kappa file.
seed (int | None) – Random seed for reproducibility.
- Return type:
Self
- classmethod from_ka(ka_str, seed=None)[source]¶
Create a System from a Kappa (.ka style) string.
- Parameters:
ka_str (str) – Kappa language string containing a system definition.
seed (int | None) – Random seed for reproducibility.
- Return type:
Self
- classmethod from_kappa(mixture=None, rules=None, observables=None, variables=None, *args, **kwargs)[source]¶
Create a System from Kappa strings.
- Parameters:
mixture (dict[str, int] | None) – Dictionary mapping agent patterns to initial counts.
rules (Iterable[str] | None) – Iterable of rule strings in Kappa format.
observables (list[str] | dict[str, str] | None) – List of observable expressions or dict mapping names to expressions.
variables (dict[str, str] | None) – Dictionary mapping variable names to expressions.
*args – Additional arguments passed to System constructor.
**kwargs – Additional keyword arguments passed to System constructor.
- Return type:
Self
- observables: dict[str, Expression]¶
Maps observable names to expressions
- variables: dict[str, Expression]¶
Maps variable names to expressions
- time: float¶
Current simulation time
- tallies: defaultdict[str, dict[str, int]]¶
Tracks rule applications
- property names: dict[str, set[str]]¶
The names of all observables and variables.
- property tallies_str: str¶
A formatted string showing how many times each rule has been applied.
- property kappa_str: str¶
The system representation in Kappa (.ka style) format.
- to_ka(filepath)[source]¶
Write system information to a Kappa file.
- Parameters:
filepath (str)
- Return type:
None
- add_rule(rule, name=None)[source]¶
Add a new rule to the system.
- Parameters:
rule (Rule | str) – Rule object or Kappa string representation.
name (str | None) – Name to assign to the rule. If None, a default name is generated.
- Raises:
AssertionError – If a rule with the given name already exists.
- Return type:
None
- remove_rule(name)[source]¶
Remove a rule by setting its rate to zero.
- Raises:
AssertionError – If the rule already has zero rate.
KeyError – If no rule with the given name exists.
- Parameters:
name (str)
- Return type:
None
- property rule_reactivities: list[float]¶
The reactivity of each rule in the system.
- property reactivity: float¶
The total reactivity of the system.
- wait()[source]¶
Advance simulation time according to exponential distribution.
- Raises:
RuntimeWarning – If system has no reactivity (infinite wait time).
- Return type:
None