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