Skip to content

Commit

Permalink
Convert to sundials version 3.1.1 (#80)
Browse files Browse the repository at this point in the history
* Move from recursive setup.py to standard python setup.py

* Add multi-precision logic to cython (no setup.py support yet)

* Add setup.py support for multi-precision

* Add CI support for multi-precision

* Add short explanation of how to use multi-precision code

* start of conversion to sundials 3.1.0
TODO:
 1/ update interface further
 2/ SUNDIALS_INDEX_TYPE should be settable

* move target to 3.1.1 sundials instead of 3.1.0

* Make sundials index type user settable

* New sundials will be a minor version bump. Put in doc how to see version

* cvode conversion to sundials 3.1.1

* nvector_serial conversion to sundials 3.1.1

* sundials dir conversion to sundials 3.1.1

* Add files to hold cython of new directories in 3.x sundials

* new linsol and matrix headers for 3.1.1

* bugfixes: compilation of common_defs.pyx now working

* add new error flag

* start with convertion of cvode to new methods

* finalize cvode API conversion to 3.1.1
Remaining issue: dense jac conversion to SUNMatrix, How ??

* Convert IDA to new API

* ENH: Allow usage of different index sizes

* ENH: Add SUNMatrix dense support

* ENH: Add SUNMatrix band support

* ENH: Don't include sundials_lapack header, not needed

* TST,CI: Drop python 3.3 and add python 3.7

* ENH: Skip lapack when building if sundials lacks lapack support

* Avoid error in test output when an integrator fails to
load on clean up of test (when del is called). Error in test
is sufficient.

* bugfix: fix unwanted lines in previous change

* Update examples to API changes

* Use uniform signature of (residual, cj) for jacobian
  • Loading branch information
bmcage authored Aug 13, 2018
1 parent 09778ec commit ce999d7
Show file tree
Hide file tree
Showing 27 changed files with 1,790 additions and 551 deletions.
57 changes: 40 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,53 +31,76 @@ matrix:
# needed to work around https://github.com/travis-ci/travis-ci/issues/4794
- python: 2.7
env:
- TOXENV=py27 SUNDIALS_VERSION='2.7.0'
- python: 3.3
env:
- TOXENV=py33 SUNDIALS_VERSION='2.7.0'
- TOXENV=py27 SUNDIALS_VERSION='3.1.1'
- python: 3.4
env:
- TOXENV=py34 SUNDIALS_VERSION='2.7.0'
- TOXENV=py34 SUNDIALS_VERSION='3.1.1'
- python: 3.5
env:
- TOXENV=py35 SUNDIALS_VERSION='2.7.0'
- TOXENV=py35 SUNDIALS_VERSION='3.1.1'
- python: 3.6
env:
- TOXENV=py36 SUNDIALS_VERSION='2.7.0'
- TOXENV=py36 SUNDIALS_VERSION='3.1.1'
# commented as 3.7 not yet on travis
#- python: 3.7
# env:
# - TOXENV=py37 SUNDIALS_VERSION='3.1.1'
- python: 3.5
env:
- TOXENV=doctr SUNDIALS_VERSION='2.7.0'
- TOXENV=doctr SUNDIALS_VERSION='3.1.1'
- python: 3.5
env:
- TOXENV=docs SUNDIALS_VERSION='2.7.0'
- TOXENV=docs SUNDIALS_VERSION='3.1.1'
- python: 3.5
env:
- TOXENV=check-manifest SUNDIALS_VERSION='2.7.0'
- TOXENV=check-manifest SUNDIALS_VERSION='3.1.1'
- python: 3.5
env:
- TOXENV=checkreadme SUNDIALS_VERSION='2.7.0'
- TOXENV=checkreadme SUNDIALS_VERSION='3.1.1'

# Additional precisions
- python: 2.7
env:
- TOXENV=py27 SUNDIALS_VERSION='3.1.1' SUNDIALS_PRECISION='single'
- python: 3.6
env:
- TOXENV=py36 SUNDIALS_VERSION='3.1.1' SUNDIALS_PRECISION='single'
- python: 2.7
env:
- TOXENV=py27 SUNDIALS_VERSION='3.1.1' SUNDIALS_PRECISION='extended'
- python: 3.6
env:
- TOXENV=py36 SUNDIALS_VERSION='3.1.1' SUNDIALS_PRECISION='extended'

allow_failures:
- python: 2.7
env:
- TOXENV=py27 SUNDIALS_VERSION='3.1.1' SUNDIALS_PRECISION='single'
- python: 3.6
env:
- TOXENV=py36 SUNDIALS_VERSION='3.1.1' SUNDIALS_PRECISION='single'

# Additional precisions
- python: 2.7
env:
- TOXENV=py27 SUNDIALS_VERSION='2.7.0' SUNDIALS_PRECISION='single'
- TOXENV=py27 SUNDIALS_VERSION='3.1.1' SUNDIALS_PRECISION='single'
- python: 3.6
env:
- TOXENV=py36 SUNDIALS_VERSION='2.7.0' SUNDIALS_PRECISION='single'
- TOXENV=py36 SUNDIALS_VERSION='3.1.1' SUNDIALS_PRECISION='single'
- python: 2.7
env:
- TOXENV=py27 SUNDIALS_VERSION='2.7.0' SUNDIALS_PRECISION='extended'
- TOXENV=py27 SUNDIALS_VERSION='3.1.1' SUNDIALS_PRECISION='extended'
- python: 3.6
env:
- TOXENV=py36 SUNDIALS_VERSION='2.7.0' SUNDIALS_PRECISION='extended'
- TOXENV=py36 SUNDIALS_VERSION='3.1.1' SUNDIALS_PRECISION='extended'

allow_failures:
- python: 2.7
env:
- TOXENV=py27 SUNDIALS_VERSION='2.7.0' SUNDIALS_PRECISION='single'
- TOXENV=py27 SUNDIALS_VERSION='3.1.1' SUNDIALS_PRECISION='single'
- python: 3.6
env:
- TOXENV=py36 SUNDIALS_VERSION='2.7.0' SUNDIALS_PRECISION='single'
- TOXENV=py36 SUNDIALS_VERSION='3.1.1' SUNDIALS_PRECISION='single'

install:
- source ci_support/ensure_sundials_installed.sh
Expand Down
5 changes: 3 additions & 2 deletions ci_support/ensure_sundials_installed.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/sh

SUNDIALS_DEFAULT_VERSION='2.7.0'
SUNDIALS_DEFAULT_VERSION='3.1.1'
SUNDIALS_DEFAULT_PRECISION='double'
SUNDIALS_DEFAULT_INDEX_TYPE='int32_t'

export SUNDIALS_DIR=$HOME/sundials/"${SUNDIALS_VERSION:-$SUNDIALS_DEFAULT_VERSION}"/"${SUNDIALS_PRECISION:-$SUNDIALS_DEFAULT_PRECISION}"
export SUNDIALS_DIR=$HOME/sundials/"${SUNDIALS_VERSION:-$SUNDIALS_DEFAULT_VERSION}"/"${SUNDIALS_PRECISION:-$SUNDIALS_DEFAULT_PRECISION}"/"${SUNDIALS_INDEX_TYPE:-$SUNDIALS_DEFAULT_INDEX_TYPE}"
SUNDIALS_LIBDIR=$SUNDIALS_DIR/lib
SUNDIALS_INCLUDEDIR=$SUNDIALS_DIR/include

Expand Down
5 changes: 3 additions & 2 deletions ci_support/install_sundials.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/sh
set -ex

SUNDIALS=sundials-"${SUNDIALS_VERSION:-2.7.0}"
SUNDIALS=sundials-"${SUNDIALS_VERSION:-3.1.1}"
SUNDIALS_FILE=$SUNDIALS.tar.gz
SUNDIALS_URL=http://computation.llnl.gov/projects/sundials-suite-nonlinear-differential-algebraic-equation-solvers/download/$SUNDIALS_FILE
PRECISION="${SUNDIALS_PRECISION:-double}"
INDEX_TYPE="${SUNDIALS_INDEX_TYPE:-int32_t}"

wget "$SUNDIALS_URL"

Expand All @@ -16,5 +17,5 @@ mkdir sundials_build
# ARKODE and examples are disabled as they does not support multiple precisions
# (should be fixed in the 3.0 release)
cd sundials_build &&
cmake -DCMAKE_INSTALL_PREFIX=$SUNDIALS_DIR -DLAPACK_ENABLE=ON -DSUNDIALS_PRECISION="$PRECISION" -DBUILD_ARKODE:BOOL=OFF -DEXAMPLES_ENABLE:BOOL=OFF -DEXAMPLES_INSTALL:BOOL=OFF ../$SUNDIALS &&
cmake -DCMAKE_INSTALL_PREFIX=$SUNDIALS_DIR -DLAPACK_ENABLE=ON -DSUNDIALS_INDEX_TYPE="$INDEX_TYPE" -DSUNDIALS_PRECISION="$PRECISION" -DBUILD_ARKODE:BOOL=OFF -DEXAMPLES_ENABLE:BOOL=OFF -DEXAMPLES_INSTALL:BOOL=OFF ../$SUNDIALS &&
make && make install
8 changes: 4 additions & 4 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
BUILD_REQUIRES = ['numpy', 'cython'] # This is need for older pip

MAJOR = 2
MINOR = 3
MICRO = 3
MINOR = 4
MICRO = 0
DEV = True

CLASSIFIERS = [
Expand All @@ -35,10 +35,10 @@
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
]

def build_verstring():
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/doublependulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def ddaspk_res(self, tres, yy, yp, res):

def ddaspk_jac(self, tres, yy, yp, cj, jac):
"""the jacobian function as required by ddaspk"""
self.jac.evaluate(tres, yy, yp, cj, jac)
self.jac.evaluate(tres, yy, yp, None, cj, jac)

#classes for the equations, as needed for the chosen solution method
class resindex2(ida.IDA_RhsFunction):
Expand Down Expand Up @@ -242,7 +242,7 @@ def set_dblpend(self, dblpend):
the data """
self.dblpend = dblpend

def evaluate(self, tres, yy, yp, cj, jac):
def evaluate(self, tres, yy, yp, residual, cj, jac):

m1 = self.dblpend.m1
m2 = self.dblpend.m2
Expand Down
12 changes: 6 additions & 6 deletions docs/examples/ode/simpleoscillator_jac.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Authors: B. Malengier
# Authors: B. Malengier
"""
This example shows the most simple way of using a solver.
This example shows the most simple way of using a solver.
We solve free vibration of a simple oscillator::
m \ddot{u} + k u = 0, u(0) = u_0, \dot{u}(0) = \dot{u}_0
using the CVODE solver, which means we use a rhs function of \dot{u}.
Solution::
u(t) = u_0*cos(sqrt(k/m)*t)+\dot{u}_0*sin(sqrt(k/m)*t)/sqrt(k/m)
"""
from __future__ import print_function
from numpy import asarray, cos, sin, sqrt
Expand All @@ -22,11 +22,11 @@ def rhseqn(t, x, xdot):
""" we create rhs equations for the problem"""
xdot[0] = x[1]
xdot[1] = - k/m * x[0]
def jaceqn(t, x, jac):

def jaceqn(t, x, fx, jac):
jac[0,1] = 1
jac[1,0] = -k/m

#instantiate the solver
from scikits.odes import ode
solver = ode('cvode', rhseqn, jacfn=jaceqn)
Expand Down
12 changes: 6 additions & 6 deletions docs/examples/ode/simpleoscillator_prec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
using the CVODE solver. The rhs function is given by \dot{u}. The
preconditioning is implemented in prec_solvefn which solves the
system P = I - gamma * J, where J is the Jacobian of the rhs.
The jac_times_vecfn calculates the Jacobian times vector product
using the analytic Jacobian.
The jac_times_vecfn calculates the Jacobian times vector product
using the analytic Jacobian.
Solution::
u(t) = u_0*cos(sqrt(k/m)*t)+\dot{u}_0*sin(sqrt(k/m)*t)/sqrt(k/m)
"""
from __future__ import print_function
from numpy import asarray, cos, sin, sqrt
Expand All @@ -32,17 +32,17 @@ def prec_solvefn(t, y, r, z, gamma, delta, lr):
def jac_times_vecfn(v, Jv, t, y, user_data):
""" Calculate Jacobian times vector product Jv = J*v"""
Jv[0] = v[1]
Jv[1] = -k/m * v[0]
Jv[1] = -k/m * v[0]

#define function for the right-hand-side equations which has specific signature
def rhseqn(t, x, xdot):
""" we create rhs equations for the problem"""
xdot[0] = x[1]
xdot[1] = - k/m * x[0]

#instantiate the solver using a left-preconditioned BiCGStab as linear solver
from scikits.odes import ode
solver = ode('cvode', rhseqn, linsolver='spbcg', precond_type='left', prec_solvefn=prec_solvefn, jac_times_vecfn=jac_times_vecfn)
solver = ode('cvode', rhseqn, linsolver='spbcgs', precond_type='left', prec_solvefn=prec_solvefn, jac_times_vecfn=jac_times_vecfn)
#obtain solution at a required time
result = solver.solve([0., 1., 2.], initx)

Expand Down
23 changes: 18 additions & 5 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ Before building ``odes``, you need to have installed:
distributions, ``python-devel`` on Fedora)
* C compiler
* Fortran compiler (e.g. gfortran)
* `Sundials 2.7.0 <https://computation.llnl.gov/casc/sundials/download/download.html>`_
* `Sundials 3.1.1 <https://computation.llnl.gov/casc/sundials/download/download.html>`_

In addition, if building from a git checkout, you'll also need Cython.

It is required that Sundials is built with the BLAS/LAPACK interface enabled, so check
the Fortran Settings section. A typical install if sundials download package is
extracted into directory sundials-2.7.0 is on a \*nix system::
extracted into directory sundials-3.1.1 is on a \*nix system::

mkdir build-sundials-2.7.0
cd build-sundials-2.7.0/
cmake -DLAPACK_ENABLE=ON -DCMAKE_INSTALL_PREFIX=<install_path> ../sundials-2.7.0/
mkdir build-sundials-3.1.1
cd build-sundials-3.1.1/
cmake -DLAPACK_ENABLE=ON -DSUNDIALS_INDEX_TYPE=int32_t -DCMAKE_INSTALL_PREFIX=<install_path> ../sundials-3.1.1/
make install

.. warning::
Expand All @@ -43,6 +43,15 @@ which will download the latest version from PyPI. This will handle the installat

If you have installed SUNDIALS in a non-standard path (e.g. ``/usr/`` or ``/usr/local/``), you can set ``$SUNDIALS_INST`` in your environment to the installation prefix of SUNDIALS (i.e. value of ``<install_path>`` mentioned above).


Testing your version of ``odes``
................................
To test the version in python, use in the python shell::

>>> import pkg_resources
>>> pkg_resources.get_distribution("scikits.odes").version

Running the Tests
.................
You need nose to run the tests. To install nose, run::
Expand All @@ -52,6 +61,10 @@ You need nose to run the tests. To install nose, run::
To run the tests, in the python shell::

>>> import scikits.odes as od; od.test()
Note that the sundials library must be in your ``LD_LIBRARY_PATH``. So, make sure the directory ``$SUNDIALS_INST/lib`` is included. You can do this for example as follows (assuming sundials was installed in ``/usr/local``::

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

Installation of ODES from git checkout
---------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion scikits/odes/dae.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ def __del__(self):
"""
Clean up what is needed
"""
del self._integrator
if hasattr(self, '_integrator'):
del self._integrator

#------------------------------------------------------------------------------
# DAE integrators
Expand Down
Loading

0 comments on commit ce999d7

Please sign in to comment.