Commit 0e398ff4 authored by Viacheslav Ostroukh's avatar Viacheslav Ostroukh 🚲
Browse files

Merge branch 'fix/ndarray_deprecation_warnings' into 'stable'

Fix Numpy-related deprecation warnings

See merge request !397
parents 9e1361b8 640e17fc
Pipeline #84271 passed with stages
in 47 minutes and 13 seconds
......@@ -15,6 +15,7 @@ import numpy as np
import tinyarray as ta
import sympy
from sympy.matrices.matrices import MatrixBase
from sympy.utilities.lambdify import lambdastr
from sympy.printing.lambdarepr import LambdaPrinter
from sympy.printing.precedence import precedence
......@@ -211,7 +212,7 @@ def discretize_symbolic(hamiltonian, coords=None, *, locals=None):
onsite_zeros = (0,) * len(coords)
if not isinstance(hamiltonian, sympy.matrices.MatrixBase):
if not isinstance(hamiltonian, MatrixBase):
hamiltonian = sympy.Matrix([hamiltonian])
_input_format = 'expression'
else:
......@@ -574,7 +575,7 @@ def _return_string(expr, coords):
expr = expr.subs(map_func_calls)
if isinstance(expr, sympy.matrices.MatrixBase):
if isinstance(expr, MatrixBase):
# express matrix return values in terms of sums of known matrices,
# which will be assigned to '_cache_n' in the function body.
mons = monomials(expr, expr.atoms(sympy.Symbol))
......
......@@ -1498,8 +1498,8 @@ def spectrum(syst, x, y=None, params=None, mask=None, file=None,
h_p = np.atleast_2d(bound_ham(**p))
spectrum.append(np.linalg.eigvalsh(h_p))
# massage masked grid points into a list of NaNs of the appropriate length
n_eigvals = len(next(filter(lambda s: s is not None, spectrum)))
nan_list = [np.nan] * n_eigvals
shape_eigvals = next(filter(lambda s: s is not None, spectrum)).shape
nan_list = np.full(shape_eigvals, np.nan)
spectrum = [nan_list if s is None else s for s in spectrum]
# make into a numpy array and reshape
new_shape = [len(v) for v in array_values] + [-1]
......@@ -1542,9 +1542,11 @@ def spectrum(syst, x, y=None, params=None, mask=None, file=None,
# plot_surface cannot directly handle rank-3 values, so we
# explicitly loop over the last axis
grid = np.meshgrid(*array_values)
for i in range(spectrum.shape[-1]):
spec = spectrum[:, :, i].transpose() # row-major to x-y ordering
ax.plot_surface(*(grid + [spec]), cstride=1, rstride=1)
with warnings.catch_warnings():
warnings.filterwarnings('ignore', message='Z contains NaN values')
for i in range(spectrum.shape[-1]):
spec = spectrum[:, :, i].transpose() # row-major to x-y ordering
ax.plot_surface(*(grid + [spec]), cstride=1, rstride=1)
_maybe_output_fig(fig, file=file, show=show)
......@@ -1687,8 +1689,13 @@ def _interpolate_field(dim, elements, discrete_field, bbox, width,
# Coordinates of the grid points that are within range of the current
# hopping.
coords = np.meshgrid(*[region[d][field_slice[d]] for d in range(dim)],
sparse=True, indexing='ij')
coords = np.array(
np.meshgrid(
*[region[d][field_slice[d]] for d in range(dim)],
sparse=True, indexing='ij'
),
dtype=object
)
# Convert "coords" into scaled distances from pos_offset
coords -= pos_offsets[i]
......
......@@ -18,6 +18,7 @@ import scipy.linalg as la
try:
import sympy
import sympy.matrices.matrices
import qsymm
from qsymm.model import Model, BlochModel, BlochCoeff
from qsymm.groups import PointGroupElement, ContinuousGroupGenerator
......
......@@ -814,7 +814,7 @@ class SMatrix(BlockResult):
block_offsets.append(block_offset)
# Symmetry block offsets for all leads - or None if lead does not have
# blocks.
self.block_offsets = block_offsets
self.block_offsets = np.array(block_offsets, dtype=object)
# Pick out symmetry block offsets for in and out leads
self.in_block_offsets = \
np.array(self.block_offsets)[list(self.in_leads)]
......
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