xitorch
xitorch copied to clipboard
Raise warnings for unused kwargs when using some methods
Some methods, like rootfinder
accepts **kwargs
that will be passed to the specific method. However, there is no warnings raised when users specify redundant kwargs
.
To reproduce:
import torch
from xitorch.optimize import rootfinder
def func1(y, A): # example function
return torch.tanh(A @ y + 0.1) + y / 2.0
A = torch.tensor([[1.1, 0.4], [0.3, 0.8]]).requires_grad_()
y0 = torch.zeros((2, 1)) # zeros as the initial guess
yroot = rootfinder(func1, y0, params=(A,), method="broyden1", unused_kwarg=1) # a warning should be raised here