Skip to content

Commit

Permalink
Merge pull request #639 from ICB-DCM/develop
Browse files Browse the repository at this point in the history
Minor bug fixes, new release
  • Loading branch information
arrjon authored Oct 29, 2024
2 parents a322de3 + b0a1347 commit 57c8d16
Show file tree
Hide file tree
Showing 18 changed files with 88 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ extend-ignore =
E501
# Empty method in an abstract base class
B027
# Disable black would make changes warning
BLK100

per-file-ignores =
# Imported but unused
Expand Down
28 changes: 14 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ on:
- main
pull_request:
schedule:
# run Monday and Thursday at 03:18 UTC
- cron: '18 15 * * MON,THU'
# run Monday at 03:18 UTC
- cron: '18 15 * * MON'

jobs:

base:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11', '3.9']
python-version: ['3.12', '3.11', '3.10']

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

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

Expand Down Expand Up @@ -54,14 +54,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11', '3.9']
python-version: ['3.12']

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

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

Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
uses: actions/checkout@v2

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

Expand All @@ -127,14 +127,14 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
python-version: ['3.11', '3.9']
python-version: ['3.12']

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

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

Expand All @@ -161,14 +161,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11']
python-version: ['3.12']

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

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

Expand All @@ -189,14 +189,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11']
python-version: ['3.12']

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

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

Expand Down Expand Up @@ -224,7 +224,7 @@ jobs:
uses: actions/checkout@v2

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

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ name: Deploy
on:
release:
types: [created]


jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
python-version: [3.12]

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

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

Expand Down
14 changes: 13 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ Release Notes
0.12 Series
...........

0.12.15 (2024-10-29)
--------------------

General:

* Minor improvements in the documentation
* Minor bug fixes in dependencies
* Minor bug fixed in general
* Dropping support of python 3.9
* Adding support for python 3.12


0.12.14 (2023-11-10)
--------------------

Expand All @@ -24,7 +36,7 @@ General:

Fixes (#615):

* Fix for wrong assets path in abc-server-dash
* Fix for wrong assets path in abc-server-dash

General

Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@

# Add notebooks prolog to Google Colab and nbviewer
nbsphinx_prolog = r"""
{% set docname = 'github/icb-dcm/pyabc/blob/main/doc/' + env.doc2path(env.docname, base=None) %}
{% set docname = 'github/icb-dcm/pyabc/blob/main/doc/' + env.doc2path(env.docname, base=None) | string %}
.. raw:: html
<div class="note">
Expand Down
1 change: 0 additions & 1 deletion pyabc/acceptor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Acceptors handle the acceptance step.
"""


from .acceptor import (
Acceptor,
AcceptorResult,
Expand Down
6 changes: 3 additions & 3 deletions pyabc/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Model:
.. note::
Most likely you do not want to use this class directly, but the
:class:`SimpleModel` instead, or even just pass a plain function
:class:`FunctionModel` instead, or even just pass a plain function
as model.
Parameters
Expand Down Expand Up @@ -216,7 +216,7 @@ class FunctionModel(Model):
A model which is initialized with a function which generates the samples.
For most cases this class will be adequate.
Note that you can also pass a plain function to the ABCSMC class, which
then gets automatically converted to a SimpleModel.
then gets automatically converted to a FunctionModel.
Parameters
----------
Expand Down Expand Up @@ -252,7 +252,7 @@ def to_model(maybe_model: Union[Callable, Model]) -> Model:
Parameters
----------
maybe_model:
Constructs a SimpleModel instance if a function is passed.
Constructs a FunctionModel instance if a function is passed.
If a Model instance is passed, the Model instance itself is
returned.
Expand Down
11 changes: 11 additions & 0 deletions pyabc/petab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,16 @@
Problem definitions in the PEtab format (https://petab.rtfd.io).
"""
import warnings

from .amici import AmiciPetabImporter

try:
import petab
except ImportError:
warnings.warn(
"PEtab import requires an installation of petab "
"(https://github.com/PEtab-dev/PEtab). "
"Install via `pip3 install petab`.",
stacklevel=1,
)
8 changes: 4 additions & 4 deletions pyabc/petab/amici.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
logger = logging.getLogger("ABC.PEtab")

try:
import petab
import petab.C as C
import petab.v1 as petab
import petab.v1.C as C
except ImportError:
petab = C = None
logger.error(
Expand Down Expand Up @@ -82,8 +82,8 @@ def __call__(self, par: Union[Sequence, Mapping]) -> Mapping:
for key in self.prior_scales.keys():
par[key] = rescale(
val=par[key],
origin_scale=self.prior_scales,
target_scale=self.scaled_scales,
origin_scale=self.prior_scales[key],
target_scale=self.scaled_scales[key],
)

# simulate model
Expand Down
4 changes: 2 additions & 2 deletions pyabc/petab/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
logger = logging.getLogger("ABC.PEtab")

try:
import petab
import petab.C as C
import petab.v1 as petab
import petab.v1.C as C
except ImportError:
petab = C = None
logger.error(
Expand Down
5 changes: 4 additions & 1 deletion pyabc/transition/local_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ def _cov_and_inv(self, n, indices):
while det <= 0:
cov += np.identity(cov.shape[0]) * self.EPS
det = la.det(cov)
inv_cov = la.inv(cov)
try:
inv_cov = la.inv(cov)
except np.linalg.LinAlgError:
inv_cov = np.linalg.pinv(cov) # Use pseudo-inverse as a fallback
return cov, inv_cov, det

def _cov(self, indices, n):
Expand Down
2 changes: 1 addition & 1 deletion pyabc/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.12.14'
__version__ = '0.12.15'
5 changes: 4 additions & 1 deletion pyabc/weighted_statistics/weighted_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ def resample(points, weights, n):
"""
weights = np.asarray(weights)
weights /= np.sum(weights)
resampled = np.random.choice(points, size=n, p=weights)
indices = np.random.choice(
points.shape[0], size=n, p=weights
) # sample index from multi-dimensional sample
resampled = points[indices]
return resampled


Expand Down
18 changes: 9 additions & 9 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ classifiers =
License :: OSI Approved :: BSD License
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.9
keywords =
likelihood-free
inference
Expand All @@ -51,7 +51,7 @@ requires =

[options]
install_requires =
numpy >= 1.19.1
numpy >= 1.23.5
scipy >= 1.5.2
pandas >= 2.0.1
cloudpickle >= 1.5.0
Expand All @@ -60,11 +60,11 @@ install_requires =
redis >= 2.10.6
distributed >= 2022.10.2
matplotlib >= 3.3.0
sqlalchemy >= 2.0.12
sqlalchemy
jabbar >= 0.0.10
gitpython >= 3.1.7

python_requires = >=3.9
python_requires = >=3.10

# not zip safe b/c of Flask templates
zip_safe = False
Expand All @@ -74,11 +74,11 @@ include_package_data = True
packages = find:

[options.extras_require]
webserver_flask =
webserver-flask =
flask-bootstrap >= 3.3.7.1
flask >= 1.1.2
bokeh >= 3.0.1
webserver_dash =
webserver-dash =
dash >= 2.11.1
dash-bootstrap-components >= 1.4.2
pyarrow =
Expand Down Expand Up @@ -111,9 +111,9 @@ autograd =
examples =
notebook >= 6.1.4
doc =
sphinx >= 6.2.1
nbsphinx >= 0.8.9
nbconvert >= 6.5.0
sphinx >= 8.1.3
nbsphinx >= 0.9.5
nbconvert >= 7.16.4
sphinx-rtd-theme >= 1.2.0
sphinx-autodoc-typehints >= 1.18.3
ipython >= 8.4.0
Expand Down
8 changes: 7 additions & 1 deletion test/migrate/create_test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ def model(p):

distance = pyabc.PNormDistance(p=2)

abc = pyabc.ABCSMC(model, prior, distance, population_size=10)
abc = pyabc.ABCSMC(
model,
prior,
distance,
population_size=10,
sampler=pyabc.SingleCoreSampler(),
)
db_file = os.path.join(tempfile.gettempdir(), 'pyabc_test_migrate.db')
abc.new("sqlite:///" + db_file, observation)
abc.run(minimum_epsilon=0.1, max_nr_populations=3)
8 changes: 3 additions & 5 deletions test/petab/test_petab.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import petab
import petab.C as C
import petab.v1 as petab
import petab.v1.C as C
import pytest
import scipy.stats

Expand All @@ -18,9 +18,7 @@


@pytest.fixture(
params=itertools.product(
[petab.C.LIN, petab.C.LOG, petab.C.LOG10], [*petab.C.PRIOR_TYPES, None]
)
params=itertools.product([C.LIN, C.LOG, C.LOG10], [*C.PRIOR_TYPES, None])
)
def prior_specs(request):
"""A one-line parameter df for a given prior type."""
Expand Down
Loading

0 comments on commit 57c8d16

Please sign in to comment.