Metadata-Version: 2.4
Name: physiomodeler
Version: 2.0.0rc1
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: matplotlib>=3.10.0,<4
Requires-Dist: mini-racer>=0.14.1,<0.15
Requires-Dist: numpy>=2.2.2,<3
Requires-Dist: pandas>=2.2.3,<4
Requires-Dist: scipy>=1.16.0,<2
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: 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

With [uv](https://docs.astral.sh/uv/):

```sh
uv add physiomodeler
```

Or with pip:

```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 the state changes: the angular
acceleration `ddtheta`.

```python
import math

from physiomodeler import Model


def pendulum(state, inputs, parameters):
    gravity = inputs["gravity"]
    length = parameters["length"]

    return {"ddtheta": -gravity / length * math.sin(state["theta"])}


pendulum_model = Model(
    pendulum,
    name="pendulum",
    state_components=["theta", "dtheta"],  # rad, rad/s
    parameters={"length": 1.0},  # m
    inputs={"gravity": 9.81},  # m/s²
)

result = pendulum_model.run_simulation(time=10, initial_state={"theta": 1.0})
result.plot(y=["theta", "dtheta"])
```

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
on_the_moon = pendulum_model.run_simulation(
    time=10,
    initial_state={"theta": 1.0},
    inputs={"gravity": 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).
