Skip to content

Commit

Permalink
Resolving DeprecationWarnings in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMeisrimelModelon committed Feb 12, 2024
1 parent 4db03d4 commit bfc9813
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 57 deletions.
2 changes: 1 addition & 1 deletion examples/glimda_vanderpol.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def f(t,y,yd):

#Basic test
x1 = y[:,0]
assert float(x1[-1]) == pytest.approx(1.706168035, abs = 1e-3)
assert x1[-1][0] == pytest.approx(1.706168035, abs = 1e-3)

return imp_mod, imp_sim

Expand Down
6 changes: 3 additions & 3 deletions src/ode.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ cdef class ODE:
"sensitivity_calculations":False,
"interpolated_sensitivity_output":False,
"rtol_as_vector":False}
self.problem_info = {"dim":0,"dimRoot":0,"dimSens":0,"state_events":False,"step_events":False,"time_events":False
,"jac_fcn":False, "sens_fcn":False, "jacv_fcn":False,"switches":False,"type":0,"jaclag_fcn":False,'prec_solve':False,'prec_setup':False
,"jac_fcn_nnz": -1}
self.problem_info = {"dim":0,"dimRoot":0,"dimSens":0,"state_events":False,"step_events":False,"time_events":False,
"jac_fcn":False, "sens_fcn":False, "jacv_fcn":False,"switches":False,"type":0,"jaclag_fcn":False,
'prec_solve':False, 'prec_setup':False, "jac_fcn_nnz": -1}
#Type of the problem
#0 = Explicit
#1 = Implicit
Expand Down
74 changes: 37 additions & 37 deletions src/solvers/radau5.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,11 +642,11 @@ def _step(self, t, y):

def _collocation_pol(self, Z, col_poly, leny):

col_poly[2*leny:3*leny] = Z[:leny] / self.C[0,0]
col_poly[leny:2*leny] = ( Z[:leny] - Z[leny:2*leny] ) / (self.C[0,0]-self.C[1,0])
col_poly[:leny] = ( Z[leny:2*leny] -Z[2*leny:3*leny] ) / (self.C[1,0]-1.)
col_poly[2*leny:3*leny] = ( col_poly[leny:2*leny] - col_poly[2*leny:3*leny] ) / self.C[1,0]
col_poly[leny:2*leny] = ( col_poly[leny:2*leny] - col_poly[:leny] ) / (self.C[0,0]-1.)
col_poly[2*leny:3*leny] = Z[:leny] / self.C[0]
col_poly[leny:2*leny] = ( Z[:leny] - Z[leny:2*leny] ) / (self.C[0]-self.C[1])
col_poly[:leny] = ( Z[leny:2*leny] -Z[2*leny:3*leny] ) / (self.C[1]-1.)
col_poly[2*leny:3*leny] = ( col_poly[leny:2*leny] - col_poly[2*leny:3*leny] ) / self.C[1]
col_poly[leny:2*leny] = ( col_poly[leny:2*leny] - col_poly[:leny] ) / (self.C[0]-1.)
col_poly[2*leny:3*leny] = col_poly[leny:2*leny]-col_poly[2*leny:3*leny]

return col_poly
Expand All @@ -657,9 +657,9 @@ def _radau_F(self, Z, t, y):
Z2 = Z[self._leny:2*self._leny]
Z3 = Z[2*self._leny:3*self._leny]

self.f(self.Y1,t+self.C[0]*self.h, y+Z1)
self.f(self.Y2,t+self.C[1]*self.h, y+Z2)
self.f(self.Y3,t+self.C[2]*self.h, y+Z3)
self.f(self.Y1, t + self.C[0] * self.h, y + Z1)
self.f(self.Y2, t + self.C[1] * self.h, y + Z2)
self.f(self.Y3, t + self.C[2] * self.h, y + Z3)

self.statistics["nfcns"] += 3

Expand All @@ -678,9 +678,9 @@ def calc_start_values(self):
newtval = self._col_poly
leny = self._leny

Z[:leny] = cq[0,0]*(newtval[:leny]+(cq[0,0]-self.C[1,0]+1.)*(newtval[leny:2*leny]+(cq[0,0]-self.C[0,0]+1.)*newtval[2*leny:3*leny]))
Z[leny:2*leny] = cq[1,0]*(newtval[:leny]+(cq[1,0]-self.C[1,0]+1.)*(newtval[leny:2*leny]+(cq[1,0]-self.C[0,0]+1.)*newtval[2*leny:3*leny]))
Z[2*leny:3*leny]= cq[2,0]*(newtval[:leny]+(cq[2,0]-self.C[1,0]+1.)*(newtval[leny:2*leny]+(cq[2,0]-self.C[0,0]+1.)*newtval[2*leny:3*leny]))
Z[:leny] = cq[0]*(newtval[:leny]+(cq[0]-self.C[1]+1.)*(newtval[leny:2*leny]+(cq[0]-self.C[0]+1.)*newtval[2*leny:3*leny]))
Z[leny:2*leny] = cq[1]*(newtval[:leny]+(cq[1]-self.C[1]+1.)*(newtval[leny:2*leny]+(cq[1]-self.C[0]+1.)*newtval[2*leny:3*leny]))
Z[2*leny:3*leny]= cq[2]*(newtval[:leny]+(cq[2]-self.C[1]+1.)*(newtval[leny:2*leny]+(cq[2]-self.C[0]+1.)*newtval[2*leny:3*leny]))

W = np.dot(self.T2,Z)

Expand Down Expand Up @@ -872,7 +872,7 @@ def interpolate(self, t, k=0):
s = (t-self._newt)/self._oldh
Z = self._col_poly

yout = self._yc+s*(Z[:leny]+(s-self.C[1,0]+1.)*(Z[leny:2*leny]+(s-self.C[0,0]+1.)*Z[2*leny:3*leny]))
yout = self._yc+s*(Z[:leny]+(s-self.C[1]+1.)*(Z[leny:2*leny]+(s-self.C[0]+1.)*Z[2*leny:3*leny]))
return yout

def _load_parameters(self):
Expand All @@ -889,15 +889,15 @@ def _load_parameters(self):
A[2,1] = (16.0+np.sqrt(6.))/36.0
A[2,2] = (1.0/9.0)

C = np.zeros([3,1])
C[0,0]=(4.0-np.sqrt(6.0))/10.0
C[1,0]=(4.0+np.sqrt(6.0))/10.0
C[2,0]=1.0
C = np.zeros([3])
C[0]=(4.0-np.sqrt(6.0))/10.0
C[1]=(4.0+np.sqrt(6.0))/10.0
C[2]=1.0

B = np.zeros([1,3])
B[0,0]=(16.0-np.sqrt(6.0))/36.0
B[0,1]=(16.0+np.sqrt(6.0))/36.0
B[0,2]=1.0/9.0
B = np.zeros([3])
B[0]=(16.0-np.sqrt(6.0))/36.0
B[1]=(16.0+np.sqrt(6.0))/36.0
B[2]=1.0/9.0

E = np.zeros(3)
E[0] = -13.0-7.*np.sqrt(6.)
Expand Down Expand Up @@ -1641,7 +1641,7 @@ def interpolate(self, t, k=0):
s = (t-self._newt)/self._oldh
Z = self._col_poly

diff = s*(Z[:leny]+(s-self.C[1,0]+1.)*(Z[leny:2*leny]+(s-self.C[0,0]+1.)*Z[2*leny:3*leny]))
diff = s*(Z[:leny]+(s-self.C[1]+1.)*(Z[leny:2*leny]+(s-self.C[0]+1.)*Z[2*leny:3*leny]))

yout = self._yc + diff[:self._leny]
ydout = self._ydc+ diff[self._leny:]
Expand Down Expand Up @@ -1715,11 +1715,11 @@ def adjust_stepsize(self, err, predict=False):

def _collocation_pol(self, Z, col_poly, leny):

col_poly[2*leny:3*leny] = Z[:leny] / self.C[0,0]
col_poly[leny:2*leny] = ( Z[:leny] - Z[leny:2*leny] ) / (self.C[0,0]-self.C[1,0])
col_poly[:leny] = ( Z[leny:2*leny] -Z[2*leny:3*leny] ) / (self.C[1,0]-1.)
col_poly[2*leny:3*leny] = ( col_poly[leny:2*leny] - col_poly[2*leny:3*leny] ) / self.C[1,0]
col_poly[leny:2*leny] = ( col_poly[leny:2*leny] - col_poly[:leny] ) / (self.C[0,0]-1.)
col_poly[2*leny:3*leny] = Z[:leny] / self.C[0]
col_poly[leny:2*leny] = ( Z[:leny] - Z[leny:2*leny] ) / (self.C[0]-self.C[1])
col_poly[:leny] = ( Z[leny:2*leny] -Z[2*leny:3*leny] ) / (self.C[1]-1.)
col_poly[2*leny:3*leny] = ( col_poly[leny:2*leny] - col_poly[2*leny:3*leny] ) / self.C[1]
col_poly[leny:2*leny] = ( col_poly[leny:2*leny] - col_poly[:leny] ) / (self.C[0]-1.)
col_poly[2*leny:3*leny] = col_poly[leny:2*leny]-col_poly[2*leny:3*leny]

return col_poly
Expand All @@ -1737,9 +1737,9 @@ def calc_start_values(self):
newtval = self._col_poly
leny = self._2leny

Z[:leny] = cq[0,0]*(newtval[:leny]+(cq[0,0]-self.C[1,0]+1.)*(newtval[leny:2*leny]+(cq[0,0]-self.C[0,0]+1.)*newtval[2*leny:3*leny]))
Z[leny:2*leny] = cq[1,0]*(newtval[:leny]+(cq[1,0]-self.C[1,0]+1.)*(newtval[leny:2*leny]+(cq[1,0]-self.C[0,0]+1.)*newtval[2*leny:3*leny]))
Z[2*leny:3*leny]= cq[2,0]*(newtval[:leny]+(cq[2,0]-self.C[1,0]+1.)*(newtval[leny:2*leny]+(cq[2,0]-self.C[0,0]+1.)*newtval[2*leny:3*leny]))
Z[:leny] = cq[0]*(newtval[:leny]+(cq[0]-self.C[1]+1.)*(newtval[leny:2*leny]+(cq[0]-self.C[0]+1.)*newtval[2*leny:3*leny]))
Z[leny:2*leny] = cq[1]*(newtval[:leny]+(cq[1]-self.C[1]+1.)*(newtval[leny:2*leny]+(cq[1]-self.C[0]+1.)*newtval[2*leny:3*leny]))
Z[2*leny:3*leny]= cq[2]*(newtval[:leny]+(cq[2]-self.C[1]+1.)*(newtval[leny:2*leny]+(cq[2]-self.C[0]+1.)*newtval[2*leny:3*leny]))

W = np.dot(self.T2,Z)

Expand All @@ -1759,15 +1759,15 @@ def _load_parameters(self):
A[2,1] = (16.0+np.sqrt(6.))/36.0
A[2,2] = (1.0/9.0)

C = np.zeros([3,1])
C[0,0]=(4.0-np.sqrt(6.0))/10.0
C[1,0]=(4.0+np.sqrt(6.0))/10.0
C[2,0]=1.0
C = np.zeros([3])
C[0]=(4.0-np.sqrt(6.0))/10.0
C[1]=(4.0+np.sqrt(6.0))/10.0
C[2]=1.0

B = np.zeros([1,3])
B[0,0]=(16.0-np.sqrt(6.0))/36.0
B[0,1]=(16.0+np.sqrt(6.0))/36.0
B[0,2]=1.0/9.0
B = np.zeros([3])
B[0]=(16.0-np.sqrt(6.0))/36.0
B[1]=(16.0+np.sqrt(6.0))/36.0
B[2]=1.0/9.0

E = np.zeros(3)
E[0] = -13.0-7.*np.sqrt(6.)
Expand Down
8 changes: 4 additions & 4 deletions tests/solvers/test_euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def test_integrator(self):
values = self.simulator.simulate(1)

assert self.simulator.t_sol[-1] == pytest.approx(1.0)
assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0)
assert self.simulator.y_sol[-1][0] == pytest.approx(2.0)

def test_step(self):
"""
Expand All @@ -207,7 +207,7 @@ def test_step(self):
self.simulator.simulate(1)

assert self.simulator.t_sol[-1] == pytest.approx(1.0)
assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0)
assert self.simulator.y_sol[-1][0] == pytest.approx(2.0)

def test_exception(self):
"""
Expand Down Expand Up @@ -356,7 +356,7 @@ def test_integrator(self):
values = self.simulator.simulate(1)

assert self.simulator.t_sol[-1] == pytest.approx(1.0)
assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0)
assert self.simulator.y_sol[-1][0] == pytest.approx(2.0)

def test_step(self):
"""
Expand All @@ -368,7 +368,7 @@ def test_step(self):
self.simulator.simulate(1)

assert self.simulator.t_sol[-1] == pytest.approx(1.0)
assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0)
assert self.simulator.y_sol[-1][0] == pytest.approx(2.0)

def test_stiff_problem(self):
f = lambda t,y: -15.0*y
Expand Down
2 changes: 1 addition & 1 deletion tests/solvers/test_glimda.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_simulate_explicit(self):

t,y = simulator.simulate(1.0)

assert float(y[-1]) == pytest.approx(float(np.exp(-1.0)),4)
assert y[-1][0] == pytest.approx(np.exp(-1.0),4)

def test_maxord(self):
"""
Expand Down
5 changes: 3 additions & 2 deletions tests/solvers/test_radau5.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ def test_collocation_polynomial(self):
assert self.sim.statistics["nsteps"] < 300

#assert self.sim.y[-2][0] == pytest.approx(1.71505001, abs = 1e-4)
print
assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, abs = 1e-4)

self.sim.report_continuously = True
Expand Down Expand Up @@ -746,6 +745,7 @@ def test_nmax_steps(self):
with pytest.raises(Radau5Error, match = err_msg):
sim.simulate(1.)

@pytest.mark.filterwarnings("ignore::RuntimeWarning")
def test_step_size_too_small(self):
"""
This tests the error for too small step-sizes
Expand Down Expand Up @@ -1192,7 +1192,7 @@ def test_simulate_explicit(self):

t,y = simulator.simulate(1.0)

assert float(y[-1]) == pytest.approx(float(np.exp(-1.0)),4)
assert y[-1][0] == pytest.approx(np.exp(-1.0),4)

def test_time_event(self):
f = lambda t,y,yd: y-yd
Expand Down Expand Up @@ -1326,6 +1326,7 @@ def test_nmax_steps(self):
with pytest.raises(Radau5Error, match = err_msg):
sim.simulate(1.)

@pytest.mark.filterwarnings("ignore::RuntimeWarning")
def test_step_size_too_small(self):
"""
This tests the error for too small step-sizes
Expand Down
6 changes: 3 additions & 3 deletions tests/solvers/test_rungekutta.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_integrator(self):
values = self.simulator.simulate(1)

assert self.simulator.t_sol[-1] == pytest.approx(1.0)
assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0)
assert self.simulator.y_sol[-1][0] == pytest.approx(2.0)

def test_time_event(self):
f = lambda t,y: [1.0]
Expand Down Expand Up @@ -303,7 +303,7 @@ def test_integrate(self):
values = self.simulator.simulate(1)

assert self.simulator.t_sol[-1] == pytest.approx(1.0)
assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0)
assert self.simulator.y_sol[-1][0] == pytest.approx(2.0)

def test_step(self):
self.simulator.report_continuously = True
Expand All @@ -312,4 +312,4 @@ def test_step(self):
self.simulator.simulate(1)

assert self.simulator.t_sol[-1] == pytest.approx(1.0)
assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0)
assert self.simulator.y_sol[-1][0] == pytest.approx(2.0)
6 changes: 3 additions & 3 deletions tests/solvers/test_sundials.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def test_interpolate(self):
t100 = sim.t_sol
sim.reset()
sim.simulate(10.)
assert float(y100[-2]) == pytest.approx(float(sim.interpolate(9.9, 0)), abs = 1e-5)
assert y100[-2][0] == pytest.approx(sim.interpolate(9.9, 0)[0], abs = 1e-5)

def test_ncp_list(self):
f = lambda t,y:np.array(-y)
Expand All @@ -594,7 +594,7 @@ def test_ncp_list(self):

t, y = sim.simulate(7, ncp_list=np.arange(0, 7, 0.1)) #Simulate 5 seconds

assert float(y[-1]) == pytest.approx(0.00364832, abs = 1e-4)
assert y[-1][0] == pytest.approx(0.00364832, abs = 1e-4)

def test_handle_result(self):
"""
Expand Down Expand Up @@ -918,7 +918,7 @@ def test_simulate_explicit(self):

t,y = simulator.simulate(1.0)

assert float(y[-1]) == pytest.approx(float(np.exp(-1.0)),4)
assert y[-1][0] == pytest.approx(np.exp(-1.0),4)

def test_init(self):
"""
Expand Down
2 changes: 2 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import pytest
from assimulo.exception import AssimuloException
from assimulo.examples import *

Expand All @@ -37,6 +38,7 @@ def test_kinsol_basic(self):
def test_kinsol_with_jac(self):
kinsol_with_jac.run_example(with_plots=False)

@pytest.mark.filterwarnings("ignore::Warning") # SparseEfficiencyWarning
def test_kinsol_ors(self):
kinsol_ors.run_example(with_plots=False)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ def test_radau5dae_state_events(self):

t,y,yd = solver.simulate(2,33)

assert float(y[-1]) == pytest.approx(0.135, abs = 1e-3)
assert y[-1][0] == pytest.approx(0.135, abs = 1e-3)

def test_dopri5_state_events(self):
solver = Dopri5(self.eproblem)

t,y = solver.simulate(2,33)

assert float(y[-1]) == pytest.approx(0.135, abs = 1e-3)
assert y[-1][0] == pytest.approx(0.135, abs = 1e-3)

def test_rodasode_state_events(self):
solver = RodasODE(self.eproblem)

t,y = solver.simulate(2,33)

assert float(y[-1]) == pytest.approx(0.135, abs = 1e-3)
assert y[-1][0] == pytest.approx(0.135, abs = 1e-3)

0 comments on commit bfc9813

Please sign in to comment.