Skip to content

Commit 8d08d86

Browse files
CLN warn user about unused parameters in Physics (deepinv#423)
* CLN warn user about unused parameters in Physics * CLN move kwargs to physics * TST check that the warning is raised * FIX linting * black --------- Co-authored-by: Andrewwango <[email protected]>
1 parent 09be3a9 commit 8d08d86

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

deepinv/physics/forward.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22
from typing import Union
3+
import warnings
34
import copy
45
import inspect
56
import collections.abc
@@ -49,6 +50,7 @@ def __init__(
4950
solver="gradient_descent",
5051
max_iter=50,
5152
tol=1e-4,
53+
**kwargs,
5254
):
5355
super().__init__()
5456
self.noise_model = noise_model
@@ -59,6 +61,11 @@ def __init__(
5961
self.tol = tol
6062
self.solver = solver
6163

64+
if len(kwargs) > 0:
65+
warnings.warn(
66+
f"Arguments {kwargs} are passed to {self.__class__.__name__} but are ignored."
67+
)
68+
6269
def __mul__(self, other):
6370
r"""
6471
Concatenates two forward operators :math:`A = A_1\circ A_2` via the mul operation
@@ -411,6 +418,7 @@ def __init__(
411418
max_iter=max_iter,
412419
solver=solver,
413420
tol=tol,
421+
**kwargs,
414422
)
415423
self.A_adj = A_adjoint
416424

deepinv/tests/test_physics.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,3 +1876,10 @@ def test_clone(name, device):
18761876
# Restore original values
18771877
physics = saved_physics
18781878
physics_clone = saved_physics_clone
1879+
1880+
1881+
def test_physics_warn_extra_kwargs():
1882+
with pytest.warns(
1883+
UserWarning, match="Arguments {'sigma': 0.5} are passed to Denoising"
1884+
):
1885+
dinv.physics.Denoising(sigma=0.5)

0 commit comments

Comments
 (0)