Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: AMICI-dev/AMICI
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e62db52abea4fc65d6c4baa47536ef486a6c9fb7
Choose a base ref
..
head repository: AMICI-dev/AMICI
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f16293d0e0780276b6ef3e0861c28e4f9990aa54
Choose a head ref
Showing with 66 additions and 29 deletions.
  1. +37 −0 documentation/python_installation.rst
  2. +28 −0 python/sdist/amici/numpy.py
  3. +1 −29 python/sdist/amici/plotting.py
37 changes: 37 additions & 0 deletions documentation/python_installation.rst
Original file line number Diff line number Diff line change
@@ -66,6 +66,43 @@ Install AMICI:
pip3 install amici
Arch Linux
----------

Install the AMICI dependencies via ``pacman``
(this requires superuser privileges):

.. code-block:: bash
sudo pacman -S python swig openblas gcc hdf5 boost-libs
Install AMICI:

.. code-block:: bash
pip3 install amici
Alternatively:

1. Check if packages are already installed with the required versions for AMICI installation.

.. code-block:: bash
sudo pacman -Si python swig openblas gcc hdf5 boost-libs
2. Upgrade installed packages if required mininum versions are not satisfied for AMICI installation.

.. code-block:: bash
sudo pacman -Su python swig openblas gcc hdf5 boost-libs
3. Install AMICI:

.. code-block:: bash
pip3 install amici
Installation on OSX
+++++++++++++++++++

28 changes: 28 additions & 0 deletions python/sdist/amici/numpy.py
Original file line number Diff line number Diff line change
@@ -10,9 +10,12 @@

import amici
import numpy as np
import sympy as sp

from . import ExpData, ExpDataPtr, Model, ReturnData, ReturnDataPtr

StrOrExpr = Union[str, sp.Expr]


class SwigPtrView(collections.abc.Mapping):
"""
@@ -429,3 +432,28 @@ def _entity_type_from_id(
return symbol

raise KeyError(f"Unknown symbol {entity_id}.")


def evaluate(expr: StrOrExpr, rdata: ReturnDataView) -> np.array:
"""Evaluate a symbolic expression based on the given simulation outputs.
:param expr:
A symbolic expression, e.g. a sympy expression or a string that can be sympified.
Can include state variable, expression, and observable IDs, depending on whether
the respective data is available in the simulation results.
Parameters are not yet supported.
:param rdata:
The simulation results.
:return:
The evaluated expression for the simulation output timepoints.
"""
from sympy.utilities.lambdify import lambdify

if isinstance(expr, str):
expr = sp.sympify(expr)

Check warning on line 454 in python/sdist/amici/numpy.py

Codecov / codecov/patch

python/sdist/amici/numpy.py#L453-L454

Added lines #L453 - L454 were not covered by tests

arg_names = list(sorted(expr.free_symbols, key=lambda x: x.name))
func = lambdify(arg_names, expr, "numpy")
args = [rdata.by_id(arg.name) for arg in arg_names]
return func(*args)

Check warning on line 459 in python/sdist/amici/numpy.py

Codecov / codecov/patch

python/sdist/amici/numpy.py#L456-L459

Added lines #L456 - L459 were not covered by tests
30 changes: 1 addition & 29 deletions python/sdist/amici/plotting.py
Original file line number Diff line number Diff line change
@@ -6,15 +6,12 @@
from typing import Iterable, Optional, Sequence, Union

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
import sympy as sp
from matplotlib.axes import Axes

from . import Model, ReturnDataView

StrOrExpr = Union[str, sp.Expr]
from .numpy import StrOrExpr, evaluate


def plot_state_trajectories(
@@ -121,31 +118,6 @@ def plot_jacobian(rdata: ReturnDataView):
plotObservableTrajectories = plot_observable_trajectories


def evaluate(expr: StrOrExpr, rdata: ReturnDataView) -> np.array:
"""Evaluate a symbolic expression based on the given simulation outputs.
:param expr:
A symbolic expression, e.g. a sympy expression or a string that can be sympified.
Can include state variable, expression, and observable IDs, depending on whether
the respective data is available in the simulation results.
Parameters are not yet supported.
:param rdata:
The simulation results.
:return:
The evaluated expression for the simulation output timepoints.
"""
from sympy.utilities.lambdify import lambdify

if isinstance(expr, str):
expr = sp.sympify(expr)

arg_names = list(sorted(expr.free_symbols, key=lambda x: x.name))
func = lambdify(arg_names, expr, "numpy")
args = [rdata.by_id(arg.name) for arg in arg_names]
return func(*args)


def plot_expressions(

Check warning on line 121 in python/sdist/amici/plotting.py

Codecov / codecov/patch

python/sdist/amici/plotting.py#L121

Added line #L121 was not covered by tests
exprs: Union[Sequence[StrOrExpr], StrOrExpr], rdata: ReturnDataView
) -> None: