Commit b09dfe52 authored by Viacheslav Ostroukh's avatar Viacheslav Ostroukh 🚲
Browse files

resolve sympy numbers module name correctly

Sympy 1.7 broke alias `sympy.numbers` and `sympy.core.numbers` should be used
instead. Second alias, however, can't be used in eariler Sympy version. This
fix uses one of them, dependent on what attribute is present.
parent ddecde8c
Pipeline #75477 passed with stages
in 8 minutes and 26 seconds
......@@ -24,6 +24,13 @@ try:
from qsymm.symmetry_finder import bravais_point_group
from qsymm.linalg import allclose
from qsymm.hamiltonian_generator import hamiltonian_from_family
# The try-except block below needs to be removed,
# when we require sympy >= 1.7
try:
sn = sympy.core.numbers
except AttributeError:
sn = sympy.numbers
except ImportError as error:
msg = ("'kwant.qsymm' is not available because one or more of its "
"dependencies is not installed.")
......@@ -345,9 +352,9 @@ def model_to_builder(model, norbs, lat_vecs, atom_coords, *, coeffs=None):
# If some onsite terms are not set, we set them to zero.
for atom in atoms:
if atom not in onsites_dict:
onsites_dict[atom] = Model(
{sympy.numbers.One(): np.zeros((norbs[atom], norbs[atom]))},
momenta=momenta)
onsites_dict[atom] = Model({
sn.One(): np.zeros((norbs[atom], norbs[atom]))
}, momenta=momenta)
# Make the Kwant system, and set all onsites and hoppings.
......
......@@ -180,7 +180,12 @@ def test_graphene_to_kwant():
assert allclose(hamiltonian2, hamiltonian3)
# Include random onsites as well
one = sympy.numbers.One()
# The try-except block below needs to be removed,
# when we require sympy >= 1.7
try:
one = sympy.core.numbers.One()
except AttributeError:
one = sympy.numbers.One()
onsites = [Model({one: np.array([[1, 0], [0, 0]])}, momenta=family[0].momenta),
Model({one: np.array([[0, 0], [0, 1]])}, momenta=family[0].momenta)]
family = family + onsites
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment