Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pixi lockfile, laplace interpolate tol -> (rtol, atol) for cg solve #257

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ Added

- Included ``edge_node_connectivity`` in :meth:`xugrid.Ugrid2d.from_meshkernel`,
so the ordering of edges is consistent with ``meshkernel``.

Changed
~~~~~~~

- :meth:`xugrid.UgridDataArrayAccessor.laplace_interpolate` now uses ``rtol``
and ``atol`` keywords instead of ``tol``, to match changes in
``scipy.linalg.sparse.cg``.

[0.10.0] 2024-05-01

[0.10.0] 2024-05-01
-------------------
Expand Down
24,252 changes: 12,317 additions & 11,935 deletions pixi.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ mapbox_earcut = "*"
matplotlib-base = "*"
netcdf4 = "*"
numba_celltree = "*"
numpy = "<2.0"
pip = "*"
pooch = "*"
pre-commit = "*"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def test_ilu0():
b[0] = 1.0
b[-1] = 1.0
M = interpolate.ILU0Preconditioner.from_csr_matrix(A)
_, info_cg = sparse.linalg.cg(A, b, tol=1.0e-5, maxiter=10)
x_pcg, info_pcg = sparse.linalg.cg(A, b, tol=1.0e-5, maxiter=10, M=M)
_, info_cg = sparse.linalg.cg(A, b, maxiter=10)
x_pcg, info_pcg = sparse.linalg.cg(A, b, maxiter=10, M=M)
x_direct = sparse.linalg.spsolve(A, b)
assert info_cg != 0 # cg does not converge
assert info_pcg == 0 # preconditioned cg does converge
Expand Down
10 changes: 7 additions & 3 deletions xugrid/core/dataarray_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,8 @@ def laplace_interpolate(
direct_solve: bool = False,
delta=0.0,
relax=0.0,
tol: float = 1.0e-5,
rtol=1.0e-5,
atol=0.0,
maxiter: int = 500,
):
"""
Expand Down Expand Up @@ -606,7 +607,9 @@ def laplace_interpolate(
ILU0 preconditioner non-diagonally dominant correction.
relax: float, default 0.0.
Modified ILU0 preconditioner relaxation factor.
tol: float, optional, default 1.0e-5.
rtol: float, optional, default 1.0e-5.
Convergence tolerance for ``scipy.sparse.linalg.cg``.
atol: float, optional, default 0.0.
Convergence tolerance for ``scipy.sparse.linalg.cg``.
maxiter: int, default 500.
Maximum number of iterations for ``scipy.sparse.linalg.cg``.
Expand All @@ -631,7 +634,8 @@ def laplace_interpolate(
direct_solve=direct_solve,
delta=delta,
relax=relax,
tol=tol,
rtol=rtol,
atol=atol,
maxiter=maxiter,
)
da_filled = da.copy(data=filled)
Expand Down
7 changes: 5 additions & 2 deletions xugrid/ugrid/interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ def laplace_interpolate(
direct_solve: bool = False,
delta=0.0,
relax=0.0,
tol: float = 1.0e-5,
atol: float = 0.0,
rtol: float = 1.0e-5,
maxiter: int = 500,
):
"""
Expand Down Expand Up @@ -235,6 +236,8 @@ def laplace_interpolate(
ILU0 preconditioner non-diagonally dominant correction.
relax: float, default 0.0
Modified ILU0 preconditioner relaxation factor.
atol: float, optional, default 0.0
Convergence tolerance for ``scipy.sparse.linalg.cg``.
tol: float, optional, default 1.0e-5.
Convergence tolerance for ``scipy.sparse.linalg.cg``.
maxiter: int, default 500.
Expand Down Expand Up @@ -301,7 +304,7 @@ def laplace_interpolate(
# Create preconditioner M
M = ILU0Preconditioner.from_csr_matrix(A, delta=delta, relax=relax)
# Call conjugate gradient solver
x, info = sparse.linalg.cg(A, rhs, tol=tol, maxiter=maxiter, M=M, atol="legacy")
x, info = sparse.linalg.cg(A, rhs, rtol=rtol, atol=atol, maxiter=maxiter, M=M)
if info < 0:
raise ValueError("scipy.sparse.linalg.cg: illegal input or breakdown")
elif info > 0:
Expand Down
Loading