Metadata-Version: 2.4
Name: physiomodeler
Version: 1.1.3
Summary: Educational tool to help model and simulate physiological systems, as represented by ordinary differential equations (ODEs)
Keywords: simulation,physiology,education,respiration,modelling
Author: Peter Somhorst
Author-email: Peter Somhorst <p.somhorst@tudelft.nl>
License-Expression: MIT
License-File: LICENSE
Requires-Dist: attrs>=25.1.0
Requires-Dist: camel-converter>=5.0.0
Requires-Dist: dataclass-wizard[toml]>=0.38.0,<1.0
Requires-Dist: frozendict>=2.4.6
Requires-Dist: jupyter>=1.1.1
Requires-Dist: markdown-exec>=1.12.1
Requires-Dist: matplotlib>=3.10.0
Requires-Dist: numpy>=2.2.2
Requires-Dist: pandas>=2.2.3
Requires-Dist: scipy>=1.15.1
Requires-Dist: playwright>=1.55.0 ; extra == 'diagrams'
Requires-Dist: ipykernel>=6.29.5 ; extra == 'notebooks'
Requires-Dist: ipympl>=0.9.7 ; extra == 'notebooks'
Requires-Dist: jupyter>=1.1.1 ; extra == 'notebooks'
Requires-Python: >=3.12
Project-URL: Homepage, https://psomhorst.github.io/physiomodeler/
Project-URL: Documentation, https://psomhorst.github.io/physiomodeler/
Provides-Extra: diagrams
Provides-Extra: notebooks
Description-Content-Type: text/markdown

# PhysioModeler

PhysioModeler is an educational tool for modelling and simulating physiological systems
described by ordinary differential equations (ODEs). It is built for physiological
models, but works for a wide range of ODE models.

The interface aims to be explicit and easy to read. You describe a model by its state
components, the functions that say how the state changes, and its parameters and inputs.
PhysioModeler solves it with SciPy and returns the result as a pandas DataFrame.

## Installation

```sh
pip install physiomodeler
```

PhysioModeler requires Python 3.12 or newer.

## Example: an undamped pendulum

A pendulum is described by its angle `theta` and angular velocity `dtheta`. The dynamics
function receives the current state and returns how each state component changes.

```python
import math

from physiomodeler import Model


def pendulum(time, state, inputs, parameters):
    g = inputs["g"]
    l = parameters["l"]
    return {
        "dtheta": state["dtheta"],
        "ddtheta": -g / l * math.sin(state["theta"]),
    }


model = Model(
    dynamics=pendulum,
    state_components=["theta", "dtheta"],
    parameters={"l": 1},     # length of the pendulum (m)
    inputs={"g": 9.81},      # gravity (m/s²)
)

result = model.run_simulation(time=10, initial_state={"theta": 1, "dtheta": 0})
result.plot(subplots=True)
```

Parameters and inputs are part of the model, so comparing scenarios only takes a change
in the arguments, for example the same pendulum on the Moon:

```python
moon = model.run_simulation(
    time=10,
    initial_state={"theta": 1, "dtheta": 0},
    inputs={"g": 1.625},
)
```

## Features

- Combine several dynamics functions, or nest models within other models.
- Inputs that are constant or change over time.
- Events, for example to detect when a state crosses a value or to stop a simulation.
- Post-analysis functions that add calculated values to the result.
- Run many simulations at once, or run a model until it reaches equilibrium.

## Documentation

The full documentation, with more examples, is at
<https://psomhorst.github.io/physiomodeler/>.

See the [changelog](https://github.com/psomhorst/physiomodeler/blob/main/CHANGELOG.md)
for what changed between versions.

## License

PhysioModeler is released under the
[MIT License](https://github.com/psomhorst/physiomodeler/blob/main/LICENSE).
