Skip to content
Snippets Groups Projects
Commit 173a8615 authored by Joseph Weston's avatar Joseph Weston
Browse files

Merge branch 'issue_203' into 'stable'

Fix compatibility issues with Sympy 1.2.

Closes #203.

See merge request kwant/kwant!228
parents 367d4603 da8dc832
Branches
No related tags found
No related merge requests found
......@@ -190,6 +190,15 @@ def sympify(expr, locals=None):
converter[list] = stored_value
else:
del converter[list]
# We assume that all present functions, like "sin", "cos", will be
# provided by user during the final evaluation through "params".
# Therefore we make sure they are define as AppliedUndef, not built-in
# sympy types.
subs = {r: sympy.Symbol(str(r.func))(*r.args)
for r in hamiltonian.atoms(sympy.Function)}
hamiltonian = hamiltonian.subs(subs)
return hamiltonian
......
......@@ -457,6 +457,11 @@ def _discretize_expression(expression, coords):
class _NumericPrinter(LambdaPrinter):
def __init__(self):
LambdaPrinter.__init__(self)
self.known_functions = {}
self.known_constants = {'pi': 'pi', 'Pi': 'pi'}
def _print_ImaginaryUnit(self, expr):
# prevent sympy from printing 'I' for imaginary unit
return "1j"
......
......@@ -97,9 +97,9 @@ res_mat = sympy.Matrix([[x**3*A + x**2*A + x**2*B, x**3*A + x**2*A + x**2*B + x*
def test_make_commutative():
assert make_commutative(expr1, x) == make_commutative(expr1, non_x)
assert make_commutative(expr1, x) == x**3*A + x**2*A + x**2*B
assert make_commutative(matr, x) == res_mat
assert make_commutative(expr1, x).expand() == (make_commutative(expr1, non_x)).expand()
assert make_commutative(expr1, x).expand() == (x**3*A + x**2*A + x**2*B).expand()
assert make_commutative(matr, x).expand() == (res_mat).expand()
expr2 = non_x*A*non_x + x**2 * A*2 * x + B*non_x/2 + non_x*B/2 + x + A + non_x + x/A
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment