Skip to content

Commit

Permalink
Merge pull request #202 from ICB-DCM/develop
Browse files Browse the repository at this point in the history
Release 0.0.10
  • Loading branch information
yannikschaelte authored Dec 4, 2019
2 parents d25bdde + 578cd7a commit 46099a7
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 44 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ addons:
- libatlas-base-dev
- lcov
- swig3.0
- pandoc

install:
- mkdir -p ~/bin/ && ln -s /usr/bin/swig3.0 ~/bin/swig && export PATH=~/bin/:$PATH
- pip3 install --upgrade setuptools wheel pkgconfig
- pip3 install --upgrade jupyter # for jupyter notebooks
- pip3 install --upgrade -r ./.travis_pip_reqs.txt
- pip3 install .

Expand All @@ -33,8 +32,9 @@ script:
- python3 -m flake8 --exclude=build,doc,example,tmp,amici_models
- travis_wait 20 python3 -m pytest --cov=pypesto ./test/test_*
- travis_wait 20 xvfb-run -a python3 -m pytest --cov=pypesto --cov-append ./test/visualize/test_*
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then sphinx-build -W -b html -d doc/_build/html doc/ doc/_build/html; fi
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then test/run_notebook.sh doc/example/; fi
- coverage xml
- test/run_notebook.sh doc/example/

after_success:
- bash <(curl -s https://codecov.io/bash)
Expand Down
8 changes: 8 additions & 0 deletions .travis_pip_reqs.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
setuptools
wheel
pkgconfig
jupyter
pytest
pytest-cov
coverage
flake8
dlib
pyswarm
gitpython
petab>=0.0.0a16
amici>=0.10.13
sphinx
nbsphinx
sphinx_rtd_theme
3 changes: 2 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# html_static_path = ['_static']
html_favicon = "logo/logo_favicon.png"

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
Expand Down
Binary file added doc/logo/logo_favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions doc/releasenotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ Release notes
..........


0.0.10 (2019-12-04)
-------------------

* Only compute FIM when sensitivities are available (#194).
* Fix documentation build (#197).
* Add support for pyswarm optimizer (#198).
* Run travis tests for documentation and notebooks only on pull requests (#199).


0.0.9 (2019-10-11)
------------------

Expand Down
4 changes: 3 additions & 1 deletion pypesto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
OptimizerResult,
Optimizer,
ScipyOptimizer,
DlibOptimizer)
DlibOptimizer,
GlobalOptimizer)
from .profile import (parameter_profile,
ProfileOptions,
ProfilerResult)
Expand Down Expand Up @@ -50,6 +51,7 @@
"Optimizer",
"ScipyOptimizer",
"DlibOptimizer",
"GlobalOptimizer",
# profile
"parameter_profile",
"ProfileOptions",
Expand Down
3 changes: 2 additions & 1 deletion pypesto/engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
multistart itself is parallelized.
"""


from .base import Engine
from .single_core import SingleCoreEngine
from .multi_process import MultiProcessEngine
from .task import OptimizerTask


__all__ = [
"Engine",
"SingleCoreEngine",
"MultiProcessEngine",
"OptimizerTask"
Expand Down
6 changes: 3 additions & 3 deletions pypesto/engine/base.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from typing import List
from abc import abstractmethod
import abc


class Engine:
class Engine(abc.ABC):
"""
Abstract engine base class.
"""

def __init__(self):
pass

@abstractmethod
@abc.abstractmethod
def execute(self, tasks: List):
raise NotImplementedError(
"This engine is not intended to be called.")
19 changes: 11 additions & 8 deletions pypesto/objective/amici_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ def _call_amici(
if sensi_order > self.max_sensi_order:
raise Exception("Sensitivity order not allowed.")

sensi_method = self.amici_solver.getSensitivityMethod()

# prepare outputs
nllh = 0.0
snllh = np.zeros(self.dim)
Expand Down Expand Up @@ -306,14 +308,15 @@ def _call_amici(
snllh,
coefficient=-1.0
)
# TODO: Compute the full Hessian, and check here
add_sim_hess_to_opt_hess(
self.x_ids,
self.mapping_par_opt_to_par_sim[data_ix],
rdata['FIM'],
s2nllh,
coefficient=-1.0
)
if sensi_method == 1:
# TODO: Compute the full Hessian, and check here
add_sim_hess_to_opt_hess(
self.x_ids,
self.mapping_par_opt_to_par_sim[data_ix],
rdata['FIM'],
s2nllh,
coefficient=-1.0
)

elif mode == MODE_RES:
res = np.hstack([res, rdata['res']]) \
Expand Down
25 changes: 20 additions & 5 deletions pypesto/objective/objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,56 @@ class Objective:
giving a standardized way of calling. Apart from that, it manages several
things including fixing of parameters and history.
Parameters
----------
fun: callable, optional
The objective function to be minimized. If it only computes the
objective function value, it should be of the form
``fun(x) -> float``
where x is an 1-D array with shape (n,), and n is the parameter space
dimension.
grad: callable, bool, optional
Method for computing the gradient vector. If it is a callable,
it should be of the form
``grad(x) -> array_like, shape (n,).``
If its value is True, then fun should return the gradient as a second
output.
hess: callable, optional
Method for computing the Hessian matrix. If it is a callable,
it should be of the form
``hess(x) -> array, shape (n,n).``
If its value is True, then fun should return the gradient as a
second, and the Hessian as a third output, and grad should be True as
well.
hessp: callable, optional
Method for computing the Hessian vector product, i.e.
``hessp(x, v) -> array_like, shape (n,)``
computes the product H*v of the Hessian of fun at x with v.
res: {callable, bool}, optional
Method for computing residuals, i.e.
``res(x) -> array_like, shape(m,).``
sres: callable, optional
Method for computing residual sensitivities. If its is a callable,
it should be of the form
``sres(x) -> array, shape (m,n).``
If its value is True, then res should return the residual
sensitivities as a second output.
Expand All @@ -74,6 +86,7 @@ class Objective:
options: pypesto.ObjectiveOptions, optional
Options as specified in pypesto.ObjectiveOptions.
Attributes
----------
Expand All @@ -90,6 +103,7 @@ class Objective:
sensitivity_orders: tuple
Temporary variable to store requested sensitivity orders
Notes
-----
Expand Down Expand Up @@ -518,6 +532,7 @@ def check_grad(self,
Compare gradient evaluation: Firstly approximate via finite
differences, and secondly use the objective gradient.
Parameters
----------
Expand All @@ -531,22 +546,22 @@ def check_grad(self,
Finite differences step size. Default: 1e-5.
verbosity: int
Level of verbosity for function output
0: no output
1: summary for all parameters
2: summary for individual parameters
Level of verbosity for function output.
* 0: no output,
* 1: summary for all parameters,
* 2: summary for individual parameters.
Default: 1.
mode: str
Residual (MODE_RES) or objective function value
(MODE_FUN, default) computation mode.
Returns
----------
result: pd.DataFrame
gradient, finite difference approximations and error estimates.
"""

if x_indices is None:
Expand Down
28 changes: 14 additions & 14 deletions pypesto/objective/petab_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def from_folder(folder,
output_folder=output_folder,
model_name=model_name)

def create_model(self, force_compile=False):
def create_model(self, force_compile=False, *args, **kwargs):
"""
Import amici model. If necessary or force_compile is True, compile
first.
Expand All @@ -93,10 +93,11 @@ def create_model(self, force_compile=False):
exist yet. If True, the output folder is deleted and the model
(re-)compiled in either case.
.. warning::
If `force_compile`, then an existing folder of that name will
be deleted.
.. warning::
If `force_compile`, then an existing folder of that name will be
deleted.
args, kwargs: Extra arguments passed to amici.SbmlImporter.sbml2amici
"""
# courtesy check if target not folder
if os.path.exists(self.output_folder) \
Expand All @@ -113,7 +114,7 @@ def create_model(self, force_compile=False):
if self._must_compile(force_compile):
logger.info(f"Compiling amici model to folder "
f"{self.output_folder}.")
self.compile_model()
self.compile_model(*args, **kwargs)
else:
logger.info(f"Using existing amici model in folder "
f"{self.output_folder}.")
Expand Down Expand Up @@ -156,18 +157,16 @@ def _must_compile(self, force_compile: bool):
# no need to (re-)compile
return False

def compile_model(self):
def compile_model(self, *args, **kwargs):
"""
Compile the model. If the output folder exists already, it is first
deleted.
"""
# check prerequisites
if not petab.condition_table_is_parameter_free(
self.petab_problem.condition_df):
raise AssertionError(
"Parameter dependent conditions in the condition file "
"are not yet supported.")
Parameters
----------
args, kwargs: Extra arguments passed to amici.SbmlImporter.sbml2amici
"""

# delete output directory
if os.path.exists(self.output_folder):
Expand Down Expand Up @@ -204,7 +203,8 @@ def compile_model(self):
observables=observables,
constantParameters=constant_parameter_ids,
sigmas=sigmas,
noise_distributions=noise_distrs
noise_distributions=noise_distrs,
*args, **kwargs
)

def create_solver(self, model=None):
Expand Down
6 changes: 4 additions & 2 deletions pypesto/optimize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
from .optimizer import (OptimizerResult,
Optimizer,
ScipyOptimizer,
DlibOptimizer)
DlibOptimizer,
GlobalOptimizer)

__all__ = ["minimize",
"OptimizeOptions",
"OptimizerResult",
"Optimizer",
"ScipyOptimizer",
"DlibOptimizer"]
"DlibOptimizer",
"GlobalOptimizer"]
2 changes: 1 addition & 1 deletion pypesto/optimize/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def minimize(
startpoint_method: {callable, False}, optional
Method for how to choose start points. False means the optimizer does
not require start points
not require start points, e.g. 'pso' method in 'GlobalOptimizer'
result: pypesto.Result
A result object to append the optimization results to. For example,
Expand Down
Loading

0 comments on commit 46099a7

Please sign in to comment.