diff --git a/src/__init__.py b/src/__init__.py index e31e2d81..105fcf13 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -35,6 +35,6 @@ def wrap(func): with open(_fpath, 'r') as f: __version__=f.readline().strip() __revision__=f.readline().strip() -except: +except Exception: __version__ = "unknown" __revision__ = "unknown" diff --git a/src/algebraic.pyx b/src/algebraic.pyx index 379ce717..1181abdb 100644 --- a/src/algebraic.pyx +++ b/src/algebraic.pyx @@ -19,9 +19,7 @@ import numpy as N cimport numpy as N from timeit import default_timer as timer -import itertools - -from exception import * +from exception import Algebraic_Exception, AssimuloException from problem import Algebraic_Problem include "constants.pxi" #Includes the constants (textual include) @@ -129,7 +127,7 @@ cdef class Algebraic: def _set_verbosity(self, verb): try: self.options["verbosity"] = int(verb) - except: + except Exception: raise AssimuloException("Verbosity must be an integer.") def _get_verbosity(self): diff --git a/src/implicit_ode.pyx b/src/implicit_ode.pyx index d3f420a6..e22b26f7 100644 --- a/src/implicit_ode.pyx +++ b/src/implicit_ode.pyx @@ -24,7 +24,7 @@ import sys import numpy as N cimport numpy as N -from exception import * +from exception import TerminateSimulation, TimeLimitExceeded from timeit import default_timer as timer import warnings diff --git a/src/lib/radau_core.py b/src/lib/radau_core.py index 47c79601..36d2fc4a 100644 --- a/src/lib/radau_core.py +++ b/src/lib/radau_core.py @@ -16,8 +16,7 @@ # along with this program. If not, see . import numpy as N - -from assimulo.ode import * +from assimulo.ode import NORMAL class Radau_Exception(Exception): pass diff --git a/src/lib/sundials_callbacks_ida_cvode.pxi b/src/lib/sundials_callbacks_ida_cvode.pxi index 7b16f70c..366c3e24 100644 --- a/src/lib/sundials_callbacks_ida_cvode.pxi +++ b/src/lib/sundials_callbacks_ida_cvode.pxi @@ -16,7 +16,7 @@ # along with this program. If not, see . import cython - +from assimulo.exception import AssimuloRecoverableError cdef int cv_rhs(realtype t, N_Vector yv, N_Vector yvdot, void* problem_data): """ @@ -37,7 +37,7 @@ cdef int cv_rhs(realtype t, N_Vector yv, N_Vector yvdot, void* problem_data): rhs = (pData.RHS)(t,y,sw=pData.sw, p=p) else: rhs = (pData.RHS)(t,y,p) - except: + except Exception: return CV_REC_ERR #Recoverable Error (See Sundials description) else: #No sensitivity @@ -46,7 +46,7 @@ cdef int cv_rhs(realtype t, N_Vector yv, N_Vector yvdot, void* problem_data): rhs = (pData.RHS)(t,y,pData.sw) else: rhs = (pData.RHS)(t,y) - except: + except Exception: return CV_REC_ERR #Recoverable Error (See Sundials description) for i in range(pData.dim): @@ -82,7 +82,7 @@ cdef int cv_sens_rhs_all(int Ns, realtype t, N_Vector yv, N_Vector yvdot, return CV_SUCCESS except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return CV_REC_ERR - except: + except Exception: traceback.print_exc() return CV_UNREC_RHSFUNC_ERR @@ -138,7 +138,7 @@ IF SUNDIALS_VERSION >= (3,0,0): return CVDLS_SUCCESS except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description) - except: + except Exception: traceback.print_exc() return CVDLS_JACFUNC_UNRECVR ELSE: @@ -205,7 +205,7 @@ ELSE: return CVDLS_SUCCESS except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description) - except: + except Exception: traceback.print_exc() return CVDLS_JACFUNC_UNRECVR @@ -234,7 +234,7 @@ IF SUNDIALS_VERSION >= (3,0,0): jac=(pData.JAC)(t,y,p) except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description) - except: + except Exception: traceback.print_exc() return CVDLS_JACFUNC_UNRECVR else: @@ -245,7 +245,7 @@ IF SUNDIALS_VERSION >= (3,0,0): jac=(pData.JAC)(t,y) except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description) - except: + except Exception: traceback.print_exc() return CVDLS_JACFUNC_UNRECVR @@ -284,7 +284,7 @@ ELSE: jac=(pData.JAC)(t,y,p) except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description) - except: + except Exception: traceback.print_exc() return CVDLS_JACFUNC_UNRECVR else: @@ -295,7 +295,7 @@ ELSE: jac=(pData.JAC)(t,y) except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description) - except: + except Exception: traceback.print_exc() return CVDLS_JACFUNC_UNRECVR @@ -341,7 +341,7 @@ cdef int cv_jacv(N_Vector vv, N_Vector Jv, realtype t, N_Vector yv, N_Vector fyv return SPGMR_SUCCESS except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return SPGMR_ATIMES_FAIL_REC - except: + except Exception: traceback.print_exc() return SPGMR_PSOLVE_FAIL_UNREC else: @@ -357,7 +357,7 @@ cdef int cv_jacv(N_Vector vv, N_Vector Jv, realtype t, N_Vector yv, N_Vector fyv return SPGMR_SUCCESS except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return SPGMR_ATIMES_FAIL_REC - except: + except Exception: traceback.print_exc() return SPGMR_PSOLVE_FAIL_UNREC @@ -375,7 +375,7 @@ IF SUNDIALS_VERSION >= (3,0,0): try: ret = (pData.PREC_SETUP)(t,y,fy,jok,gamma,pData.PREC_DATA) - except: + except Exception: return CV_REC_ERR #Recoverable Error (See Sundials description) jcurPtr[0] = 1 if ret[0] else 0 @@ -399,7 +399,7 @@ IF SUNDIALS_VERSION >= (3,0,0): try: zres = (pData.PREC_SOLVE)(t,y,fy,r,gamma,delta,pData.PREC_DATA) - except: + except Exception: return CV_REC_ERR #Recoverable Error (See Sundials description) for i in range(pData.dim): @@ -422,7 +422,7 @@ ELSE: try: ret = (pData.PREC_SETUP)(t,y,fy,jok,gamma,pData.PREC_DATA) - except: + except Exception: return CV_REC_ERR #Recoverable Error (See Sundials description) jcurPtr[0] = 1 if ret[0] else 0 @@ -446,7 +446,7 @@ ELSE: try: zres = (pData.PREC_SOLVE)(t,y,fy,r,gamma,delta,pData.PREC_DATA) - except: + except Exception: return CV_REC_ERR #Recoverable Error (See Sundials description) for i in range(pData.dim): @@ -475,7 +475,7 @@ cdef int cv_prec(realtype t, N Vector yv, N Vector fyv, zptr[i] = zres[i] return SPGMR_SUCCESS - except: + except Exception: return SPGMR_PSOLVE_FAIL_UNREC """ @@ -501,7 +501,7 @@ cdef int cv_root(realtype t, N_Vector yv, realtype *gout, void* problem_data): gout[i]=root[i] return CV_SUCCESS - except: + except Exception: return CV_RTFUNC_FAIL # Unrecoverable Error cdef int ida_res(realtype t, N_Vector yv, N_Vector yvdot, N_Vector residual, void* problem_data): @@ -534,7 +534,7 @@ cdef int ida_res(realtype t, N_Vector yv, N_Vector yvdot, N_Vector residual, voi return IDA_SUCCESS except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return IDA_REC_ERR # recoverable error (see Sundials description) - except: + except Exception: traceback.print_exc() return IDA_RES_FAIL else: #NO SENSITIVITY @@ -552,7 +552,7 @@ cdef int ida_res(realtype t, N_Vector yv, N_Vector yvdot, N_Vector residual, voi return IDA_SUCCESS except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return IDA_REC_ERR # recoverable error (see Sundials description) - except: + except Exception: traceback.print_exc() return IDA_RES_FAIL @@ -589,7 +589,7 @@ IF SUNDIALS_VERSION >= (3,0,0): return IDADLS_SUCCESS except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return IDADLS_JACFUNC_RECVR #Recoverable Error - except: + except Exception: traceback.print_exc() return IDADLS_JACFUNC_UNRECVR else: @@ -606,7 +606,7 @@ IF SUNDIALS_VERSION >= (3,0,0): return IDADLS_SUCCESS except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return IDADLS_JACFUNC_RECVR #Recoverable Error - except: + except Exception: traceback.print_exc() return IDADLS_JACFUNC_UNRECVR ELSE: @@ -641,7 +641,7 @@ ELSE: return IDADLS_SUCCESS except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return IDADLS_JACFUNC_RECVR #Recoverable Error - except: + except Exception: traceback.print_exc() return IDADLS_JACFUNC_UNRECVR else: @@ -658,7 +658,7 @@ ELSE: return IDADLS_SUCCESS except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return IDADLS_JACFUNC_RECVR #Recoverable Error - except: + except Exception: traceback.print_exc() return IDADLS_JACFUNC_UNRECVR @@ -688,7 +688,7 @@ cdef int ida_root(realtype t, N_Vector yv, N_Vector yvdot, realtype *gout, void gout[i]=root[i] return IDA_SUCCESS - except: + except Exception: return IDA_RTFUNC_FAIL # Unrecoverable Error cdef int ida_jacv(realtype t, N_Vector yy, N_Vector yp, N_Vector rr, N_Vector vv, N_Vector Jv, realtype cj, @@ -720,7 +720,7 @@ cdef int ida_jacv(realtype t, N_Vector yy, N_Vector yp, N_Vector rr, N_Vector vv return SPGMR_SUCCESS except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return SPGMR_ATIMES_FAIL_REC - except: + except Exception: traceback.print_exc() return SPGMR_PSOLVE_FAIL_UNREC else: @@ -736,7 +736,7 @@ cdef int ida_jacv(realtype t, N_Vector yy, N_Vector yp, N_Vector rr, N_Vector vv return SPGMR_SUCCESS except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return SPGMR_ATIMES_FAIL_REC - except: + except Exception: traceback.print_exc() return SPGMR_PSOLVE_FAIL_UNREC diff --git a/src/lib/sundials_callbacks_kinsol.pxi b/src/lib/sundials_callbacks_kinsol.pxi index bf31cf9c..fc730356 100644 --- a/src/lib/sundials_callbacks_kinsol.pxi +++ b/src/lib/sundials_callbacks_kinsol.pxi @@ -16,6 +16,7 @@ # along with this program. If not, see . import cython +from assimulo.exception import AssimuloRecoverableError IF SUNDIALS_VERSION >= (3,0,0): cdef int kin_jac(N_Vector xv, N_Vector fval, SUNMatrix Jac, @@ -39,7 +40,7 @@ IF SUNDIALS_VERSION >= (3,0,0): col_i[j] = jac[j,i] return KINDLS_SUCCESS - except: + except Exception: return KINDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description) ELSE: cdef int kin_jac(long int Neq, N_Vector xv, N_Vector fval, DlsMat Jacobian, @@ -62,7 +63,7 @@ ELSE: col_i[j] = jac[j,i] return KINDLS_SUCCESS - except: + except Exception: return KINDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description) cdef int kin_jacv(N_Vector vv, N_Vector Jv, N_Vector vx, int* new_u, @@ -83,7 +84,7 @@ cdef int kin_jacv(N_Vector vv, N_Vector Jv, N_Vector vx, int* new_u, return SPGMR_SUCCESS except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return SPGMR_ATIMES_FAIL_REC - except: + except Exception: traceback.print_exc() return SPGMR_PSOLVE_FAIL_UNREC @@ -105,7 +106,7 @@ cdef int kin_res(N_Vector xv, N_Vector fval, void *problem_data): return KIN_SUCCESS except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return KIN_REC_ERR - except: + except Exception: traceback.print_exc() return KIN_SYSFUNC_FAIL @@ -132,7 +133,7 @@ IF SUNDIALS_VERSION >= (3,0,0): zres = (pData.PREC_SOLVE)(r) except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return KIN_REC_ERR - except: + except Exception: traceback.print_exc() return KIN_SYSFUNC_FAIL @@ -157,7 +158,7 @@ IF SUNDIALS_VERSION >= (3,0,0): (pData.PREC_SETUP)(u, fval, uscale, fscale) except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return KIN_REC_ERR - except: + except Exception: traceback.print_exc() return KIN_SYSFUNC_FAIL @@ -186,7 +187,7 @@ ELSE: zres = (pData.PREC_SOLVE)(r) except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return KIN_REC_ERR - except: + except Exception: traceback.print_exc() return KIN_SYSFUNC_FAIL @@ -211,7 +212,7 @@ ELSE: (pData.PREC_SETUP)(u, fval, uscale, fscale) except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError): return KIN_REC_ERR - except: + except Exception: traceback.print_exc() return KIN_SYSFUNC_FAIL diff --git a/src/ode.pyx b/src/ode.pyx index 503d98dc..8bd333fb 100644 --- a/src/ode.pyx +++ b/src/ode.pyx @@ -22,7 +22,7 @@ from timeit import default_timer as timer import itertools import multiprocessing -from exception import * +from exception import ODE_Exception, AssimuloException from problem import Explicit_Problem, Delay_Explicit_Problem, Implicit_Problem, SingPerturbed_Problem from support import Statistics @@ -345,7 +345,7 @@ cdef class ODE: def _set_verbosity(self, verb): try: self.options["verbosity"] = int(verb) - except: + except Exception: raise AssimuloException("Verbosity must be an integer.") def _get_verbosity(self): diff --git a/src/problem.pyx b/src/problem.pyx index a9bfc23c..45572267 100644 --- a/src/problem.pyx +++ b/src/problem.pyx @@ -103,7 +103,7 @@ cdef class cImplicit_Problem(cProblem): cpdef res_internal(self, N.ndarray[double, ndim=1] res, double t, N.ndarray[double, ndim=1] y, N.ndarray[double, ndim=1] yd): try: res[:] = self.res(t,y,yd) - except: + except Exception: return ID_FAIL return ID_OK @@ -132,7 +132,7 @@ cdef class cOverdetermined_Problem(cProblem): cpdef res_internal(self, N.ndarray[double, ndim=1] res, double t, N.ndarray[double, ndim=1] y, N.ndarray[double, ndim=1] yd): try: res[:] = self.res(t,y,yd) - except: + except Exception: return ID_FAIL return ID_OK @@ -161,7 +161,7 @@ cdef class cExplicit_Problem(cProblem): cpdef int rhs_internal(self, N.ndarray[double, ndim=1] yd, double t, N.ndarray[double, ndim=1] y): try: yd[:] = self.rhs(t,y) - except: + except Exception: return ID_FAIL return ID_OK diff --git a/src/solvers/dasp3.py b/src/solvers/dasp3.py index b2bc2f3d..650315af 100644 --- a/src/solvers/dasp3.py +++ b/src/solvers/dasp3.py @@ -16,12 +16,10 @@ # along with this program. If not, see . import numpy as N -import scipy as S -import scipy.linalg as LIN from assimulo.problem import SingPerturbed_Problem -from assimulo.exception import * -from assimulo.ode import * +from assimulo.exception import Explicit_ODE_Exception, DASP3_Exception +from assimulo.ode import NORMAL, ID_PY_COMPLETE from assimulo.explicit_ode import Explicit_ODE diff --git a/src/solvers/euler.pyx b/src/solvers/euler.pyx index 0c3d3f5d..6f7e0c5f 100644 --- a/src/solvers/euler.pyx +++ b/src/solvers/euler.pyx @@ -20,9 +20,8 @@ import numpy as N import numpy.linalg as LIN import scipy.sparse as sp -#from assimulo.ode import * from assimulo.explicit_ode cimport Explicit_ODE -from assimulo.exception import * +from assimulo.exception import AssimuloException include "constants.pxi" #Includes the constants (textual include) @@ -442,7 +441,7 @@ cdef class ImplicitEuler(Explicit_ODE): def _set_h(self,h): try: self.options["h"] = float(h) - except: + except Exception: raise AssimuloException("Step-size must be a (scalar) float.") def _get_h(self): @@ -651,7 +650,7 @@ cdef class ExplicitEuler(Explicit_ODE): def _set_h(self,h): try: self.options["h"] = float(h) - except: + except Exception: raise AssimuloException("Step-size must be a (scalar) float.") def _get_h(self): diff --git a/src/solvers/glimda.py b/src/solvers/glimda.py index 623c1bb3..b41372e5 100644 --- a/src/solvers/glimda.py +++ b/src/solvers/glimda.py @@ -18,8 +18,8 @@ import numpy as N import sys -from assimulo.exception import * -from assimulo.ode import * +from assimulo.exception import GLIMDA_Exception +from assimulo.ode import ID_PY_COMPLETE, NORMAL from assimulo.implicit_ode import Implicit_ODE @@ -158,9 +158,9 @@ def integrate(self, t, y, yd, tf, opts): ROPT[10]= 0.0 #Minimum condition number #Dummy methods - dfdy_dummy = lambda t:x #df/dy - dfdx_dummy = lambda t:x #df/dx - dqdx_dummy = lambda t:x #dq/dx + dfdy_dummy = lambda t:t #df/dy + dfdx_dummy = lambda t:t #df/dx + dqdx_dummy = lambda t:t #dq/dx qeval_dummy = lambda x,t:x #q(x,t) res_dummy = lambda yd,y,t:self.problem.res(t,y,yd) #Needed to correct the order of the arguments diff --git a/src/solvers/kinsol.pyx b/src/solvers/kinsol.pyx index efdf76c3..c0dbaac5 100644 --- a/src/solvers/kinsol.pyx +++ b/src/solvers/kinsol.pyx @@ -24,7 +24,6 @@ N.import_array() import numpy.linalg import traceback -from assimulo.exception import * from assimulo.algebraic cimport Algebraic cimport sundials_includes as SUNDIALS @@ -678,7 +677,7 @@ cdef class KINSOL(Algebraic): def _set_globalization_strategy(self, lsolver): if lsolver.upper() == "LINESEARCH": - self.options["strategy"] = KIN_LINSEARCH + self.options["strategy"] = KIN_LINESEARCH elif lsolver.upper() == "NONE": self.options["strategy"] = KIN_NONE else: @@ -700,7 +699,7 @@ cdef class KINSOL(Algebraic): def _set_max_krylov(self, max_krylov): try: self.options["max_krylov"] = int(max_krylov) - except: + except Exception: raise Exception("Maximum number of krylov dimension should be an integer.") if self.options["max_krylov"] < 0: raise Exception("Maximum number of krylov dimension should be an positive integer.") diff --git a/src/solvers/odassl.py b/src/solvers/odassl.py index afa637b4..e997372f 100644 --- a/src/solvers/odassl.py +++ b/src/solvers/odassl.py @@ -17,12 +17,10 @@ import numpy as np -from assimulo.ode import * +from assimulo.ode import ID_PY_EVENT, ID_PY_COMPLETE, NORMAL from assimulo.support import set_type_shape_array from assimulo.implicit_ode import OverdeterminedDAE -from assimulo.exception import * - from assimulo.lib import odassl realtype = float diff --git a/src/solvers/odepack.py b/src/solvers/odepack.py index 2ca0adb3..8dc25fef 100644 --- a/src/solvers/odepack.py +++ b/src/solvers/odepack.py @@ -19,8 +19,8 @@ import scipy.linalg as Sc import scipy.sparse as sp import sys -from assimulo.exception import * -from assimulo.ode import * +from assimulo.exception import ODEPACK_Exception, RKStarter_Exception +from assimulo.ode import ID_PY_COMPLETE, ID_PY_EVENT, NORMAL import logging from assimulo.explicit_ode import Explicit_ODE @@ -969,7 +969,7 @@ def Nordsieck_RKn(self,t0,y,sw0): s=self.number_of_steps H=(s-1)*self.H co_nord=[N.array([1./2,1.]),N.array([2./5,3./5,1.])] - l=size(y,0) + l=N.size(y,0) y0=y[0,:] yf=self.f(t0,y0,sw0) diff --git a/src/solvers/radar5.py b/src/solvers/radar5.py index 0bf8e341..da52c56a 100644 --- a/src/solvers/radar5.py +++ b/src/solvers/radar5.py @@ -16,16 +16,11 @@ # along with this program. If not, see . import numpy as N -import scipy as S -import scipy.linalg as LIN -import copy +import pylab as P import sys -from assimulo.exception import * -from assimulo.ode import * - +from assimulo.ode import NORMAL, ID_PY_COMPLETE, ID_PY_EVENT from assimulo.explicit_ode import Explicit_ODE -from assimulo.implicit_ode import Implicit_ODE try: from assimulo.lib import radar5 @@ -274,9 +269,9 @@ def integrate(self, t, y, tf, opts): # print IWORK #Dummy methods - mas_dummy = lambda t:x - jac_dummy = (lambda t:x) if not self.usejac else self.Fjac - jaclag_dummy = (lambda t:x) if not self.usejaclag else self.problem.jaclag + mas_dummy = lambda t:t + jac_dummy = (lambda t:t) if not self.usejac else self.Fjac + jaclag_dummy = (lambda t:t) if not self.usejaclag else self.problem.jaclag nlags = 0 if not self.usejaclag else self.problem.nlags njacl = 0 if not self.usejaclag else self.problem.njacl @@ -681,7 +676,7 @@ def _get_usejac(self): def _set_usejaclag(self, jaclag): self.options["usejaclag"] = bool(jaclag) - def _get_usejaclag(self, jaclag): + def _get_usejaclag(self): return self.options["usejaclag"] usejaclag = property(_get_usejaclag,_set_usejaclag) @@ -878,7 +873,7 @@ def _set_mxst(self, mxst): if (self.options["mxst"] < 1): raise Radar_Exception("mxst must be a positive integer.") - mxst = property(_get_mxst, _set_mxst) + mxst = property(_get_mxst, _set_mxst) def _set_usejaclag(self, jaclag): self.options["usejaclag"] = bool(jaclag) @@ -903,4 +898,4 @@ def _get_usejaclag(self): """ return self.options["usejaclag"] - usejaclag = property(_get_usejaclag,_set_usejaclag) + usejaclag = property(_get_usejaclag, _set_usejaclag) diff --git a/src/solvers/radau5.py b/src/solvers/radau5.py index fa41b7e9..4a105604 100644 --- a/src/solvers/radau5.py +++ b/src/solvers/radau5.py @@ -357,7 +357,7 @@ def integrate(self, t, y, tf, opts): IOUT = 1 #solout is called after every step #Dummy methods - jac_dummy = (lambda t:x) if not self.usejac else self._jacobian + jac_dummy = (lambda t:t) if not self.usejac else self._jacobian #Check for initialization if opts["initialize"]: @@ -1151,8 +1151,8 @@ def integrate(self, t, y, yd, tf, opts): IWORK[9] = self._leny #M2 #Dummy methods - mas_dummy = lambda t:x - jac_dummy = (lambda t:x) if not self.usejac else self.problem.jac + mas_dummy = lambda t:t + jac_dummy = (lambda t:t) if not self.usejac else self.problem.jac #Check for initialization if opts["initialize"]: @@ -1586,7 +1586,7 @@ def newton(self,t,y,yd): Z = N.dot(self.T3,W) #Calculate the new Z values if self._fac_con*newnrm <= self.fnewt: #Convergence? - self._itfail = False; + self._itfail = False break else: #Iteration failed diff --git a/src/solvers/rosenbrock.py b/src/solvers/rosenbrock.py index 1e6d654f..7c8d28f2 100644 --- a/src/solvers/rosenbrock.py +++ b/src/solvers/rosenbrock.py @@ -18,10 +18,10 @@ import numpy as N import scipy.sparse as sp -from assimulo.ode import * +from assimulo.ode import NORMAL, ID_PY_EVENT, ID_PY_COMPLETE from assimulo.explicit_ode import Explicit_ODE -from assimulo.exception import * +from assimulo.exception import Rodas_Exception from assimulo.support import set_type_shape_array from assimulo.lib import rodas @@ -346,7 +346,7 @@ def _solout(self, nrsol, told, t, y, cont, lrc, irtrn): if self.problem_info["state_events"]: flag, t, y = self.event_locator(told, t, y) - #Convert to Fortram indicator. + #Convert to Fortran indicator. if flag == ID_PY_EVENT: irtrn = -1 if self._opts["report_continuously"]: @@ -411,9 +411,9 @@ def integrate(self, t, y, tf, opts): IWORK[0] = self.maxsteps #Dummy methods - mas_dummy = lambda t:x - jac_dummy = (lambda t:x) if not self.usejac else self._jacobian - dfx_dummy = lambda t:x + mas_dummy = lambda t:t + jac_dummy = (lambda t:t) if not self.usejac else self._jacobian + dfx_dummy = lambda t:t #Check for initialization if opts["initialize"]: diff --git a/src/solvers/runge_kutta.py b/src/solvers/runge_kutta.py index 51777b4c..32b2eff2 100644 --- a/src/solvers/runge_kutta.py +++ b/src/solvers/runge_kutta.py @@ -17,10 +17,9 @@ import numpy as N -from assimulo.ode import * +from assimulo.ode import ID_PY_EVENT, ID_PY_COMPLETE, NORMAL, ID_PY_OK from assimulo.explicit_ode import Explicit_ODE - -from assimulo.exception import * +from assimulo.exception import Dopri5_Exception, Explicit_ODE_Exception, AssimuloException from assimulo.lib import dopri5 @@ -480,7 +479,7 @@ def event_func(t, y): def f(dy ,t, y): try: dy[:] = self.problem.rhs(t, y, self.sw) - except: + except Exception: return False return True self.f = f @@ -815,7 +814,7 @@ def integrate(self, t, y, tf, opts): def _set_h(self,h): try: self.options["h"] = float(h) - except: + except Exception: raise AssimuloException("Step-size must be a (scalar) float.") def _get_h(self): diff --git a/src/solvers/sdirk_dae.pyx b/src/solvers/sdirk_dae.pyx index 70ac01ef..5e748f31 100644 --- a/src/solvers/sdirk_dae.pyx +++ b/src/solvers/sdirk_dae.pyx @@ -18,8 +18,8 @@ import numpy as N import sys -from assimulo.exception import * -from assimulo.ode import * +from assimulo.exception import ODEPACK_Exception, RKStarter_Exception +from assimulo.ode import ID_PY_COMPLETE, ID_PY_EVENT, NORMAL from assimulo.explicit_ode import Implicit_ODE diff --git a/src/solvers/sundials.pyx b/src/solvers/sundials.pyx index 7927f5a2..85aa459b 100644 --- a/src/solvers/sundials.pyx +++ b/src/solvers/sundials.pyx @@ -25,7 +25,7 @@ import numpy.linalg import traceback import scipy.sparse as sparse -from assimulo.exception import * +from assimulo.exception import AssimuloException from assimulo.explicit_ode cimport Explicit_ODE from assimulo.implicit_ode cimport Implicit_ODE @@ -855,7 +855,7 @@ cdef class IDA(Implicit_ODE): def _set_lsoff(self, lsoff): try: self.options["lsoff"] = bool(lsoff) - except: + except Exception: Exception('Unkown input to lsoff, must be a boolean.') def _get_lsoff(self): @@ -933,7 +933,7 @@ cdef class IDA(Implicit_ODE): def _set_suppress_alg(self,suppress_alg): try: self.options["suppress_alg"] = bool(suppress_alg) - except: + except Exception: raise AssimuloException("Unkown input to suppress_alg, must be a boolean.") def _get_suppress_alg(self): @@ -962,7 +962,7 @@ cdef class IDA(Implicit_ODE): def _set_suppress_sens(self,suppress_sens): try: self.options["suppress_sens"] = bool(suppress_sens) - except: + except Exception: raise AssimuloException("Unkown input to suppress_sens, must be a boolean.") def _get_suppress_sens(self): @@ -1090,7 +1090,7 @@ cdef class IDA(Implicit_ODE): def _set_max_cor_S(self,maxcorS): try: self.options["maxcorS"] = int(maxcorS) - except: + except Exception: raise AssimuloException("The maximum nonlinear sensitivity iterations must be a positiv integer.") def _get_max_cor_S(self): @@ -1141,7 +1141,7 @@ cdef class IDA(Implicit_ODE): def _set_max_h(self,max_h): try: self.options["maxh"] = float(max_h) - except: + except Exception: raise AssimuloException("Maximal stepsize must be a (scalar) float.") def _get_max_h(self): @@ -1388,7 +1388,7 @@ cdef class IDA(Implicit_ODE): def _set_external_event_detection(self, event_opt): try: self.options["external_event_detection"] = bool(event_opt) - except: + except Exception: raise AssimuloException("Unkown input to external_event_detection, must be a boolean.") def _get_external_event_detection(self): @@ -2108,7 +2108,7 @@ cdef class CVode(Explicit_ODE): if opts["report_continuously"]: try: flag_initialize = self.report_solution(t, y, opts) - except: + except Exception: self.store_statistics(CV_TSTOP_RETURN) raise if flag_initialize: @@ -2803,7 +2803,7 @@ cdef class CVode(Explicit_ODE): def _set_max_cor_S(self,maxcorS): try: self.options["maxcorS"] = int(maxcorS) - except: + except Exception: raise AssimuloException("The maximum nonlinear sensitivity iterations must be a positiv integer.") def _get_max_cor_S(self): @@ -2827,7 +2827,7 @@ cdef class CVode(Explicit_ODE): def _set_max_cor(self, maxcor): try: self.options["maxcor"] = int(maxcor) - except: + except Exception: raise AssimuloException("The maximum nonlinear iterations must be a positiv integer.") def _get_max_cor(self): @@ -2850,7 +2850,7 @@ cdef class CVode(Explicit_ODE): def _set_max_h(self,max_h): try: self.options["maxh"] = float(max_h) - except: + except Exception: raise AssimuloException("Maximal stepsize must be a (scalar) float.") def _get_max_h(self): @@ -2876,7 +2876,7 @@ cdef class CVode(Explicit_ODE): def _set_min_h(self,min_h): try: self.options["minh"] = float(min_h) - except: + except Exception: raise AssimuloException("Minimal stepsize must be a (scalar) float.") def _get_min_h(self): @@ -2981,7 +2981,7 @@ cdef class CVode(Explicit_ODE): def _set_suppress_sens(self,suppress_sens): try: self.options["suppress_sens"] = bool(suppress_sens) - except: + except Exception: raise AssimuloException("Unkown input to suppress_sens, must be a boolean.") def _get_suppress_sens(self): @@ -3098,7 +3098,7 @@ cdef class CVode(Explicit_ODE): def _set_max_krylov(self, maxkrylov): try: self.options["maxkrylov"] = int(maxkrylov) - except: + except Exception: raise AssimuloException("Maximum number of krylov dimension should be an integer.") if self.options["maxkrylov"] < 0: raise AssimuloException("Maximum number of krylov dimension should be an positive integer.") @@ -3192,7 +3192,7 @@ cdef class CVode(Explicit_ODE): def _set_external_event_detection(self, event_opt): try: self.options["external_event_detection"] = bool(event_opt) - except: + except Exception: raise AssimuloException("Unkown input to external_event_detection, must be a boolean.") def _get_external_event_detection(self): diff --git a/tests/solvers/test_radau5.py b/tests/solvers/test_radau5.py index 52a5fff1..000c0bf4 100644 --- a/tests/solvers/test_radau5.py +++ b/tests/solvers/test_radau5.py @@ -1140,7 +1140,7 @@ def f(t, y): try: sim.simulate(1.0) assert False, "Simulation passed without Exception, TimeLimitException should have been raised" - except: + except Exception: pass found_data = False diff --git a/tests/solvers/test_sundials.py b/tests/solvers/test_sundials.py index 4ef2c333..8019c107 100644 --- a/tests/solvers/test_sundials.py +++ b/tests/solvers/test_sundials.py @@ -393,7 +393,7 @@ def test_statistics_stored(self): try: exp_sim.simulate(1.0) assert False, "Simulation passed without Exception, TimeLimitException should have been raised" - except: + except Exception: pass found_data = False diff --git a/tests/test_examples.py b/tests/test_examples.py index 7115d9cf..5d31ee67 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -18,219 +18,219 @@ import nose from assimulo import testattr from assimulo.exception import AssimuloException -import assimulo.examples +from assimulo.examples import * class Test_Examples: @testattr(stddist = True) def test_cvode_with_jac_sparse(self): try: - assimulo.examples.cvode_with_jac_sparse.run_example(with_plots=False) + cvode_with_jac_sparse.run_example(with_plots=False) except AssimuloException: pass #Handle the case when SuperLU is not installed @testattr(stddist = True) def test_ida_with_user_defined_handle_result(self): - assimulo.examples.ida_with_user_defined_handle_result.run_example(with_plots=False) + ida_with_user_defined_handle_result.run_example(with_plots=False) @testattr(stddist = True) def test_radau5dae_time_events_f(self): - assimulo.examples.radau5dae_time_events.run_example(with_plots=False) + radau5dae_time_events.run_example(with_plots=False) @testattr(stddist = True) def test_kinsol_basic(self): - assimulo.examples.kinsol_basic.run_example(with_plots=False) + kinsol_basic.run_example(with_plots=False) @testattr(stddist = True) def test_kinsol_with_jac(self): - assimulo.examples.kinsol_with_jac.run_example(with_plots=False) + kinsol_with_jac.run_example(with_plots=False) @testattr(stddist = True) def test_kinsol_ors(self): - assimulo.examples.kinsol_ors.run_example(with_plots=False) + kinsol_ors.run_example(with_plots=False) @testattr(stddist = True) def test_cvode_with_preconditioning(self): - assimulo.examples.cvode_with_preconditioning.run_example(with_plots=False) + cvode_with_preconditioning.run_example(with_plots=False) @testattr(stddist = True) def test_dasp3_basic(self): print("Currently not running test_dasp3_basic. Numerically unstable problem.") - #assimulo.examples.dasp3_basic.run_example(with_plots=False) + #dasp3_basic.run_example(with_plots=False) @testattr(stddist = True) def test_cvode_gyro(self): - assimulo.examples.cvode_gyro.run_example(with_plots=False) + cvode_gyro.run_example(with_plots=False) @testattr(stddist = True) def test_cvode_basic(self): - assimulo.examples.cvode_basic.run_example(with_plots=False) + cvode_basic.run_example(with_plots=False) @testattr(stddist = True) def test_cvode_with_disc(self): - assimulo.examples.cvode_with_disc.run_example(with_plots=False) + cvode_with_disc.run_example(with_plots=False) @testattr(stddist = True) def test_cvode_with_initial_sensitivity(self): - assimulo.examples.cvode_with_initial_sensitivity.run_example(with_plots=False) + cvode_with_initial_sensitivity.run_example(with_plots=False) @testattr(stddist = True) def test_cvode_with_jac(self): - assimulo.examples.cvode_with_jac.run_example(with_plots=False) + cvode_with_jac.run_example(with_plots=False) @testattr(stddist = True) def test_cvode_with_jac_spgmr(self): - assimulo.examples.cvode_with_jac_spgmr.run_example(with_plots=False) + cvode_with_jac_spgmr.run_example(with_plots=False) @testattr(stddist = True) def test_ida_with_jac_spgmr(self): - assimulo.examples.ida_with_jac_spgmr.run_example(with_plots=False) + ida_with_jac_spgmr.run_example(with_plots=False) @testattr(stddist = True) def test_cvode_with_parameters(self): - assimulo.examples.cvode_with_parameters.run_example(with_plots=False) + cvode_with_parameters.run_example(with_plots=False) @testattr(stddist = True) def test_cvode_with_parameters_fcn(self): - assimulo.examples.cvode_with_parameters_fcn.run_example(with_plots=False) + cvode_with_parameters_fcn.run_example(with_plots=False) @testattr(stddist = True) def test_cvode_with_parameters_modified(self): - assimulo.examples.cvode_with_parameters_modified.run_example(with_plots=False) + cvode_with_parameters_modified.run_example(with_plots=False) @testattr(stddist = True) def test_euler_basic(self): - assimulo.examples.euler_basic.run_example(with_plots=False) + euler_basic.run_example(with_plots=False) @testattr(stddist = True) def test_euler_with_disc(self): - assimulo.examples.euler_with_disc.run_example(with_plots=False) + euler_with_disc.run_example(with_plots=False) @testattr(stddist = True) def test_rungekutta4_basic(self): - assimulo.examples.rungekutta4_basic.run_example(with_plots=False) + rungekutta4_basic.run_example(with_plots=False) @testattr(stddist = True) def test_rungekutta34_basic(self): - assimulo.examples.rungekutta34_basic.run_example(with_plots=False) + rungekutta34_basic.run_example(with_plots=False) @testattr(stddist = True) def test_rungekutta34_with_disc(self): - assimulo.examples.rungekutta34_with_disc.run_example(with_plots=False) + rungekutta34_with_disc.run_example(with_plots=False) @testattr(stddist = True) def test_ida_with_disc(self): - assimulo.examples.ida_with_disc.run_example(with_plots=False) + ida_with_disc.run_example(with_plots=False) @testattr(stddist = True) def test_ida_with_initial_sensitivity(self): - assimulo.examples.ida_with_initial_sensitivity.run_example(with_plots=False) + ida_with_initial_sensitivity.run_example(with_plots=False) @testattr(stddist = True) def test_ida_with_jac(self): - assimulo.examples.ida_with_jac.run_example(with_plots=False) + ida_with_jac.run_example(with_plots=False) @testattr(stddist = True) def test_ida_with_parameters(self): - assimulo.examples.ida_with_parameters.run_example(with_plots=False) + ida_with_parameters.run_example(with_plots=False) @testattr(stddist = True) def test_radau5ode_vanderpol_c(self): - assimulo.examples.radau5ode_vanderpol.run_example(with_plots=False) + radau5ode_vanderpol.run_example(with_plots=False) @testattr(stddist = True) def test_radau5ode_vanderpol_f(self): - assimulo.examples.radau5ode_vanderpol.run_example(with_plots=False) + radau5ode_vanderpol.run_example(with_plots=False) @testattr(stddist = True) def test_radau5ode_with_disc_c(self): - assimulo.examples.radau5ode_with_disc.run_example(with_plots=False) + radau5ode_with_disc.run_example(with_plots=False) @testattr(stddist = True) def test_radau5ode_with_disc_f(self): - assimulo.examples.radau5ode_with_disc.run_example(with_plots=False) + radau5ode_with_disc.run_example(with_plots=False) @testattr(stddist = True) def test_radau5ode_with_disc_sparse(self): - assimulo.examples.radau5ode_with_disc_sparse.run_example(with_plots=False) + radau5ode_with_disc_sparse.run_example(with_plots=False) @testattr(stddist = True) def test_radau5ode_with_jac_sparse_c(self): - assimulo.examples.radau5ode_with_jac_sparse.run_example(with_plots=False) + radau5ode_with_jac_sparse.run_example(with_plots=False) @testattr(stddist = True) def test_radau5dae_vanderpol_f(self): - assimulo.examples.radau5dae_vanderpol.run_example(with_plots=False) + radau5dae_vanderpol.run_example(with_plots=False) @testattr(stddist = True) def test_dopri5_basic(self): - assimulo.examples.dopri5_basic.run_example(with_plots=False) + dopri5_basic.run_example(with_plots=False) @testattr(stddist = True) def test_dopri5_with_disc(self): - assimulo.examples.dopri5_with_disc.run_example(with_plots=False) + dopri5_with_disc.run_example(with_plots=False) @testattr(stddist = True) def test_rodasode_vanderpol(self): - assimulo.examples.rodasode_vanderpol.run_example(with_plots=False) + rodasode_vanderpol.run_example(with_plots=False) @testattr(stddist = True) def test_mech_system_pendulum1(self): """ This tests the class Mechanical_system together with ind1 and ida """ - assimulo.examples.mech_system_pendulum.run_example('ind1',with_plots=False,with_test=True) + mech_system_pendulum.run_example('ind1',with_plots=False,with_test=True) @testattr(stddist = True) def test_mech_system_pendulum2(self): """ This tests the class Mechanical_system together with ind2 and ida """ - assimulo.examples.mech_system_pendulum.run_example('ind2',with_plots=False,with_test=True) + mech_system_pendulum.run_example('ind2',with_plots=False,with_test=True) @testattr(stddist = True) def test_mech_system_pendulum3(self): """ This tests the class Mechanical_system together with ind3 and ida """ - assimulo.examples.mech_system_pendulum.run_example('ind3',with_plots=False,with_test=True) + mech_system_pendulum.run_example('ind3',with_plots=False,with_test=True) @testattr(stddist = True) def test_mech_system_pendulum_ggl2(self): """ This tests the class Mechanical_system together with ggl2 and ida """ - assimulo.examples.mech_system_pendulum.run_example('ggl2',with_plots=False,with_test=True) + mech_system_pendulum.run_example('ggl2',with_plots=False,with_test=True) @testattr(stddist = True) def test_mech_system_pendulum_ovstab2(self): """ This tests the class Mechanical_system together with ovstab2 and odassl """ - assimulo.examples.mech_system_pendulum.run_example('ovstab2',with_plots=False,with_test=True) + mech_system_pendulum.run_example('ovstab2',with_plots=False,with_test=True) @testattr(stddist = True) def test_mech_system_pendulum_ovstab1(self): """ This tests the class Mechanical_system together with ovstab1 and odassl """ - assimulo.examples.mech_system_pendulum.run_example('ovstab1',with_plots=False,with_test=True) + mech_system_pendulum.run_example('ovstab1',with_plots=False,with_test=True) @testattr(stddist = True) def test_lsodar_vanderpol(self): - assimulo.examples.lsodar_vanderpol.run_example(with_plots=False) + lsodar_vanderpol.run_example(with_plots=False) @testattr(stddist = True) def test_lsodar_with_disc(self): - assimulo.examples.lsodar_with_disc.run_example(with_plots=False) + lsodar_with_disc.run_example(with_plots=False) @testattr(stddist = True) def test_euler_vanderpol(self): - assimulo.examples.euler_vanderpol.run_example(with_plots=False) + euler_vanderpol.run_example(with_plots=False) @testattr(stddist = True) def test_cvode_basic_backward(self): - assimulo.examples.cvode_basic_backward.run_example(with_plots=False) + cvode_basic_backward.run_example(with_plots=False) @testattr(stddist = True) def test_ida_basic_backward(self): - assimulo.examples.ida_basic_backward.run_example(with_plots=False) + ida_basic_backward.run_example(with_plots=False)