From f748446686a9aa8ae4495bf6bc0c3d961a3537db Mon Sep 17 00:00:00 2001 From: PeterMeisrimelModelon <92585725+PeterMeisrimelModelon@users.noreply.github.com> Date: Wed, 24 Jan 2024 11:19:43 +0100 Subject: [PATCH] Unifying scipy imports --- examples/cvode_with_jac_sparse.py | 4 +-- examples/kinsol_ors.py | 33 +++++++++++------------ examples/mech_system_pendulum.py | 7 +++-- examples/radau5ode_with_disc_sparse.py | 4 +-- examples/radau5ode_with_jac_sparse.py | 6 ++--- src/lib/sundials_callbacks_ida_cvode.pxi | 13 ++++----- src/solvers/euler.pyx | 4 +-- src/solvers/odepack.py | 27 +++++++++---------- src/solvers/radau5.py | 26 +++++++++--------- src/solvers/sundials.pyx | 2 -- tests/solvers/test_euler.py | 4 +-- tests/solvers/test_odepack.py | 4 +-- tests/solvers/test_radau5.py | 34 ++++++++++++------------ tests/solvers/test_rosenbrock.py | 4 +-- tests/solvers/test_sundials.py | 4 +-- 15 files changed, 85 insertions(+), 91 deletions(-) diff --git a/examples/cvode_with_jac_sparse.py b/examples/cvode_with_jac_sparse.py index d7da5cc3..bdc745c9 100644 --- a/examples/cvode_with_jac_sparse.py +++ b/examples/cvode_with_jac_sparse.py @@ -16,7 +16,7 @@ # along with this program. If not, see . import numpy as np -import scipy.sparse as SP +import scipy.sparse as sps import nose from assimulo.solvers import CVode from assimulo.problem import Explicit_Problem @@ -59,7 +59,7 @@ def jac(t,y): rowvals = [0, 1, 0, 1, 2, 0, 1] data = [-0.04, 0.04, 1e4*y[2], -1e4*y[2]-6e7*y[1], 6e7*y[1], 1e4*y[1], -1e4*y[1]] - J = SP.csc_matrix((data, rowvals, colptrs)) + J = sps.csc_matrix((data, rowvals, colptrs)) return J #Defines an Assimulo explicit problem diff --git a/examples/kinsol_ors.py b/examples/kinsol_ors.py index 046cbb5c..f904ad42 100644 --- a/examples/kinsol_ors.py +++ b/examples/kinsol_ors.py @@ -15,19 +15,16 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . -import numpy as np -import scipy.linalg as LIN -import scipy.io as IO -import scipy.sparse as SPARSE -import scipy.sparse.linalg as LINSP -import nose import os +import nose +import numpy as np +import scipy as sp +import scipy.sparse as sps from assimulo.solvers import KINSOL from assimulo.problem import Algebraic_Problem import warnings -import scipy.sparse -warnings.simplefilter("ignore", scipy.sparse.SparseEfficiencyWarning) +warnings.simplefilter("ignore", sps.SparseEfficiencyWarning) file_path = os.path.dirname(os.path.realpath(__file__)) @@ -39,22 +36,22 @@ def run_example(with_plots=True): Iterative Methods for Sparse Linear Systems. """ #Read the original matrix - A_original = IO.mmread(os.path.join(file_path,"kinsol_ors_matrix.mtx")) + A_original = sp.io.mmread(os.path.join(file_path,"kinsol_ors_matrix.mtx")) #Scale the original matrix - A = SPARSE.spdiags(1.0/A_original.diagonal(), 0, len(A_original.diagonal()), len(A_original.diagonal())) * A_original + A = sps.spdiags(1.0/A_original.diagonal(), 0, len(A_original.diagonal()), len(A_original.diagonal())) * A_original #Preconditioning by Symmetric Gauss Seidel if True: - D = SPARSE.spdiags(A.diagonal(), 0, len(A_original.diagonal()), len(A_original.diagonal())) - Dinv = SPARSE.spdiags(1.0/A.diagonal(), 0, len(A_original.diagonal()), len(A_original.diagonal())) - E = -SPARSE.tril(A,k=-1) - F = -SPARSE.triu(A,k=1) + D = sps.spdiags(A.diagonal(), 0, len(A_original.diagonal()), len(A_original.diagonal())) + Dinv = sps.spdiags(1.0/A.diagonal(), 0, len(A_original.diagonal()), len(A_original.diagonal())) + E = -sps.tril(A,k=-1) + F = -sps.triu(A,k=1) L = (D-E).dot(Dinv) U = D-F Prec = L.dot(U) - solvePrec = LINSP.factorized(Prec) + solvePrec = sps.linalg.factorized(Prec) #Create the RHS b = A.dot(np.ones(A.shape[0])) @@ -91,7 +88,7 @@ def prec_solve(r): def setup_param(solver): solver.linear_solver = "spgmr" solver.max_dim_krylov_subspace = 10 - solver.ftol = LIN.norm(res(solver.y0))*1e-9 + solver.ftol = np.linalg.norm(res(solver.y0))*1e-9 solver.max_iter = 300 solver.verbosity = 10 solver.globalization_strategy = "none" @@ -105,8 +102,8 @@ def setup_param(solver): #Solve Preconditioned system y_prec = alg_solver_prec.solve() - print("Error , in y: ", LIN.norm(y-np.ones(len(y)))) - print("Error (preconditioned), in y: ", LIN.norm(y_prec-np.ones(len(y_prec)))) + print("Error , in y: ", np.linalg.norm(y-np.ones(len(y)))) + print("Error (preconditioned), in y: ", np.linalg.norm(y_prec-np.ones(len(y_prec)))) if with_plots: import pylab as P diff --git a/examples/mech_system_pendulum.py b/examples/mech_system_pendulum.py index 6f13bdcc..852b2e11 100644 --- a/examples/mech_system_pendulum.py +++ b/examples/mech_system_pendulum.py @@ -15,9 +15,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . -import numpy as np import nose -import scipy.linalg as sl +import numpy as np from assimulo.special_systems import Mechanical_System from assimulo.solvers import IDA, ODASSL @@ -58,10 +57,10 @@ def run_example(index="ind1", with_plots=True, with_test=False): final_residual=my_pend.res(0.,dae_pend.y,dae_pend.yd) print(my_pend.name+" Residuals after the integration run\n") - print(final_residual, 'Norm: ', sl.norm(final_residual)) + print(final_residual, 'Norm: ', np.linalg.norm(final_residual)) if with_test: - nose.tools.assert_less(sl.norm(final_residual), 1.5e-1) + nose.tools.assert_less(np.linalg.norm(final_residual), 1.5e-1) if with_plots: dae_pend.plot(mask=[1,1]+(len(my_pend.y0)-2)*[0]) return my_pend, dae_pend diff --git a/examples/radau5ode_with_disc_sparse.py b/examples/radau5ode_with_disc_sparse.py index bed2de1c..2906f318 100644 --- a/examples/radau5ode_with_disc_sparse.py +++ b/examples/radau5ode_with_disc_sparse.py @@ -16,7 +16,7 @@ # along with this program. If not, see . import numpy as np -import scipy.sparse as sp +import scipy.sparse as sps import nose from assimulo.solvers import Radau5ODE from assimulo.problem import Explicit_Problem @@ -54,7 +54,7 @@ def rhs(self,t,y,sw): return np.array([yd_0,yd_1,yd_2]) def jac(self, t, y): - return sp.csc_matrix((len(y), len(y)), dtype = 'float') + return sps.csc_matrix((len(y), len(y)), dtype = 'float') jac_nnz = 0 diff --git a/examples/radau5ode_with_jac_sparse.py b/examples/radau5ode_with_jac_sparse.py index 4264300d..54abe28b 100644 --- a/examples/radau5ode_with_jac_sparse.py +++ b/examples/radau5ode_with_jac_sparse.py @@ -15,9 +15,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . -import numpy as np -import scipy.sparse as SP import nose +import numpy as np +import scipy.sparse as sps from assimulo.solvers import Radau5ODE from assimulo.problem import Explicit_Problem @@ -57,7 +57,7 @@ def jac(t,y): rowvals = [0, 1, 0, 1, 2, 0, 1] data = [-0.04, 0.04, 1e4*y[2], -1e4*y[2]-6e7*y[1], 6e7*y[1], 1e4*y[1], -1e4*y[1]] - J = SP.csc_matrix((data, rowvals, colptrs)) + J = sps.csc_matrix((data, rowvals, colptrs)) return J #Defines an Assimulo explicit problem diff --git a/src/lib/sundials_callbacks_ida_cvode.pxi b/src/lib/sundials_callbacks_ida_cvode.pxi index d200c589..5f84ea4e 100644 --- a/src/lib/sundials_callbacks_ida_cvode.pxi +++ b/src/lib/sundials_callbacks_ida_cvode.pxi @@ -17,6 +17,7 @@ import cython import traceback +import scipy.sparse as sps from assimulo.exception import AssimuloRecoverableError cdef int cv_rhs(realtype t, N_Vector yv, N_Vector yvdot, void* problem_data) noexcept: @@ -123,8 +124,8 @@ IF SUNDIALS_VERSION >= (3,0,0): else: jac=(pData.JAC)(t,y) - if not isinstance(jac, sparse.csc_matrix): - jac = sparse.csc_matrix(jac) + if not isinstance(jac, sps.csc_matrix): + jac = sps.csc_matrix(jac) raise AssimuloException("The Jacobian must be stored on Scipy's CSC format.") ret_nnz = jac.nnz if ret_nnz > nnz: @@ -188,8 +189,8 @@ ELSE: else: jac=(pData.JAC)(t,y) - if not isinstance(jac, sparse.csc_matrix): - jac = sparse.csc_matrix(jac) + if not isinstance(jac, sps.csc_matrix): + jac = sps.csc_matrix(jac) raise AssimuloException("The Jacobian must be stored on Scipy's CSC format.") ret_nnz = jac.nnz if ret_nnz > nnz: @@ -250,7 +251,7 @@ IF SUNDIALS_VERSION >= (3,0,0): traceback.print_exc() return CVDLS_JACFUNC_UNRECVR - if isinstance(jac, sparse.csc_matrix): + if isinstance(jac, sps.csc_matrix): for j in range(Neq): col_i = Jacobian.cols[j] for i in range(jac.indptr[j], jac.indptr[j+1]): @@ -300,7 +301,7 @@ ELSE: traceback.print_exc() return CVDLS_JACFUNC_UNRECVR - if isinstance(jac, sparse.csc_matrix): + if isinstance(jac, sps.csc_matrix): for j in range(Neq): col_i = DENSE_COL(Jacobian, j) for i in range(jac.indptr[j], jac.indptr[j+1]): diff --git a/src/solvers/euler.pyx b/src/solvers/euler.pyx index 1d98e4fa..aa64c9f9 100644 --- a/src/solvers/euler.pyx +++ b/src/solvers/euler.pyx @@ -19,7 +19,7 @@ cimport numpy as np import numpy as np -import scipy.sparse as sp +import scipy.sparse as sps from assimulo.explicit_ode cimport Explicit_ODE from assimulo.exception import AssimuloException @@ -331,7 +331,7 @@ cdef class ImplicitEuler(Explicit_ODE): if self.usejac: #Retrieve the user-defined jacobian jac = self.problem.jac(t,y) - if isinstance(jac, sp.csc_matrix): + if isinstance(jac, sps.csc_matrix): jac = jac.toarray() else: #Calculate a numeric jacobian delt = np.array([(self._eps*max(abs(yi),1.e-5))**0.5 for yi in y])*np.identity(self._leny) #Calculate a disturbance diff --git a/src/solvers/odepack.py b/src/solvers/odepack.py index 70d13d71..e3943c32 100644 --- a/src/solvers/odepack.py +++ b/src/solvers/odepack.py @@ -18,8 +18,7 @@ import sys import logging import numpy as np -import scipy.linalg as Sc -import scipy.sparse as sp +import scipy.sparse as sps from assimulo.exception import ODEPACK_Exception, RKStarter_Exception from assimulo.ode import ID_PY_COMPLETE, ID_PY_EVENT, NORMAL @@ -154,11 +153,11 @@ def autostart(self,t,y,sw0=[]): direction=np.sign(tf-t0) #Perturb initial condition and compute rough Lipschitz constant - cent=Sc.norm(y)/normscale/100. + cent=np.linalg.norm(y)/normscale/100. v0=y+cent*np.random.rand(len(y),1) u0prime=f(t,y,sw0) v0prime=f(t,v0,sw0) - Lip=Sc.norm(u0prime-v0prime)/Sc.norm(y-v0) + Lip=np.linalg.norm(u0prime-v0prime)/np.linalg.norm(y-v0) h=direction*min(1e-3*T,max(1e-8*T,0.05/Lip)) #step 1: fwd Euler step u1=y+h*u0prime @@ -168,11 +167,11 @@ def autostart(self,t,y,sw0=[]): u0comp=u1-h*u1prime #step 3: estimate of local error du=u0comp-y - dunorm=Sc.norm(du) + dunorm=np.linalg.norm(du) errnorm=dunorm/normscale #step 4: new estimate of Lipschitz constant u0comprime=f(t0,u0comp,sw0) - L=Sc.norm(u0comprime-u0prime)/dunorm + L=np.linalg.norm(u0comprime-u0prime)/dunorm M=np.dot(du,u0comprime-u0prime)/dunorm**2 #step 5: construct a refined starting stepsize theta1=tolscale/np.sqrt(errnorm) @@ -203,7 +202,7 @@ def integrate_start(self, t, y): # a) get previous stepsize if any hu, nqu ,nq ,nyh, nqnyh = get_lsod_common() #H = hu if hu != 0. else 1.e-4 # this needs some reflections - #H =(abs(RWORK[0]-t)*((self.options["rtol"])**(1/(self.rkstarter+1))))/(100*Sc.norm(self.problem.rhs(t,y,self.sw))+10)#if hu != 0. else 1.e-4 + #H =(abs(RWORK[0]-t)*((self.options["rtol"])**(1/(self.rkstarter+1))))/(100*np.linalg.norm(self.problem.rhs(t,y,self.sw))+10)#if hu != 0. else 1.e-4 H=1e-2 #H=self.autostart(t,y) #H=3*H @@ -271,7 +270,7 @@ def _jacobian(self, t, y): """ jac = self.problem.jac(t,y) - if isinstance(jac, sp.csc_matrix): + if isinstance(jac, sps.csc_matrix): jac = jac.toarray() return jac @@ -908,7 +907,7 @@ def rk_like13(self, t0, y0, sw0): c+=1 nord[0,:] = y0 nord[1,:] = h*K[0,:] - nord[2:,:] = Sc.solve(self.A[self.number_of_steps],b) + nord[2:,:] = np.linalg.solve(self.A[self.number_of_steps],b) return nord def rk_like14(self, t0, y0, sw0): """ @@ -931,7 +930,7 @@ def rk_like14(self, t0, y0, sw0): c+=1 nord[0,:] = y0 nord[1,:] = h*K[0,:] - nord[2:,:] = Sc.solve(self.A[self.number_of_steps],b) + nord[2:,:] = np.linalg.solve(self.A[self.number_of_steps],b) return nord def rk_like15(self, t0, y0, sw0): """ @@ -954,7 +953,7 @@ def rk_like15(self, t0, y0, sw0): c+=1 nord[0,:] = y0 nord[1,:] = h*K[0,:] - nord[2:,:] = Sc.solve(self.A[self.number_of_steps],b) + nord[2:,:] = np.linalg.solve(self.A[self.number_of_steps],b) return nord def nordsieck(self,k): """ @@ -975,12 +974,12 @@ def Nordsieck_RKn(self,t0,y,sw0): co=np.array([co_nord[0]]) nord_n=np.vander(co_nord[0],self.number_of_steps+1) b=y[1:]-y0-co.T*yf - nord=Sc.solve(nord_n[0:2,0:2],b) + nord=np.linalg.solve(nord_n[0:2,0:2],b) elif l==4: co=np.array([co_nord[1]]) nord_n=np.vander(co_nord[1],self.number_of_steps+1) b=y[1:]-y0-H*co.T*yf - nord=Sc.solve(nord_n[0:3,0:3],b) + nord=np.linalg.solve(nord_n[0:3,0:3],b) nord=np.vstack((y0,H*yf,nord[::-1])) return nord def Nordsieck_RKs(self,t0,y,sw0): @@ -994,7 +993,7 @@ def Nordsieck_RKs(self,t0,y,sw0): co=co_nord[s-2] co=np.array([co]) b=y[1:]-y0-H*co.T*yf - nord=Sc.solve(A[s],b) + nord=np.linalg.solve(A[s],b) nord=np.vstack((y0,H*yf,nord)) return nord diff --git a/src/solvers/radau5.py b/src/solvers/radau5.py index 6b368b10..5a3695f7 100644 --- a/src/solvers/radau5.py +++ b/src/solvers/radau5.py @@ -16,8 +16,8 @@ # along with this program. If not, see . import numpy as np -import scipy as S -import scipy.sparse as sp +import scipy as sp +import scipy.sparse as sps from assimulo.exception import ( AssimuloException, @@ -339,7 +339,7 @@ def _jacobian(self, t, y): ret = 0 try: jac = self.problem.jac(t,y) - if isinstance(jac, sp.csc_matrix) and (self.options["linear_solver"] == "DENSE"): + if isinstance(jac, sps.csc_matrix) and (self.options["linear_solver"] == "DENSE"): jac = jac.toarray() except BaseException as E: jac = np.eye(len(y)) @@ -694,8 +694,8 @@ def newton(self,t,y): for k in range(20): self._curiter = 0 #Reset the iteration - self._fac_con = max(self._fac_con, self._eps)**0.8; - self._theta = abs(self.thet); + self._fac_con = max(self._fac_con, self._eps)**0.8 + self._theta = abs(self.thet) if self._needjac: self._jac = self.jacobian(t,y) @@ -707,9 +707,9 @@ def newton(self,t,y): self._g = self._gamma/self.h self._B = self._g*self.I - self._jac - self._P1,self._L1,self._U1 = S.linalg.lu(self._B) #LU decomposition - self._P2,self._L2,self._U2 = S.linalg.lu(self._a*self.I-self._jac) - self._P3,self._L3,self._U3 = S.linalg.lu(self._b*self.I-self._jac) + self._P1,self._L1,self._U1 = sp.linalg.lu(self._B) #LU decomposition + self._P2,self._L2,self._U2 = sp.linalg.lu(self._a*self.I-self._jac) + self._P3,self._L3,self._U3 = sp.linalg.lu(self._b*self.I-self._jac) self._needLU = False @@ -1513,8 +1513,8 @@ def newton(self,t,y,yd): for k in range(20): self._curiter = 0 #Reset the iteration - self._fac_con = max(self._fac_con, self._eps)**0.8; - self._theta = abs(self.thet); + self._fac_con = max(self._fac_con, self._eps)**0.8 + self._theta = abs(self.thet) if self._needjac: self._jac = self.jacobian(t,y,yd) @@ -1526,9 +1526,9 @@ def newton(self,t,y,yd): self._g = self._gamma/self.h self._B = self._g*self.M - self._jac - self._P1,self._L1,self._U1 = S.linalg.lu(self._B) #LU decomposition - self._P2,self._L2,self._U2 = S.linalg.lu(self._a*self.M-self._jac) - self._P3,self._L3,self._U3 = S.linalg.lu(self._b*self.M-self._jac) + self._P1,self._L1,self._U1 = sp.linalg.lu(self._B) #LU decomposition + self._P2,self._L2,self._U2 = sp.linalg.lu(self._a*self.M-self._jac) + self._P3,self._L3,self._U3 = sp.linalg.lu(self._b*self.M-self._jac) self._needLU = False diff --git a/src/solvers/sundials.pyx b/src/solvers/sundials.pyx index 079c0ecd..761197b4 100644 --- a/src/solvers/sundials.pyx +++ b/src/solvers/sundials.pyx @@ -20,8 +20,6 @@ import numpy as np cimport numpy as np -import scipy.sparse as sparse - from assimulo.exception import AssimuloException from assimulo.explicit_ode cimport Explicit_ODE diff --git a/tests/solvers/test_euler.py b/tests/solvers/test_euler.py index daa3e8aa..501f2e8a 100644 --- a/tests/solvers/test_euler.py +++ b/tests/solvers/test_euler.py @@ -21,7 +21,7 @@ from assimulo.problem import Explicit_Problem from assimulo.exception import AssimuloException, TimeLimitExceeded import numpy as np -import scipy.sparse as sp +import scipy.sparse as sps float_regex = "[\s]*[\d]*.[\d]*((e|E)(\+|\-)\d\d|)" @@ -293,7 +293,7 @@ def test_usejac_csc_matrix(self): This tests the functionality of the property usejac. """ f = lambda t,x: np.array([x[1], -9.82]) #Defines the rhs - jac = lambda t,x: sp.csc_matrix(np.array([[0.,1.],[0.,0.]])) #Defines the jacobian + jac = lambda t,x: sps.csc_matrix(np.array([[0.,1.],[0.,0.]])) #Defines the jacobian exp_mod = Explicit_Problem(f, [1.0,0.0]) exp_mod.jac = jac diff --git a/tests/solvers/test_odepack.py b/tests/solvers/test_odepack.py index dc0fe731..b5037e67 100644 --- a/tests/solvers/test_odepack.py +++ b/tests/solvers/test_odepack.py @@ -23,7 +23,7 @@ from assimulo.exception import TimeLimitExceeded import numpy as np -import scipy.sparse as sp +import scipy.sparse as sps float_regex = "[\s]*[\d]*.[\d]*((e|E)(\+|\-)\d\d|)" @@ -156,7 +156,7 @@ def jac_sparse(t,y): J[1,0]=my*(-2.*y[0]*y[1]-1.) J[1,1]=my*(1.-y[0]**2) - return sp.csc_matrix(J) + return sps.csc_matrix(J) #Define an Assimulo problem y0 = [2.0,-0.6] #Initial conditions diff --git a/tests/solvers/test_radau5.py b/tests/solvers/test_radau5.py index 2e5ca5d4..5731d623 100644 --- a/tests/solvers/test_radau5.py +++ b/tests/solvers/test_radau5.py @@ -24,7 +24,7 @@ from assimulo.problem import Implicit_Problem from assimulo.lib.radau_core import Radau_Exception from assimulo.exception import TimeLimitExceeded -import scipy.sparse as sp +import scipy.sparse as sps import numpy as np import re @@ -462,7 +462,7 @@ def jac_sparse(t,y): J[1,0]=my*(-2.*y[0]*y[1]-1.) J[1,1]=my*(1.-y[0]**2) - return sp.csc_matrix(J) + return sps.csc_matrix(J) #Define an Assimulo problem y0 = [2.0,-0.6] #Initial conditions @@ -844,7 +844,7 @@ def test_solver_sparse_jac_wrong_format(self): This tests the error when using a sparse jacobian of the wrong format """ f = lambda t, y: [y] - jac = lambda t, y: sp.spdiags([1], 0, 1, 1, format = 'csr') + jac = lambda t, y: sps.spdiags([1], 0, 1, 1, format = 'csr') y0 = np.array([1.]) prob = Explicit_Problem(f, y0) prob.jac = jac @@ -865,7 +865,7 @@ def test_solver_sparse_jac_nnz_too_small(self): """ n = 5 f = lambda t, y: y - jac = lambda t, y: sp.eye(n, n, dtype = np.double, format = 'csc') + jac = lambda t, y: sps.eye(n, n, dtype = np.double, format = 'csc') y0 = np.array([1.]*n) prob = Explicit_Problem(f, y0) prob.jac = jac @@ -886,7 +886,7 @@ def test_solver_sparse_jac_nnz_zero(self): """ n = 5 f = lambda t, y: [0.]*n - jac = lambda t, y: sp.csc_matrix((n, n), dtype = np.double) + jac = lambda t, y: sps.csc_matrix((n, n), dtype = np.double) y0 = np.array([1.]*n) prob = Explicit_Problem(f, y0) prob.jac = jac @@ -904,7 +904,7 @@ def test_sparse_solver_no_nnz(self): This tests the error when trying to simulate using the sparse linear solver, without specifying the number of non-zero elements """ f = lambda t, y: [y] - jac = lambda t, y: sp.spdiags([1], 0, 1, 1, format = 'csc') + jac = lambda t, y: sps.spdiags([1], 0, 1, 1, format = 'csc') y0 = np.array([1.]) prob = Explicit_Problem(f, y0) prob.jac = jac @@ -923,7 +923,7 @@ def test_sparse_solver_invalid_nnz_type(self): This tests the error when trying to simulate using the sparse linear solver with invalid inputs for nnz; wrong type. """ f = lambda t, y: [y] - jac = lambda t, y: sp.spdiags([1], 0, 1, 1, format = 'csc') + jac = lambda t, y: sps.spdiags([1], 0, 1, 1, format = 'csc') y0 = np.array([1.]) for nnz in [None, "test"]: @@ -945,7 +945,7 @@ def test_sparse_solver_invalid_nnz_negative(self): This tests the error when trying to simulate using the sparse linear solver with invalid inputs for nnz; negative. """ f = lambda t, y: [y] - jac = lambda t, y: sp.spdiags([1], 0, 1, 1, format = 'csc') + jac = lambda t, y: sps.spdiags([1], 0, 1, 1, format = 'csc') y0 = np.array([1.]) for nnz in [-2, -10]: @@ -967,7 +967,7 @@ def test_sparse_solver_invalid_nnz_too_large(self): This tests the error when trying to simulate using the sparse linear solver with invalid inputs for nnz; too_large. """ f = lambda t, y: [y] - jac = lambda t, y: sp.spdiags([1], 0, 1, 1, format = 'csc') + jac = lambda t, y: sps.spdiags([1], 0, 1, 1, format = 'csc') y0 = np.array([1.]) for nnz in [5, 100]: @@ -988,14 +988,14 @@ def test_sparse_solver_jacobian(self): ## Take trivial problem with somewhat arbitrary jacobians ## Test that functions for internal processing of jacobian do not produces segfaults jacobians = [ - (lambda t, y: sp.csc_matrix(np.array([[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]])), 9), - (lambda t, y: sp.csc_matrix(np.array([[0., 1., 1.], [1., 0., 1.], [1., 1., 0.]])), 6), - (lambda t, y: sp.csc_matrix(np.array([[0., 1., 1.], [1., 1., 1.], [1., 1., 1.]])), 8), - (lambda t, y: sp.csc_matrix(np.array([[0., 0., 0.], [0., 1., 0.], [0., 0., 0.]])), 1), - (lambda t, y: sp.csc_matrix(np.array([[0., 0., 0.], [1., 0., 0.], [0., 0., 0.]])), 1), - (lambda t, y: sp.csc_matrix(np.array([[0., 0., 0.], [0., 0., 0.], [0., 1., 0.]])), 1), - (lambda t, y: sp.csc_matrix(np.array([[0., 0., 1.], [0., 0., 0.], [0., 0., 0.]])), 1), - (lambda t, y: sp.csc_matrix(np.array([[1., 0., 0.], [0., 0., 0.], [0., 0., 0.]])), 1), + (lambda t, y: sps.csc_matrix(np.array([[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]])), 9), + (lambda t, y: sps.csc_matrix(np.array([[0., 1., 1.], [1., 0., 1.], [1., 1., 0.]])), 6), + (lambda t, y: sps.csc_matrix(np.array([[0., 1., 1.], [1., 1., 1.], [1., 1., 1.]])), 8), + (lambda t, y: sps.csc_matrix(np.array([[0., 0., 0.], [0., 1., 0.], [0., 0., 0.]])), 1), + (lambda t, y: sps.csc_matrix(np.array([[0., 0., 0.], [1., 0., 0.], [0., 0., 0.]])), 1), + (lambda t, y: sps.csc_matrix(np.array([[0., 0., 0.], [0., 0., 0.], [0., 1., 0.]])), 1), + (lambda t, y: sps.csc_matrix(np.array([[0., 0., 1.], [0., 0., 0.], [0., 0., 0.]])), 1), + (lambda t, y: sps.csc_matrix(np.array([[1., 0., 0.], [0., 0., 0.], [0., 0., 0.]])), 1), ] for i, (jac, nnz) in enumerate(jacobians): diff --git a/tests/solvers/test_rosenbrock.py b/tests/solvers/test_rosenbrock.py index 04cdc1b9..f5a157ab 100644 --- a/tests/solvers/test_rosenbrock.py +++ b/tests/solvers/test_rosenbrock.py @@ -21,7 +21,7 @@ from assimulo.problem import Explicit_Problem from assimulo.exception import TimeLimitExceeded import numpy as np -import scipy.sparse as sp +import scipy.sparse as sps float_regex = "[\s]*[\d]*.[\d]*((e|E)(\+|\-)\d\d|)" @@ -53,7 +53,7 @@ def jac_sparse(t,y): J[1,0]=my*(-2.*y[0]*y[1]-1.) J[1,1]=my*(1.-y[0]**2) - return sp.csc_matrix(J) + return sps.csc_matrix(J) y0 = [2.0,-0.6] #Initial conditions diff --git a/tests/solvers/test_sundials.py b/tests/solvers/test_sundials.py index fe7d29cc..3f477dfa 100644 --- a/tests/solvers/test_sundials.py +++ b/tests/solvers/test_sundials.py @@ -22,7 +22,7 @@ from assimulo.problem import Implicit_Problem from assimulo.exception import AssimuloException, TimeLimitExceeded, TerminateSimulation import numpy as np -import scipy.sparse as sp +import scipy.sparse as sps class Extended_Problem(Explicit_Problem): @@ -496,7 +496,7 @@ def test_usejac_csc_matrix(self): This tests the functionality of the property usejac. """ f = lambda t,x: np.array([x[1], -9.82]) #Defines the rhs - jac = lambda t,x: sp.csc_matrix(np.array([[0.,1.],[0.,0.]])) #Defines the jacobian + jac = lambda t,x: sps.csc_matrix(np.array([[0.,1.],[0.,0.]])) #Defines the jacobian exp_mod = Explicit_Problem(f, [1.0,0.0]) exp_mod.jac = jac