Skip to main content

scikit-complexity

Category Tools
Development black ruff mypy docformatter
Testing pytest coverage interrogate
Security pip-audit bandit
Automation nox pre-commit
Package version pythonversion downloads
Documentation properdocs
Communication discussions

Overview

scikit-complexity simulates and analyses complex systems from any field of science. You describe a system by its parts, and the library derives its equations, picks a solver unless you choose one, runs the simulation, and can stream it to the Rerun viewer.

Complex systems are usually modelled in separate tools, often one for each field, each with its own conventions. Here every field shares one small vocabulary in the style of scikit-learn. Elements carry states, interactions change them through laws, and systems nest and compose.

Cooling coffee
Physics
Cooling coffee
Duffing
Physics
Duffing
Mirollo-Strogatz
Physics
Mirollo-Strogatz
Brusselator
Chemistry
Brusselator
Cubic autocatalysis
Chemistry
Cubic autocatalysis
Cyclic cellular automaton
Chemistry
Cyclic cellular automaton
Agent-based SIR
Biology
Agent-based SIR
Boolean repressilator
Biology
Boolean repressilator
Replicator dynamics
Biology
Replicator dynamics
Correlated geometric Brownian motions
Economics
Correlated geometric Brownian motions
Fishery capital
Economics
Fishery capital
Geometric Brownian motion
Economics
Geometric Brownian motion
Chua's circuit
Engineering
Chua's circuit
Memristor oscillator
Engineering
Memristor oscillator
Tunnel-diode oscillator
Engineering
Tunnel-diode oscillator
Finite-time blow-up
Mathematics
Finite-time blow-up
Random walk on a hypergraph
Mathematics
Random walk on a hypergraph
Julia set
Mathematics
Julia set
Majority automaton on the Baumslag-Solitar group
Computer science
Majority automaton on the Baumslag-Solitar group
Majority automaton on the free group
Computer science
Majority automaton on the free group
Game of Life
Computer science
Game of Life
Hegselmann-Krause
Social science
Hegselmann-Krause
Public goods game on a hypergraph
Social science
Public goods game on a hypergraph
Prisoner's dilemma tournament
Social science
Prisoner's dilemma tournament

A few of the ready-to-run systems, each with a documented example in the gallery.

Features

  • One interface for many kinds of dynamics. Differential equations, stochastic processes, jump processes, discrete maps, cellular automata, agents, networks and hypergraphs, fields and partial differential equations, quantum systems, and systems that learn by gradient descent all run through simulate.
  • The form is inferred. The library reads the laws of a system and decides whether it is an ordinary differential equation, a stochastic differential equation, or a jump process. It then compiles it for NumPy, Numba, or JAX.
  • Symbolic or numeric laws. A law is a Sage symbolic expression, which you can inspect and solve exactly, or a Python function.
  • Live runs. A simulation streams to Rerun as it runs, and a schedule changes its parameters during the run.
  • Analyses and experiments. The analysis functions range from Lyapunov exponents and entropy to network motifs, scaling laws, and system identification. The experiment functions run parameter sweeps, sensitivity analyses, calibrations, and studies of basin stability.
  • Mature libraries underneath. SciPy, NetworkX, Mesa, LAMMPS, QuTiP, JAX, and others do the numerical work.
  • Parts of your own. The ready-made systems use the same public classes as you do, so each one is also an example for a system of your own.

Installation

scikit-complexity supports Python 3.12, 3.13, and 3.14 on Linux and on macOS 13 or later with Apple silicon. It is available on PyPI. On Python 3.14 the install builds memory-allocator from source, so it needs a C compiler.

pip install scikit-complexity

The installation includes Sage through the passagemath distributions, LAMMPS, Mesa, Numba, JAX, and Rerun. Windows has no passagemath wheels, so on Windows the package runs in WSL.

For development, clone the repository and install the project with PDM.

git clone https://github.com/georgedouzas/scikit-complexity.git
cd scikit-complexity
pdm install

Usage

The library follows the conventions of scikit-learn. What you define is an estimator, a class with get_params, set_params, and clone, such as an element, an interaction, or a system. What you do to it is a function. simulate runs a system as cross_validate runs a model, an analysis measures the run as sklearn.metrics scores a model, and an experiment runs many systems as the model selection functions do.

You can start in two ways. Select a ready-made system from the catalog, or build a custom system from the general classes of skcomplex.core.components.

Select a ready-made system

This section finds a system of the catalog, reads its description, and simulates it. Every ready-made system is a class with a field, topics, references, and parameters. You import it from its subfield, the package skcomplex.systems.<field>.<subfield>, and all_systems lists the classes, as all_estimators does in scikit-learn.

The systems of one field, here ecology, are listed by their field path.

from skcomplex.systems import all_systems

ecology = [name for name, _ in all_systems(field='biology/ecology')]

A search by topic covers every field, and a search by capability tags selects systems by what they do, such as running with random events.

oscillators = [name for name, _ in all_systems(topics='oscillation')]
stochastic = [name for name, _ in all_systems(field='chemistry', tags={'randomness': 'stochastic'})]

The class you choose is imported from its subfield, and its attributes say what it models and where it comes from.

from skcomplex.systems.biology.ecology import LotkaVolterraSystem

LotkaVolterraSystem.topics, LotkaVolterraSystem.references, LotkaVolterraSystem().get_params()

The topics of LotkaVolterraSystem are predator-prey, ode, and oscillation, its references are Lotka (1925) and Volterra (1926), and its parameters start from 40 prey and 9 predators. simulate runs it with its tuned settings, or with parameters and settings of your own.

from skcomplex.core.engine.runtime import simulate

trajectory = simulate(LotkaVolterraSystem())
fast_prey = simulate(LotkaVolterraSystem(r=1.5), until=50, dt=0.1)
round(float(fast_prey.get_values('prey.x').max()))

With a prey growth rate of 1.5, the prey peak at 49. Each run can also stream to the Rerun viewer.

Prey and predators cycle
lotka_volterra
Prey and predators cycle
An epidemic rises and fades
sir
An epidemic rises and fades
Wolves, sheep and grass on a grid
wolf_sheep
Wolves, sheep and grass on a grid

The catalog lists every system by field and topic, and the page of each system shows the classes it is built from.

Build a custom system

This section writes a predator and prey system from the core alone. An element declares its states. An interaction declares its roles, the names of the elements it reads and changes, and returns its laws. In _get_laws, the namespace s holds the symbols of its parameters and of the elements bound to its roles. The system takes one element class, the general RateInteraction, and one new interaction.

from typing import Annotated

from skcomplex.core.components.elements import Element
from skcomplex.core.components.interactions import Interaction, RateInteraction
from skcomplex.core.components.laws import RateLaw
from skcomplex.core.components.systems import CompositeSystem
from skcomplex.core.engine.runtime import simulate
from skcomplex.core.specs import ParameterSpec, RoleSpec, StateSpec


class PopulationElement(Element):
    def __init__(self, label, visual=None, *, n: Annotated[float, StateSpec()] = 1.0):
        super().__init__(label, visual=visual)
        self.n = n


class PredationInteraction(Interaction):
    def __init__(
        self,
        label,
        *,
        predator: Annotated[str, RoleSpec(states=('n',))],
        prey: Annotated[str, RoleSpec(states=('n',))],
        a: Annotated[float, ParameterSpec()] = 0.4,
        b: Annotated[float, ParameterSpec()] = 0.1,
    ):
        super().__init__(label)
        self.predator = predator
        self.prey = prey
        self.a = a
        self.b = b

    def _get_laws(self, s):
        contacts = s.predator.n * s.prey.n
        return [RateLaw(s.prey.n, -s.a * contacts), RateLaw(s.predator.n, s.b * contacts)]


system = CompositeSystem(
    elements=[PopulationElement('rabbits', n=40), PopulationElement('foxes', n=9)],
    interactions=[
        RateInteraction('growth', target='rabbits', state='n', rate=lambda s: 1.1 * s.target.n * (1 - s.target.n / 1000)),
        PredationInteraction('hunt', predator='foxes', prey='rabbits'),
        RateInteraction('death', target='foxes', state='n', rate=lambda s: -0.4 * s.target.n),
    ],
)
trajectory = simulate(system, until=30, dt=0.05)
round(float(trajectory.get_values('rabbits.n').max()))

The rabbits peak at 51. A RerunObserver records the run for the Rerun viewer, and RerunObserver('predators', spawn=True) opens the viewer during the run. A schedule changes a parameter while the system runs. Here it halves the hunting rate at time 15.

import tempfile
from pathlib import Path

from skcomplex.core.engine.viz import RerunObserver

recording = Path(tempfile.mkdtemp()) / 'predators.rrd'
trajectory = simulate(
    system,
    until=30,
    dt=0.05,
    observers=[RerunObserver('predators', save_path=recording)],
    schedule={'hunt.a': lambda t: 0.4 if t < 15 else 0.2},
)
float(trajectory.times[-1])

The run ends at time 30.0, with the hunting rate halved for its second half. A new process takes one more interaction. Here a fishery harvests a fish stock in proportion to its size, and the analysis symbolic returns the equations of the system.

from sage.all__sagemath_symbolics import oo
from sage.sets.real_set import RealSet

from skcomplex.core.analysis import symbolic


class HarvestInteraction(Interaction):
    def __init__(
        self,
        label,
        *,
        target: Annotated[str, RoleSpec(states=('n',))],
        h: Annotated[float, ParameterSpec(domain=RealSet.closed_open(0, oo))] = 0.1,
    ):
        super().__init__(label)
        self.target = target
        self.h = h

    def _get_laws(self, s):
        return [RateLaw(s.target.n, -s.h * s.target.n)]


harvested = CompositeSystem(
    elements=[PopulationElement('fish', n=500)],
    interactions=[
        RateInteraction('growth', target='fish', state='n', rate=lambda s: 0.5 * s.target.n * (1 - s.target.n / 1000)),
        HarvestInteraction('fishing', target='fish', h=0.1),
    ],
)
symbolic(harvested).equations['fish.n']

The equation of the stock is the logistic growth -0.0005 (n - 1000) n minus the harvest h n.

Find out which components fit

This section checks that parts fit before you build a system with them. An interaction states what it needs from each role, and an element states what it carries.

hunt = PredationInteraction('hunt', predator='foxes', prey='rabbits')
hunt.get_requirements().roles['prey'].states, list(PopulationElement('rabbits').get_states())

The role prey reads the state n, and PopulationElement carries n, so they fit. When a role is bound to an element without the state it reads, simulate raises a RoleElementError.

from skcomplex.core.errors import RoleElementError


class TankElement(Element):
    def __init__(self, label, visual=None, *, level: Annotated[float, StateSpec()] = 1.0):
        super().__init__(label, visual=visual)
        self.level = level


wrong = CompositeSystem(
    elements=[TankElement('tank'), PopulationElement('foxes')],
    interactions=[PredationInteraction('hunt', predator='foxes', prey='tank')],
)
try:
    simulate(wrong, until=1)
except RoleElementError as error:
    message = str(error)
message

The message says that the role prey reads n but the element tank carries level. It proposes three fixes: bind the role to an element that carries the state, declare the state on the element, or read another state.

The parts pages list every element, interaction, law, solver, and backend with the tags they accept, and the user guide walks through the choices in order.

Spec-driven development

The project develops from specifications with OpenSpec. Its engineering constitution, openspec/constitution.md, binds all work, and openspec/config.yaml names it as binding.

Metadata

Release files for scikit-complexity 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scikit-complexity 0.9.0
File Size Uploaded Provenance Actions
scikit_complexity-0.9.0.tar.gz 3.6 MB With provenance Details for scikit_complexity-0.9.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for scikit-complexity 0.9.0
File Interpreter ABI Platform Actions
scikit_complexity-0.9.0-py3-none-any.whl Python 3 none any Details for scikit_complexity-0.9.0-py3-none-any.whl

Total release size: 7.2 MB

Release files / scikit_complexity-0.9.0.tar.gz

Download URL scikit_complexity-0.9.0.tar.gz
Size 3.6 MB
Tags Source
SHA-256 checksum
How to use checksums
a565215953317b3983689aa2eede1eb6cbc5c3b8252fd2f07f2905e990dc2670
BLAKE2b-256 checksum
How to use checksums
85c13703a93e7f9d87fa2a538b6895484899dcabaa6387d7ef3b6e89991d966f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / scikit_complexity-0.9.0-py3-none-any.whl

Download URL scikit_complexity-0.9.0-py3-none-any.whl
Size 3.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
ea9807d9a09cc8159a948fd484dfb8bf8f291d9a4ae4259caaf0b512e7ce49d0
BLAKE2b-256 checksum
How to use checksums
69902221ebd3997de82fd16a942fd14e11ef425e6119d9e5829101625d63c8bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for scikit-complexity 0.9.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for scikit_complexity-0.9.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page