Skip to content

Commit

Permalink
Fixing DeprecationWarnings + various typos; fixed Radar solver statis…
Browse files Browse the repository at this point in the history
…tics
  • Loading branch information
PeterMeisrimelModelon committed Jan 12, 2024
1 parent e1891c8 commit b73d913
Show file tree
Hide file tree
Showing 38 changed files with 52 additions and 86 deletions.
2 changes: 1 addition & 1 deletion examples/cvode_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def f(t,y):
P.show()

#Basic test
nose.tools.assert_almost_equal(float(y2[-1]), 0.00347746, 5)
nose.tools.assert_almost_equal(y2[-1][0], 0.00347746, 5)
nose.tools.assert_almost_equal(exp_sim.get_last_step(), 0.0222169642893, 3)

return exp_mod, exp_sim
Expand Down
2 changes: 1 addition & 1 deletion examples/cvode_basic_backward.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def f(t,y):
P.show()

#Basic test
nose.tools.assert_almost_equal(float(y[-1]), 4.00000000, 3)
nose.tools.assert_almost_equal(y[-1][0], 4.00000000, 3)

return exp_mod, exp_sim

Expand Down
2 changes: 1 addition & 1 deletion examples/cvode_stability.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def f(t,y):
exp_sim = CVode(exp_mod) #Create a CVode solver

#Sets the parameters
exp_sim.stablimdet = True
exp_sim.stablimit = True
exp_sim.report_continuously = True

#Simulate
Expand Down
2 changes: 1 addition & 1 deletion examples/cvode_with_disc.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def handle_event(self, solver, event_info):

event_info = self.check_eIter(b_mode, a_mode)

if not True in event_info: #Breaks the iteration loop
if True not in event_info: #Breaks the iteration loop
break

#Helper function for handle_event
Expand Down
2 changes: 1 addition & 1 deletion examples/cvode_with_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def f(t, y, p):
exp_sim.discr = 'BDF'
exp_sim.rtol = 1.e-4
exp_sim.atol = N.array([1.0e-8, 1.0e-14, 1.0e-6])
exp_sim.sensmethod = 'SIMULTANEOUS' #Defines the sensitvity method used
exp_sim.sensmethod = 'SIMULTANEOUS' #Defines the sensitivity method used
exp_sim.suppress_sens = False #Dont suppress the sensitivity variables in the error test.
exp_sim.report_continuously = True

Expand Down
2 changes: 1 addition & 1 deletion examples/cvode_with_parameters_fcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def fsens(t, y, s, p):
exp_sim.discr = 'BDF'
exp_sim.rtol = 1.e-4
exp_sim.atol = N.array([1.0e-8, 1.0e-14, 1.0e-6])
exp_sim.sensmethod = 'SIMULTANEOUS' #Defines the sensitvity method used
exp_sim.sensmethod = 'SIMULTANEOUS' #Defines the sensitivity method used
exp_sim.suppress_sens = False #Dont suppress the sensitivity variables in the error test.
exp_sim.report_continuously = True

Expand Down
3 changes: 1 addition & 2 deletions examples/cvode_with_parameters_modified.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def f(t, y, p):
exp_sim.discr = 'BDF'
exp_sim.rtol = 1.e-4
exp_sim.atol = N.array([1.0e-8, 1.0e-14, 1.0e-6])
exp_sim.sensmethod = 'SIMULTANEOUS' #Defines the sensitvity method used
exp_sim.sensmethod = 'SIMULTANEOUS' #Defines the sensitivity method used
exp_sim.suppress_sens = False #Dont suppress the sensitivity variables in the error test.
exp_sim.report_continuously = True

Expand All @@ -95,4 +95,3 @@ def f(t, y, p):

if __name__=='__main__':
mod,sim = run_example()

4 changes: 2 additions & 2 deletions examples/cvode_with_preconditioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def prec_setup(t, y, fy, jok, gamma, data):
A = np.array([[2.0, 1.0], [3.0, 2.0]])

#If jok is false the jacobian data needs to be recomputed
if jok == False:
if jok is False:

#Extract the diagonal of the jacobian to form a Jacobi preconditioner
a0 = A[0, 0] * t * np.cos(y[0])
Expand All @@ -64,7 +64,7 @@ def prec_setup(t, y, fy, jok, gamma, data):
return [True, a]

#If jok is true the existing jacobian data can be reused
if jok == True:
if jok is True:

#Return false (jacobian data was reused) and the old data
return [False, data]
Expand Down
2 changes: 1 addition & 1 deletion examples/dopri5_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def f(t,y):
P.show()

#Basic test
nose.tools.assert_almost_equal(float(y[-1]),0.02695199,5)
nose.tools.assert_almost_equal(y[-1][0],0.02695199,5)

return exp_mod, exp_sim

Expand Down
5 changes: 1 addition & 4 deletions examples/dopri5_with_disc.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def handle_event(self, solver, event_info):

event_info = self.check_eIter(b_mode, a_mode)

if not True in event_info: #Breaks the iteration loop
if True not in event_info: #Breaks the iteration loop
break

#Helper function for handle_event
Expand Down Expand Up @@ -163,6 +163,3 @@ def run_example(with_plots=True):

if __name__=="__main__":
mod,sim = run_example()



2 changes: 1 addition & 1 deletion examples/euler_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def f(t,y):
P.show()

#Basic test
nose.tools.assert_almost_equal(float(y2[-1]), 0.02628193)
nose.tools.assert_almost_equal(y2[-1][0], 0.02628193)

return exp_mod, exp_sim

Expand Down
1 change: 0 additions & 1 deletion examples/euler_vanderpol.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,3 @@ def jac(t,y):

if __name__=='__main__':
mod,sim = run_example()

4 changes: 1 addition & 3 deletions examples/euler_with_disc.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def handle_event(self, solver, event_info):

event_info = self.check_eIter(b_mode, a_mode)

if not True in event_info: #Breaks the iteration loop
if True not in event_info: #Breaks the iteration loop
break

#Helper function for handle_event
Expand Down Expand Up @@ -121,8 +121,6 @@ def init_mode(self, solver):
solver.y[1] = (-1.0 if solver.sw[1] else 3.0)
solver.y[2] = (0.0 if solver.sw[2] else 2.0)



def run_example(with_plots=True):
r"""
Example of the use of Euler's method for a differential equation
Expand Down
2 changes: 1 addition & 1 deletion examples/glimda_vanderpol.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import numpy as N
import nose
from assimulo.solvers import GLIMDA,IDA
from assimulo.solvers import GLIMDA
from assimulo.problem import Implicit_Problem

def run_example(with_plots=True):
Expand Down
2 changes: 1 addition & 1 deletion examples/ida_basic_backward.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def f(t,y,yd):
P.show()

#Basic test
nose.tools.assert_almost_equal(float(y[-1]), 4.00000000, 3)
nose.tools.assert_almost_equal(y[-1][0], 4.00000000, 3)

return imp_mod, imp_sim

Expand Down
7 changes: 1 addition & 6 deletions examples/ida_with_disc.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def handle_event(self, solver, event_info):

event_info = self.check_eIter(b_mode, a_mode)

if not True in event_info: #Breaks the iteration loop
if True not in event_info: #Breaks the iteration loop
break

#Helper function for handle_event
Expand Down Expand Up @@ -125,8 +125,6 @@ def init_mode(self, solver):
#see SUNDIALS IDA documentation
#on the option 'IDA_YA_YDP_INIT'



def run_example(with_plots=True):
r"""
Example of the use of IDA for an implicit differential equation
Expand Down Expand Up @@ -168,6 +166,3 @@ def run_example(with_plots=True):

if __name__=="__main__":
mod,sim = run_example()



2 changes: 1 addition & 1 deletion examples/ida_with_initial_sensitivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def f(t, y, yd,p):
imp_sim.atol = 1e-6
imp_sim.pbar = [1,1,1] #pbar is used to estimate the tolerances for the parameters
imp_sim.report_continuously = True #Need to be able to store the result using the interpolate methods
imp_sim.sensmethod = 'SIMULTANEOUS' #Defines the sensitvity method used
imp_sim.sensmethod = 'SIMULTANEOUS' #Defines the sensitivity method used
imp_sim.suppress_sens = False #Dont suppress the sensitivity variables in the error test.

#Simulate
Expand Down
1 change: 0 additions & 1 deletion examples/ida_with_jac.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,3 @@ def jac(c,t,y,yd):

if __name__=='__main__':
mod,sim = run_example()

1 change: 0 additions & 1 deletion examples/ida_with_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,3 @@ def f(t, y, yd, p):

if __name__=='__main__':
mod,sim = run_example()

2 changes: 0 additions & 2 deletions examples/ida_with_user_defined_handle_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,5 @@ def handle_result(solver, t ,y, yd):

return imp_mod, imp_sim


if __name__=='__main__':
mod,sim = run_example()

2 changes: 0 additions & 2 deletions examples/kinsol_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# 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 numpy as N
import nose
from assimulo.solvers import KINSOL
from assimulo.problem import Algebraic_Problem
Expand Down Expand Up @@ -53,4 +52,3 @@ def res(y):

if __name__=='__main__':
mod, solv = run_example()

8 changes: 3 additions & 5 deletions examples/kinsol_ors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import numpy as N
import scipy as S
import scipy.linalg as LIN
import scipy.io as IO
import scipy.sparse as SPARSE
Expand Down Expand Up @@ -79,7 +78,7 @@ def prec_setup(u,f, uscale, fscale):
def prec_solve(r):
return solvePrec(r)

y0 = S.rand(A.shape[0])
y0 = N.random.rand(A.shape[0])

#Define an Assimulo problem
alg_mod = Algebraic_Problem(res, y0=y0, jac=jac, jacv=jacv, name = 'ORS Example')
Expand All @@ -101,10 +100,10 @@ def setup_param(solver):
setup_param(alg_solver)
setup_param(alg_solver_prec)

#Solve orignal system
#Solve original system
y = alg_solver.solve()

#Solve Preconditionined system
#Solve Preconditioned system
y_prec = alg_solver_prec.solve()

print("Error , in y: ", LIN.norm(y-N.ones(len(y))))
Expand Down Expand Up @@ -137,4 +136,3 @@ def setup_param(solver):

if __name__=='__main__':
mod, solv = run_example()

1 change: 0 additions & 1 deletion examples/kinsol_with_jac.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,3 @@ def jac(y):

if __name__=='__main__':
mod, solv = run_example()

7 changes: 1 addition & 6 deletions examples/lsodar_bouncing_ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
# 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 numpy as N
import nose
import numpy as N
from assimulo.solvers import LSODAR
from assimulo.problem import Explicit_Problem
import sys
import os

"""
The bouncing ball example for LSODAR
Expand Down Expand Up @@ -155,6 +153,3 @@ def run_example(with_plots=True):

if __name__=="__main__":
mod,sim = run_example()



2 changes: 1 addition & 1 deletion examples/lsodar_vanderpol.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def f(t,y):
exp_mod = Explicit_Problem(f,y0, name = "LSODAR: Van der Pol's equation")

#Define an explicit solver
exp_sim = LSODAR(exp_mod) #Create a Radau5 solver
exp_sim = LSODAR(exp_mod) #Create a LSODAR solver

#Sets the parameters
exp_sim.atol = 1e-4 #Default 1e-6
Expand Down
2 changes: 1 addition & 1 deletion examples/lsodar_with_disc.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def handle_event(self, solver, event_info):

event_info = self.check_eIter(b_mode, a_mode)

if not True in event_info: #Breaks the iteration loop
if True not in event_info: #Breaks the iteration loop
break

#Helper function for handle_event
Expand Down
2 changes: 0 additions & 2 deletions examples/mech_system_pendulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# 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 nose
import assimulo.problem as ap
import assimulo.special_systems as ass
import numpy as N
import nose
Expand Down
4 changes: 2 additions & 2 deletions examples/radau5ode_with_disc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#Extend Assimulos problem definition
class Extended_Problem(Explicit_Problem):

#Sets the initial conditons directly into the problem
#Sets the initial conditions directly into the problem
y0 = [0.0, -1.0, 0.0]
sw0 = [False,True,True]

Expand Down Expand Up @@ -84,7 +84,7 @@ def handle_event(self, solver, event_info):

event_info = self.check_eIter(b_mode, a_mode)

if not True in event_info: #Breaks the iteration loop
if True not in event_info: #Breaks the iteration loop
break

#Helper function for handle_event
Expand Down
7 changes: 2 additions & 5 deletions examples/radau5ode_with_disc_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#Extend Assimulos problem definition
class Extended_Problem(Explicit_Problem):

#Sets the initial conditons directly into the problem
#Sets the initial conditions directly into the problem
y0 = [0.0, -1.0, 0.0]
sw0 = [False,True,True]

Expand Down Expand Up @@ -90,7 +90,7 @@ def handle_event(self, solver, event_info):

event_info = self.check_eIter(b_mode, a_mode)

if not True in event_info: #Breaks the iteration loop
if True not in event_info: #Breaks the iteration loop
break

#Helper function for handle_event
Expand Down Expand Up @@ -127,8 +127,6 @@ def init_mode(self, solver):
solver.y[1] = (-1.0 if solver.sw[1] else 3.0)
solver.y[2] = (0.0 if solver.sw[2] else 2.0)



def run_example(with_plots=True):
#Create an instance of the problem
exp_mod = Extended_Problem() #Create the problem
Expand Down Expand Up @@ -161,4 +159,3 @@ def run_example(with_plots=True):

if __name__=="__main__":
mod,sim = run_example()

4 changes: 1 addition & 3 deletions examples/radau5ode_with_jac_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from assimulo.solvers import Radau5ODE
from assimulo.problem import Explicit_Problem


def run_example(with_plots=True):
r"""
Example for demonstrating the use of a user supplied Jacobian (sparse).
Expand Down Expand Up @@ -90,10 +89,9 @@ def jac(t,y):
P.show()

#Basic tests
nose.tools.assert_almost_equal(y[-1][0],0.9851,3)
nose.tools.assert_almost_equal(y[-1][0], 0.9851, 3)

return exp_mod, exp_sim


if __name__=='__main__':
mod,sim = run_example()
1 change: 0 additions & 1 deletion examples/rodasode_vanderpol.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,3 @@ def jac(t,y):

if __name__=='__main__':
mod,sim = run_example()

2 changes: 1 addition & 1 deletion examples/rungekutta34_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def f(t,y):
t, y = exp_sim.simulate(5) #Simulate 5 seconds

#Basic test
nose.tools.assert_almost_equal(float(y[-1]),0.02695199,5)
nose.tools.assert_almost_equal(y[-1][0], 0.02695199, 5)

#Plot
if with_plots:
Expand Down
Loading

0 comments on commit b73d913

Please sign in to comment.