Skip to content

Commit

Permalink
Upgrade to Python 3.11, Cython3 (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMeisrimelModelon authored Jan 24, 2024
1 parent 7f88eb0 commit 31c5d5e
Show file tree
Hide file tree
Showing 78 changed files with 382 additions and 404 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ jobs:
matrix:
sundials_version: [2.7.0, 3.2.0]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11.x'
- name: Setup Python
run: |
python3 -m pip install Cython numpy scipy matplotlib nose-py3
- name: Install system
run: |
sudo apt-get -y install python3-scipy python3-setuptools python3-nose cython3
sudo apt-get -y install cmake liblapack-dev libsuitesparse-dev libhypre-dev
sudo cp -v /usr/lib/x86_64-linux-gnu/libblas.so /usr/lib/x86_64-linux-gnu/libblas_OPENMP.so
- name: Install superlu
Expand All @@ -38,5 +43,4 @@ jobs:
- name: Build
run: python3 setup.py install --user --sundials-home=/usr --blas-home=/usr/lib/x86_64-linux-gnu/ --lapack-home=/usr/lib/x86_64-linux-gnu/ --superlu-home=/usr --extra-fortran-compile-flags="-fallow-argument-mismatch"
- name: Test
run: nosetests3 tests

run: python3 -m nose --verbose tests/* tests/solvers/*
4 changes: 3 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
--- CHANGELOG ---
--- Assimulo-3.4.4 ---
--- Assimulo-3.5.0 ---
* Changed "numpy.float" to equivalent "numpy.float64" due to DeprecationWarnings in numpy >= 1.20.
* Improved examples with sparse jacobians by omitting the zeros in the jacobians.
* Upgraded to Cython >= 3.
* Removed deprecated build option "sundials_with_superlu", which is checked automatically.

--- Assimulo-3.4.3 ---
* Improved compliance with newer scipy version by instead using corresponding numpy calls when more suitable.
Expand Down
4 changes: 2 additions & 2 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ INSTALL
=======

*REQUIREMENTS
- Python-2.7/3.* (with headers)
- Python-3 (with headers)
- Numpy, Scipy, Pylab
- Sundials-2.5/2.6/3.1/4.1
- Cython >= 0.18
- Cython >= 3
- C-compiler
- Fortran-compiler
- BLAS
Expand Down
18 changes: 18 additions & 0 deletions doc/sphinx/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
Changelog
==========

--- Assimulo-3.5.0 ---
* Changed "numpy.float" to equivalent "numpy.float64" due to DeprecationWarnings in numpy >= 1.20.
* Improved examples with sparse jacobians by omitting the zeros in the jacobians.
* Upgraded to Cython >= 3.
* Removed deprecated build option "sundials_with_superlu", which is checked automatically.

--- Assimulo-3.4.3 ---
* Improved compliance with newer scipy version by instead using corresponding numpy calls when more suitable.

--- Assimulo-3.4.2 ---
* Updated an import statement in one of the examples to resolve compliance issues with scipy 1.10.1.

--- Assimulo-3.4.1 ---
* Restored functionality of CVode with 'external_event_detection' = True, which broke with 3.4.0.
* CVode now allows rtol = 0.
* Added support for CVode (without sensitivities) with non-negative relative tolerance vector.
Requires a SUNDIALS installation supporting this, see README.

--- Assimulo-3.4.0 ---
* Removed Radau5ODE Fortran implementation.
This change should be seamless since the C implementation is numerically equivalent.
Expand Down
8 changes: 4 additions & 4 deletions doc/sphinx/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ Installation

Dependencies:

- `Python-2.7 / 3.* <http://www.python.org/>`_
- `Numpy <http://www.scipy.org/Download/>`_ (>1.6.1 for the solver DASP3)
- `Python-3 <http://www.python.org/>`_
- `Numpy <http://www.scipy.org/Download/>`_
- `Scipy <http://www.scipy.org/Download/>`_
- `Pylab <http://matplotlib.sourceforge.net/>`_

Additional dependencies for compiling from source:

- `Python-2.7 / 3.* <http://www.python.org/>`_ with headers (python-dev package for Ubuntu)
- `Python-3 <http://www.python.org/>`_ with headers (python-dev package for Ubuntu)
- `Sundials-2.6/2.7/3.1/4.1 <http://computation.llnl.gov/casc/sundials/main.html>`_ (for 64bits machines, install Sundials using -fPIC)
- `Cython 0.18 <http://www.cython.org/>`_
- `Cython 3.0.7 <http://www.cython.org/>`_
- C compiler
- Fortran compiler
- BLAS (only needed for the solver GLIMDA)
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinx/source/markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def mark_solvers():
elif solver[1] == "DAE_OVER":
file.write(' mod = '+problem_name+'(res, y0, yd0, t0)\n\n')
else:
print "Unknown solver type"
print("Unknown solver type")
file.write('.. note::\n\n')
file.write(' For complex problems, it is recommended to check the available :doc:`examples <examples>` and the documentation in the problem class, :class:`'+problem_name+ ' <assimulo.problem.'+problem_name+'>`. It is also recommended to define your problem as a subclass of :class:`'+problem_name+ ' <assimulo.problem.'+problem_name+'>`.\n\n')
file.write('.. warning::\n\n')
Expand Down
5 changes: 2 additions & 3 deletions examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@
"mech_system_pendulum", "euler_vanderpol", "cvode_with_parameters_modified",
"cvode_basic_backward","ida_basic_backward","dasp3_basic", "cvode_with_preconditioning",
"kinsol_basic","kinsol_with_jac", "radau5dae_time_events", "kinsol_ors", "lsodar_bouncing_ball",
"cvode_with_parameters_fcn", "ida_with_user_defined_handle_result", "cvode_with_jac_sparse"]


"cvode_with_parameters_fcn", "ida_with_user_defined_handle_result", "cvode_with_jac_sparse",
"radar_basic", "cvode_stability"]
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
3 changes: 1 addition & 2 deletions 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 All @@ -95,4 +95,3 @@ def f(t,y):

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

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()

Loading

0 comments on commit 31c5d5e

Please sign in to comment.