Skip to content

Commit

Permalink
remaining import & exception cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMeisrimelModelon committed Dec 21, 2023
1 parent 072db04 commit 8b77e5d
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 2 additions & 4 deletions src/algebraic.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
from problem import Algebraic_Problem

include "constants.pxi" #Includes the constants (textual include)
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/implicit_ode.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import sys
import numpy as N
cimport numpy as N

from exception import *
from exception import TerminateSimulation
from timeit import default_timer as timer
import warnings

Expand Down
52 changes: 26 additions & 26 deletions src/lib/sundials_callbacks_ida_cvode.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cdef int cv_rhs(realtype t, N_Vector yv, N_Vector yvdot, void* problem_data):
rhs = (<object>pData.RHS)(t,y,sw=<list>pData.sw, p=p)
else:
rhs = (<object>pData.RHS)(t,y,p)
except:
except Exception:
return CV_REC_ERR #Recoverable Error (See Sundials description)

else: #No sensitivity
Expand All @@ -46,7 +46,7 @@ cdef int cv_rhs(realtype t, N_Vector yv, N_Vector yvdot, void* problem_data):
rhs = (<object>pData.RHS)(t,y,<list>pData.sw)
else:
rhs = (<object>pData.RHS)(t,y)
except:
except Exception:
return CV_REC_ERR #Recoverable Error (See Sundials description)

for i in range(pData.dim):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -234,7 +234,7 @@ IF SUNDIALS_VERSION >= (3,0,0):
jac=(<object>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:
Expand All @@ -245,7 +245,7 @@ IF SUNDIALS_VERSION >= (3,0,0):
jac=(<object>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

Expand Down Expand Up @@ -284,7 +284,7 @@ ELSE:
jac=(<object>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:
Expand All @@ -295,7 +295,7 @@ ELSE:
jac=(<object>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

Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -375,7 +375,7 @@ IF SUNDIALS_VERSION >= (3,0,0):

try:
ret = (<object>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
Expand All @@ -399,7 +399,7 @@ IF SUNDIALS_VERSION >= (3,0,0):

try:
zres = (<object>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):
Expand All @@ -422,7 +422,7 @@ ELSE:

try:
ret = (<object>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
Expand All @@ -446,7 +446,7 @@ ELSE:

try:
zres = (<object>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):
Expand Down Expand Up @@ -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
"""

Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down
16 changes: 8 additions & 8 deletions src/lib/sundials_callbacks_kinsol.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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,
Expand All @@ -62,7 +62,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,
Expand All @@ -83,7 +83,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

Expand All @@ -105,7 +105,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

Expand All @@ -132,7 +132,7 @@ IF SUNDIALS_VERSION >= (3,0,0):
zres = (<object>pData.PREC_SOLVE)(r)
except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return KIN_REC_ERR
except:
except Exception:
traceback.print_exc()
return KIN_SYSFUNC_FAIL

Expand All @@ -157,7 +157,7 @@ IF SUNDIALS_VERSION >= (3,0,0):
(<object>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

Expand Down Expand Up @@ -186,7 +186,7 @@ ELSE:
zres = (<object>pData.PREC_SOLVE)(r)
except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
return KIN_REC_ERR
except:
except Exception:
traceback.print_exc()
return KIN_SYSFUNC_FAIL

Expand All @@ -211,7 +211,7 @@ ELSE:
(<object>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

Expand Down
4 changes: 2 additions & 2 deletions src/ode.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions src/problem.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Loading

0 comments on commit 8b77e5d

Please sign in to comment.