Skip to content

Commit

Permalink
Merged.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanmg committed Oct 5, 2023
2 parents f2d8c23 + c015e4a commit 6cacf43
Show file tree
Hide file tree
Showing 30 changed files with 514 additions and 298 deletions.
13 changes: 13 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
[flake8]
extend-ignore =
# Don't be crazy if line too long
E501
# Missing docstring in __init__
D107
# black: blank lines after docstring for function/class
D202,D204
# Missing docstring in public module/class/method/function/package/magic method
D100,D101,D102,D103,D104,D105
per-file-ignores =
*/__init__.py:F401,F403
tests/*:S101
exclude =
amici_models
cache_fiddy
28 changes: 28 additions & 0 deletions .github/workflows/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh

# Install CI dependencies, arguments specify what is required

# Base packages
pip install --upgrade pip
pip install wheel setuptools

# Used to create local test environments
pip install tox

# Update apt
sudo apt-get update

# Check arguments
for par in "$@"; do
case $par in
doc)
# documentation
sudo apt-get install pandoc
;;

*)
echo "Unknown argument: $par" >&2
exit 1
;;
esac
done
88 changes: 81 additions & 7 deletions .github/workflows/test_suite.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: Test suite
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
schedule:
# run Sunday at 01:23 UTC
- cron: '23 1 * * SUN'

jobs:
build:
Expand All @@ -12,7 +17,7 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ['3.9', '3.10', '3.11']
python-version: ['3.9', '3.11']

steps:
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -37,15 +42,84 @@ jobs:
swig \
libatlas-base-dev
# TODO remove once released
- name: Install custom AMICI
run: |
pip install --upgrade --upgrade-strategy eager -e git+https://github.com/AMICI-dev/amici.git@develop#egg=amici\&subdirectory=python/sdist
- name: Install package
run: |
pip install --upgrade --upgrade-strategy eager -e .[tests,amici,pypesto]
pip install --upgrade --upgrade-strategy eager -e .[tests,amici]
- name: Run tests
run: |
pytest tests/
quality:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11']

steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Prepare python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Cache
uses: actions/cache@v3
with:
path: ~/.cache
key: ${{ runner.os }}-${{ matrix.python-version }}-ci-quality

- name: Install dependencies
run: pip install tox pre-commit

- name: Check repository size
run: tox -e size

- name: Run quality checks
timeout-minutes: 5
run: tox -e pyroma,flake8

# failing on github
# - name: Run pre-commit hooks
# run: pre-commit run --all-files

docs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11']

steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Prepare python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Cache
uses: actions/cache@v3
with:
path: ~/.cache
key: ${{ runner.os }}-${{ matrix.python-version }}-ci-docs

- name: Install dependencies
run: .github/workflows/setup.sh doc

- name: apt
run: |
sudo apt-get update \
&& sudo apt-get install -y \
swig \
libatlas-base-dev
- name: Install package
run: |
pip install --upgrade --upgrade-strategy eager -e .[doc]
- name: Build doc
timeout-minutes: 10
run: tox -e doc
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile = black
5 changes: 4 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ sphinx:
build:
os: ubuntu-22.04
tools:
python: "3.10"
python: "3.11"
apt_packages:
- libatlas-base-dev
- swig

python:
install:
Expand Down
5 changes: 3 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import sys

import mock

# Configuration file for the Sphinx documentation builder.
Expand All @@ -12,8 +15,6 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.

import os
import sys

sys.path.insert(0, os.path.abspath(".."))

Expand Down
1 change: 1 addition & 0 deletions doc/rtd_requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
petab
urllib3<2
9 changes: 4 additions & 5 deletions examples/derivative.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@
"from fiddy.analysis import ApproximateCentral\n",
"from fiddy.success import Consistency\n",
"\n",
"\n",
"point = np.array([1,0,0])\n",
"point = np.array([1, 0, 0])\n",
"sizes = [1e-10, 1e-5]\n",
"derivative = get_derivative(\n",
" function=rosen,\n",
" point=point,\n",
" sizes=[1e-10, 1e-5],\n",
" method_ids=[MethodId.FORWARD, MethodId.BACKWARD],\n",
" direction_ids=['x','y','z'],\n",
" direction_ids=[\"x\", \"y\", \"z\"],\n",
" analysis_classes=[ApproximateCentral],\n",
" success_checker=Consistency(rtol=1e-2, atol=1e-15),\n",
")\n",
Expand Down Expand Up @@ -254,7 +253,7 @@
}
],
"source": [
"derivative.df.loc['x', 'computer_results']"
"derivative.df.loc[\"x\", \"computer_results\"]"
]
},
{
Expand Down Expand Up @@ -318,7 +317,7 @@
}
],
"source": [
"derivative.df.loc['x', 'analysis_results']"
"derivative.df.loc[\"x\", \"analysis_results\"]"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions fiddy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from .constants import *
from .derivative import Derivative, get_derivative
from .directional_derivative import methods

# from . import difference
from .function import Function, CachedFunction
from .function import CachedFunction, Function
from .numpy import fiddy_array

# from . import quotient
from .step import step
from .derivative import Derivative, get_derivative
from .directional_derivative import methods
from .numpy import fiddy_array

# from .gradient_check import gradient_check
5 changes: 2 additions & 3 deletions fiddy/analysis.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import abc
from typing import Any, List, Dict
from dataclasses import dataclass, field
from typing import Any, Dict

import numpy as np

from .constants import Type, MethodId
from .constants import MethodId, Type
from .directional_derivative import DirectionalDerivative
from . import directional_derivative


@dataclass
Expand Down
26 changes: 3 additions & 23 deletions fiddy/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import numpy as np
from numpy.typing import NDArray


__all__ = [
"Type",
"MethodId",
Expand Down Expand Up @@ -32,10 +31,8 @@ class Type:
# TODO rename analysis and success to e.g.
# - "ANALYSE_DIRECTIONAL_DERIVATIVE_METHOD" and
# - "ANALYSE_DERIVATIVE_METHOD" and
ANALYSIS_METHOD = Callable[
["directional_derivative.DirectionalDerivative"], Any
]
SUCCESS_CHECKER = Callable[["derivative.Derivative"], Union[bool, Any]]
ANALYSIS_METHOD = Callable[["DirectionalDerivative"], Any] # noqa: F821
SUCCESS_CHECKER = Callable[["Derivative"], Union[bool, Any]] # noqa: F821


# FIXME rename, since this can be the name of the base class in `derivative.py`
Expand All @@ -46,26 +43,9 @@ class MethodId(str, Enum):
BACKWARD = "backward"
CENTRAL = "central"
FORWARD = "forward"
RICHARDSON = "richardson"
# richardson
# five point?
# TODO separate enum for "order" of method?
# e.g. for higher-order derivatives?
HYBRID = "hybrid"


# class AnalysisMethod(str, Enum):
# ABSOLUTE_ERROR = "absolute_error"
# RELATIVE_ERROR = "relative_error"
# =======


## TODO remove? redundant
# class GradientCheckMethod(str, Enum):
# BACKWARD = MethodId.BACKWARD
# CENTRAL = MethodId.CENTRAL
# FORWARD = MethodId.FORWARD
# HYBRID = MethodId.HYBRID
##>>>>>>> origin/main


EPSILON = 1e-5
23 changes: 6 additions & 17 deletions fiddy/derivative.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
import abc
from typing import Any, Callable, Dict, List, Union
import warnings

from dataclasses import dataclass
from typing import Callable, Dict, List, Union

import numpy as np
import pandas as pd

from .constants import (
MethodId,
Type,
EPSILON,
)

from .analysis import Analysis
from .constants import MethodId, Type
from .directional_derivative import (
methods,
get_directions,
Computer,
DirectionalDerivative,
get_directions,
methods,
)

from .success import Success


# @dataclass
# class Analysis:
# # Change to callable?
Expand Down Expand Up @@ -125,8 +114,8 @@ def df(self):
df.index.rename("direction", inplace=True)
return df

def print(self):
print(self.df)
# def print(self):
# print(self.df)


def get_derivative(
Expand Down
Loading

0 comments on commit 6cacf43

Please sign in to comment.