Skip to content

Commit

Permalink
Address Deprecation Warnings (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
prisae authored Feb 20, 2024
1 parent 0063de3 commit 977c12b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion emg3d/meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ def _seasurface(edges, widths, center, seasurface, stretching, vector, limits):

# No vector given (only one existing cell).
if vector is None:
tdmin = fact*widths
tdmin = fact*widths.item()
cedge = center + tdmin/2
alphmax = 1.1*stretching[0] # 10 % extra stretching.

Expand Down
7 changes: 6 additions & 1 deletion emg3d/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from dataclasses import dataclass

import numpy as np
import scipy as sp
import scipy.linalg as sl
import scipy.sparse.linalg as ssl

Expand All @@ -41,6 +42,10 @@
'RegularGridProlongator']


# Remove once scipy >= 3.12 is required!
TOL = 'tol' if int(sp.__version__.split('.')[1]) < 12 else 'rtol'


def __dir__():
return __all__

Expand Down Expand Up @@ -758,7 +763,7 @@ def callback(x):
# therefore throw an exception in `_terminate`, and catch it here.
try:
efield.field, i = getattr(ssl, var.sslsolver)(
A=A, b=sfield.field, x0=efield.field, tol=var.tol,
A=A, b=sfield.field, x0=efield.field, **{TOL: var.tol},
maxiter=var.ssl_maxit, atol=1e-30, M=M, callback=callback)
except _ConvergenceError:
i = -1 # Mark it as error; returned field is all zero.
Expand Down
10 changes: 5 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __exit__(self, *exc):
def test_main(script_runner):

# Test the installed version runs by -h.
ret = script_runner.run('emg3d', '-h')
ret = script_runner.run(['emg3d', '-h'])
assert ret.success
assert "Multigrid solver for 3D electromagnetic diffusion." in ret.stdout

Expand All @@ -47,19 +47,19 @@ def test_main(script_runner):

# Test emg3d/cli/_main_.py by calling the file - I.
ret = script_runner.run(
'python', join('emg3d', 'cli', 'main.py'), '--version')
['python', join('emg3d', 'cli', 'main.py'), '--version'])
assert ret.success
assert "emg3d v" in ret.stdout

# Test emg3d/cli/_main_.py by calling the file - II.
ret = script_runner.run(
'python', join('emg3d', 'cli', 'main.py'), '--report')
['python', join('emg3d', 'cli', 'main.py'), '--report'])
assert ret.success
# Exclude time to avoid errors.
assert emg3d.utils.Report().__repr__()[115:475] in ret.stdout

# Test emg3d/cli/_main_.py by calling the file - III.
ret = script_runner.run('python', join('emg3d', 'cli', 'main.py'), '-d')
ret = script_runner.run(['python', join('emg3d', 'cli', 'main.py'), '-d'])
assert not ret.success
assert "* ERROR :: Config file not found: " in ret.stderr

Expand All @@ -72,7 +72,7 @@ def test_main(script_runner):
def test_main2(script_runner):

# Test emg3d/__main__.py by calling the folder emg3d.
ret = script_runner.run('python', 'emg3d', '--report')
ret = script_runner.run(['python', 'emg3d', '--report'])
assert ret.success
# Exclude time to avoid errors.
# Exclude empymod-version (after 475), because if run locally without
Expand Down
2 changes: 1 addition & 1 deletion tests/test_electrodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ def fwd(u):
def adj(v):
"""What does `Simulation._get_rfield()`."""
# The strength in _get_rfield is conj(residual*weight), normalized
strength = complex(v/-smu0)
strength = complex(v.item()/-smu0)
src = rec._adjoint_source(rec.coordinates, strength=strength)
return src.get_field(mesh, frequency).field

Expand Down
2 changes: 2 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
import pytest
import numpy as np
from copy import deepcopy
Expand Down Expand Up @@ -113,6 +114,7 @@ def test_json(self, tmpdir):

def test_convert(self, tmpdir):
io.save(tmpdir+'/test.npz', **self.data)
time.sleep(0.1)
io.convert(tmpdir+'/test.npz', tmpdir+'/test.json')
h5 = io.load(tmpdir+'/test.npz')
js = io.load(tmpdir+'/test.json')
Expand Down

0 comments on commit 977c12b

Please sign in to comment.