odespy icon indicating copy to clipboard operation
odespy copied to clipboard

Python 3.6 compatibility.

Open phn opened this issue 8 years ago • 2 comments

Hello,

I have made some changes to the code to make it run under Python 3.6. The code now runs under 2.7, 3.5 and 3.6.

Please see the file CHANGES_FOR_PY36.md for a list of changes.

I have setup up Tox so that it is easy to run tests under different versions of Python (see tox.ini).

The tests succeed for all but the StaggeredMidpoint algorithm. This failures is present in all versions of Python. So it seems like there is a bug in the algorithm. If you could let me know a fix I will incorporate it into this pull request.

Testing RungeKutta4 ...ok Testing StaggeredMidpoint ____________________________________________ test_complex ____________________________________________

def test_complex():
  _run_test_problems(Complex)

odespy/tests/test_basics.py:310:


odespy/tests/test_basics.py:258: in _run_test_problems u, t = solver.solve(problem['time_points']) odespy/solvers.py:1043: in solve self.u[n+1] = self.advance() # new value


self = <[UnboundLocalError("local variable 'f_name' referenced before assignment") raised in repr()] StaggeredMidpoint object at 0x7f1be05e6978>

def advance(self):
    """
        u[0], u[2], etc. are velocities at t=(i+1/2)*dt.
        u[1], u[3], etc. are positions at t=i*dt.
        """
    u, f, n, t = self.u, self.f, self.n, self.t
    dt = t[n+1] - t[n]
    u_new = u[n].copy()  # just need to allocate
    f_n = f(u[n], t[n])
    # March forward velocities
    if n == 0:
        # First step: use special formula for updating velocities
      for i in range(0, len(u[n]), 2):

E TypeError: object of type 'numpy.complex128' has no len()

odespy/solvers.py:1922: TypeError ---------------------------------------- Captured stdout call ---------------------------------------- Scalar ODE with complex value u' = 1./(t - 1 + 1j) Testing AdamsBashMoulton2 ...ok

Regards, Prasanth

phn avatar Apr 09 '17 06:04 phn

how do I get your files to work with the latest jupyter notebook? I am unable to use python 2.7 for some reason

Alienater avatar Apr 26 '17 03:04 Alienater

@Alienater

Sorry for the late reply. Can you be more specific about the errors you get? I am able to run tests in Python 2.7 and 3.6.

phn avatar May 28 '17 12:05 phn