test_simple_derivations failed
Hello, I am encountering two failures when running the test. I have installed sympy
package, the errors persist.
Any ideas which part of my installation is not correct?
Below is the error summaries:
================================== FAILURES ===================================
_______________________ test_simple_derivations[False] ________________________
ValueError: Error from parse_expr with transformed code: 'k_x *A (x ,y )*k_x '
The above exception was the direct cause of the following exception:
commutative = False
@pytest.mark.parametrize('commutative', [True, False])
def test_simple_derivations(commutative):
kx, ky, kz = sympy.symbols('k_x k_y k_z', commutative=commutative)
test = {
kx**2 : {(0,): 2/ax**2, (1,): -1/ax**2},
kx**2 + 1 : {(0,): 1 + 2/ax**2, (1,): -1/ax**2},
kx**2 + 2 : {(0,): 2 + 2/ax**2, (1,): -1/ax**2},
kx**2 + 1.0 : {(0,): 1.0 + 2/ax**2, (1,): -1/ax**2},
kx**2 + 2.0 : {(0,): 2.0 + 2/ax**2, (1,): -1/ax**2},
kx**2 + ky**2 : {(0, 1): -1/ay**2, (0, 0): 2/ax**2 + 2/ay**2,
(1, 0): -1/ax**2},
kx**2 + ky**2 + kz**2 : {(1, 0, 0): -1/ax**2, (0, 0, 1): -1/az**2,
(0, 0, 0): 2/ax**2 + 2/ay**2 + 2/az**2,
(0, 1, 0): -1/ay**2},
ky**2 + kz**2 : {(0, 1): -1/az**2, (0, 0): 2/ay**2 + 2/az**2,
(1, 0): -1/ay**2},
kz**2 : {(0,): 2/az**2, (1,): -1/az**2},
}
non_commutative_test = {
kx * fA(x, y) * kx : {(1, ): -fA(ax/2 + x, y)/ax**2,
(0, ): fA(-ax/2 + x, y)/ax**2 + fA(ax/2 + x, y)/ax**2},
kx**2 + kz * fB(y) : {(1, 0): -1/ax**2, (0, 1): -I*fB(y)/(2*az),
(0, 0): 2/ax**2},
kx * fA(x) : {(0,): 0, (1,): -I*fA(ax + x)/(2*ax)},
ky * fA(x) : {(1,): -I*fA(x)/(2*ay), (0,): 0},
kx * fA(x) * B : {(0,): 0, (1,): -I*fA(ax + x)*B/(2*ax)},
5 * kx : {(0,): 0, (1,): -5*I/(2*ax)},
kx * (fA(x) + fB(x)) : {(0,): 0,
(1,): -I*fA(ax + x)/(2*ax) - I*fB(ax + x)/(2*ax)},
}
if not commutative:
test.update(non_commutative_test)
for inp, out in test.items():
got, _ = discretize_symbolic(inp)
assert got == out
for inp, out in test.items():
> got, _ = discretize_symbolic(str(inp), locals=ns)
C:\Programs\Python37\lib\site-packages\kwant\continuum\tests\test_discretizer.py:145:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
C:\Programs\Python37\lib\site-packages\kwant\continuum\discretizer.py:185: in discretize_symbolic
hamiltonian = sympify(hamiltonian, locals)
C:\Programs\Python37\lib\site-packages\kwant\continuum\_common.py:193: in sympify
hamiltonian = sympy.sympify(expr, locals=locals)
C:\Programs\Python37\lib\site-packages\sympy\core\sympify.py:495: in sympify
expr = parse_expr(a, local_dict=locals, transformations=transformations, evaluate=evaluate)
C:\Programs\Python37\lib\site-packages\sympy\parsing\sympy_parser.py:1105: in parse_expr
raise e from ValueError(f"Error from parse_expr with transformed code: {code!r}")
C:\Programs\Python37\lib\site-packages\sympy\parsing\sympy_parser.py:1096: in parse_expr
rv = eval_expr(code, local_dict, global_dict)
C:\Programs\Python37\lib\site-packages\sympy\parsing\sympy_parser.py:916: in eval_expr
code, global_dict, local_dict) # take local objects in preference
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ???
E TypeError: 'Symbol' object is not callable
<string>:1: TypeError
_______________________ test_simple_derivations_matrix ________________________
ValueError: Error from parse_expr with transformed code: 'Matrix ([[k_x *A (x ,y )*k_x ]])'
The above exception was the direct cause of the following exception:
def test_simple_derivations_matrix():
test = {
kx**2 : {(0,): 2/ax**2, (1,): -1/ax**2},
kx**2 + ky**2 : {(0, 1): -1/ay**2, (0, 0): 2/ax**2 + 2/ay**2,
(1, 0): -1/ax**2},
kx**2 + ky**2 + kz**2 : {(1, 0, 0): -1/ax**2, (0, 0, 1): -1/az**2,
(0, 0, 0): 2/ax**2 + 2/ay**2 + 2/az**2,
(0, 1, 0): -1/ay**2},
ky**2 + kz**2 : {(0, 1): -1/az**2, (0, 0): 2/ay**2 + 2/az**2,
(1, 0): -1/ay**2},
kz**2 : {(0,): 2/az**2, (1,): -1/az**2},
kx * fA(x, y) * kx : {(1, ): -fA(ax/2 + x, y)/ax**2,
(0, ): fA(-ax/2 + x, y)/ax**2 + fA(ax/2 + x, y)/ax**2},
kx**2 + kz * fB(y) : {(1, 0): -1/ax**2, (0, 1): -I*fB(y)/(2*az),
(0, 0): 2/ax**2},
kx * fA(x) : {(0,): 0, (1,): -I*fA(ax + x)/(2*ax)},
ky * fA(x) : {(1,): -I*fA(x)/(2*ay), (0,): 0},
kx * fA(x) * B : {(0,): 0, (1,): -I*fA(ax + x)*B/(2*ax)},
5 * kx : {(0,): 0, (1,): -5*I/(2*ax)},
kx * (fA(x) + fB(x)) : {(0,): 0,
(1,): -I*fA(ax + x)/(2*ax) - I*fB(ax + x)/(2*ax)},
}
new_test = []
for inp, out in test.items():
new_out = {}
for k, v in out.items():
new_out[k] = sympy.Matrix([v])
new_test.append((sympy.Matrix([inp]), new_out))
for inp, out in new_test:
got, _ = discretize_symbolic(inp)
assert got == out
for inp, out in new_test:
> got, _ = discretize_symbolic(str(inp), locals=ns)
C:\Programs\Python37\lib\site-packages\kwant\continuum\tests\test_discretizer.py:198:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
C:\Programs\Python37\lib\site-packages\kwant\continuum\discretizer.py:185: in discretize_symbolic
hamiltonian = sympify(hamiltonian, locals)
C:\Programs\Python37\lib\site-packages\kwant\continuum\_common.py:193: in sympify
hamiltonian = sympy.sympify(expr, locals=locals)
C:\Programs\Python37\lib\site-packages\sympy\core\sympify.py:495: in sympify
expr = parse_expr(a, local_dict=locals, transformations=transformations, evaluate=evaluate)
C:\Programs\Python37\lib\site-packages\sympy\parsing\sympy_parser.py:1105: in parse_expr
raise e from ValueError(f"Error from parse_expr with transformed code: {code!r}")
C:\Programs\Python37\lib\site-packages\sympy\parsing\sympy_parser.py:1096: in parse_expr
rv = eval_expr(code, local_dict, global_dict)
C:\Programs\Python37\lib\site-packages\sympy\parsing\sympy_parser.py:916: in eval_expr
code, global_dict, local_dict) # take local objects in preference
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ???
E TypeError: 'Symbol' object is not callable
<string>:1: TypeError
=========================== short test summary info ===========================
FAILED ..\..\..\..\..\..\..\Programs\Python37\lib\site-packages\kwant\continuum\tests\test_discretizer.py::test_simple_derivations[False]
FAILED ..\..\..\..\..\..\..\Programs\Python37\lib\site-packages\kwant\continuum\tests\test_discretizer.py::test_simple_derivations_matrix
================= 2 failed, 344 passed, 18 skipped in 48.68s ==================
Process finished with exit code 0