Skip to content

Commit

Permalink
Merge pull request #266 from dweindl/release_0.3.0
Browse files Browse the repository at this point in the history
Release 0.3.0
  • Loading branch information
dweindl authored Jun 25, 2024
2 parents 90379c4 + d8ad9b8 commit c427340
Show file tree
Hide file tree
Showing 50 changed files with 424 additions and 305 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-patch", "version-update:semver-minor"]
3 changes: 2 additions & 1 deletion .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: CI

on:
push:
pull_request:
workflow_dispatch:
schedule:
- cron: '48 4 * * *'
Expand All @@ -11,7 +12,7 @@ jobs:
strategy:
matrix:
platform: [windows-latest, macos-latest, ubuntu-latest]
python-version: ["3.9", "3.11"]
python-version: ["3.10", "3.12"]
runs-on: ${{ matrix.platform }}

steps:
Expand Down
30 changes: 15 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
args: ["--profile", "black", "--filter-files", "--line-length", "79"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand All @@ -16,13 +10,19 @@ repos:
args: [--allow-multiple-documents]
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.7.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.11
hooks:
- id: black-jupyter
# It is recommended to specify the latest version of Python
# supported by your project here, or alternatively use
# pre-commit's default_language_version, see
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.11
args: ["--line-length", "79"]
# Run the linter.
- id: ruff
args:
- --fix
- --config
- pyproject.toml

# Run the formatter.
- id: ruff-format
args:
- --config
- pyproject.toml
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sphinx:
build:
os: "ubuntu-22.04"
tools:
python: "3.9"
python: "3.10"

python:
install:
Expand Down
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# PEtab changelog

## 0.3 series

### 0.3.0

**This release requires `python>=3.10`**

**Features**
* Visualization: Make line plot lines configurable via
`petab.visualize.plotter.measurement_line_kwargs and
`petab.visualize.plotter.simulation_line_kwargs`
by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/254
* Validator: check that `datasetId`s referenced in visualization tables exists
in measurement tables
by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/255

**Fixes**
* Drop an index if it's reset
by @dilpath in https://github.com/PEtab-dev/libpetab-python/pull/262

## New Contributors
* @PaulJonasJost made their first contribution in https://github.com/PEtab-dev/libpetab-python/pull/250

**Full Changelog**: https://github.com/PEtab-dev/libpetab-python/compare/v0.2.9...v0.3.0

## 0.2 series

### 0.2.9
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ and the easiest way to install it is running

pip3 install petab

It will require Python>=3.9 to run. (We are following the
It will require Python>=3.10 to run. (We are following the
[numpy Python support policy](https://numpy.org/neps/nep-0029-deprecation_policy.html)).

Development versions of the PEtab library can be installed using
Expand Down Expand Up @@ -57,7 +57,7 @@ Examples for PEtab Python library usage:

## Getting help

If you have any question or problems with this package, feel free to post them
If you have any questions or problems with this package, feel free to post them
at our GitHub [issue tracker](https://github.com/PEtab-dev/libpetab-python/issues/).

## Contributing
Expand Down
5 changes: 2 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# -- Project information -----------------------------------------------------

project = "libpetab-python"
copyright = "2018-2023, the PEtab developers"
copyright = "2018-2024, the PEtab developers"
author = "PEtab developers"

# The full version, including alpha/beta/rc tags
Expand All @@ -29,7 +29,7 @@
# -- Custom pre-build --------------------------------------------------------


subprocess.run(["python", "md2rst.py"])
subprocess.run([sys.executable, "md2rst.py"]) # noqa: S603

# -- General configuration ---------------------------------------------------

Expand Down Expand Up @@ -74,7 +74,6 @@
"members": None,
"imported-members": ["petab"],
"inherited-members": None,
"private-members": None,
"show-inheritance": None,
}

Expand Down
9 changes: 5 additions & 4 deletions petab/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import numpy as np
import pandas as pd
import sympy
from sympy.abc import _clash

import petab

from .C import *
from .math import sympify_petab

__all__ = [
"calculate_residuals",
Expand Down Expand Up @@ -157,7 +157,7 @@ def get_symbolic_noise_formulas(observable_df) -> Dict[str, sympy.Expr]:
if NOISE_FORMULA not in observable_df.columns:
noise_formula = None
else:
noise_formula = sympy.sympify(row.noiseFormula, locals=_clash)
noise_formula = sympify_petab(row.noiseFormula)
noise_formulas[observable_id] = noise_formula
return noise_formulas

Expand Down Expand Up @@ -322,7 +322,8 @@ def calculate_llh_for_table(
parameter_df: pd.DataFrame,
) -> float:
"""Calculate log-likelihood for one set of tables. For the arguments, see
`calculate_llh`."""
`calculate_llh`.
"""
llhs = []

# matching columns
Expand All @@ -335,7 +336,7 @@ def calculate_llh_for_table(
noise_formulas = get_symbolic_noise_formulas(observable_df)

# iterate over measurements, find corresponding simulations
for irow, row in measurement_df.iterrows():
for _, row in measurement_df.iterrows():
measurement = row[MEASUREMENT]

# look up in simulation df
Expand Down
1 change: 0 additions & 1 deletion petab/composite_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def from_yaml(yaml_config: Union[Dict, str]) -> "CompositeProblem":
Arguments:
yaml_config: PEtab configuration as dictionary or YAML file name
"""

if isinstance(yaml_config, str):
path_prefix = os.path.dirname(yaml_config)
yaml_config = yaml.load_yaml(yaml_config)
Expand Down
10 changes: 6 additions & 4 deletions petab/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


def get_condition_df(
condition_file: Union[str, pd.DataFrame, Path, None]
condition_file: Union[str, pd.DataFrame, Path, None],
) -> pd.DataFrame:
"""Read the provided condition file into a ``pandas.Dataframe``
Expand All @@ -40,14 +40,17 @@ def get_condition_df(
)

if not isinstance(condition_file.index, pd.RangeIndex):
condition_file.reset_index(inplace=True)
condition_file.reset_index(
drop=condition_file.index.name != CONDITION_ID,
inplace=True,
)

try:
condition_file.set_index([CONDITION_ID], inplace=True)
except KeyError:
raise KeyError(
f"Condition table missing mandatory field {CONDITION_ID}."
)
) from None

return condition_file

Expand Down Expand Up @@ -75,7 +78,6 @@ def create_condition_df(
A :py:class:`pandas.DataFrame` with empty given rows and columns and
all nan values
"""

condition_ids = [] if condition_ids is None else list(condition_ids)

data = {CONDITION_ID: condition_ids}
Expand Down
18 changes: 8 additions & 10 deletions petab/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def write_simulation_df(df: pd.DataFrame, filename: Union[str, Path]) -> None:


def get_visualization_df(
visualization_file: Union[str, Path, pd.DataFrame, None]
visualization_file: Union[str, Path, pd.DataFrame, None],
) -> Union[pd.DataFrame, None]:
"""Read PEtab visualization table
Expand Down Expand Up @@ -102,7 +102,8 @@ def get_visualization_df(
except pd.errors.EmptyDataError:
warn(
"Visualization table is empty. Defaults will be used. "
"Refer to the documentation for details."
"Refer to the documentation for details.",
stacklevel=2,
)
vis_spec = pd.DataFrame()
return vis_spec
Expand Down Expand Up @@ -226,9 +227,9 @@ def get_flattened_id_mappings(

mappings[OBSERVABLE_ID][observable_replacement_id] = observable_id

for field, hyperparameter_type, target in [
(NOISE_PARAMETERS, "noiseParameter", NOISE_FORMULA),
(OBSERVABLE_PARAMETERS, "observableParameter", OBSERVABLE_FORMULA),
for field, hyperparameter_type in [
(NOISE_PARAMETERS, "noiseParameter"),
(OBSERVABLE_PARAMETERS, "observableParameter"),
]:
if field in measurements:
mappings[field][
Expand Down Expand Up @@ -357,7 +358,6 @@ def concat_tables(
Returns:
The concatenated DataFrames
"""

if isinstance(tables, pd.DataFrame):
return tables

Expand Down Expand Up @@ -389,7 +389,6 @@ def to_float_if_float(x: Any) -> Any:
Returns:
``x`` as float if possible, otherwise ``x``
"""

try:
return float(x)
except (ValueError, TypeError):
Expand Down Expand Up @@ -427,19 +426,18 @@ def create_combine_archive(
email: E-mail address of archive creator
organization: Organization of archive creator
"""

path_prefix = os.path.dirname(str(yaml_file))
yaml_config = yaml.load_yaml(yaml_file)

# function-level import, because module-level import interfered with
# other SWIG interfaces
try:
import libcombine
except ImportError:
except ImportError as err:
raise ImportError(
"To use PEtab's COMBINE functionality, libcombine "
"(python-libcombine) must be installed."
)
) from err

def _add_file_metadata(location: str, description: str = ""):
"""Add metadata to the added file"""
Expand Down
12 changes: 3 additions & 9 deletions petab/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import numpy as np
import pandas as pd
import sympy as sp
from sympy.abc import _clash

import petab

from . import core, measurements, parameters
from .C import * # noqa: F403
from .math import sympify_petab
from .models import Model

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -105,7 +105,6 @@ def check_condition_df(
Raises:
AssertionError: in case of problems
"""

# Check required columns are present
req_cols = []
_check_df(df, req_cols, "condition")
Expand Down Expand Up @@ -167,7 +166,6 @@ def check_measurement_df(
Raises:
AssertionError, ValueError: in case of problems
"""

_check_df(df, MEASUREMENT_DF_REQUIRED_COLS, "measurement")

for column_name in MEASUREMENT_DF_REQUIRED_COLS:
Expand Down Expand Up @@ -319,7 +317,7 @@ def check_observable_df(observable_df: pd.DataFrame) -> None:
for row in observable_df.itertuples():
obs = getattr(row, OBSERVABLE_FORMULA)
try:
sp.sympify(obs, locals=_clash)
sympify_petab(obs)
except sp.SympifyError as e:
raise AssertionError(
f"Cannot parse expression '{obs}' "
Expand All @@ -328,7 +326,7 @@ def check_observable_df(observable_df: pd.DataFrame) -> None:

noise = getattr(row, NOISE_FORMULA)
try:
sympified_noise = sp.sympify(noise, locals=_clash)
sympified_noise = sympify_petab(noise)
if sympified_noise is None or (
sympified_noise.is_Number and not sympified_noise.is_finite
):
Expand Down Expand Up @@ -432,7 +430,6 @@ def assert_measured_observables_defined(
Raises:
AssertionError: in case of problems
"""

used_observables = set(measurement_df[OBSERVABLE_ID].values)
defined_observables = set(observable_df.index.values)
if undefined_observables := (used_observables - defined_observables):
Expand All @@ -453,7 +450,6 @@ def condition_table_is_parameter_free(condition_df: pd.DataFrame) -> bool:
``True`` if there are no parameter overrides in the condition table,
``False`` otherwise.
"""

return len(petab.get_parametric_overrides(condition_df)) == 0


Expand All @@ -468,7 +464,6 @@ def assert_parameter_id_is_string(parameter_df: pd.DataFrame) -> None:
Raises:
AssertionError: in case of problems
"""

for parameter_id in parameter_df:
if isinstance(parameter_id, str):
if parameter_id[0].isdigit():
Expand Down Expand Up @@ -1088,7 +1083,6 @@ def assert_measurement_conditions_present_in_condition_table(
Raises:
AssertionError: in case of problems
"""

used_conditions = set(measurement_df[SIMULATION_CONDITION_ID].values)
if PREEQUILIBRATION_CONDITION_ID in measurement_df:
used_conditions |= set(
Expand Down
Loading

0 comments on commit c427340

Please sign in to comment.