TypeError: 'file' is an invalid keyword argument for warn()

Author: pgzmnkCreated Jul 11, 2025Updated Jul 11, 2025

Running odeint with fixed_adams solver. If the model doesn't converge, an error with the warnings.warn method arises.

sol = odeint(
    model, 
    ic[0], 
    ts,
    method="fixed_adams",
     ).detach().numpy()

Error:

File /opt/conda/envs/arcade/lib/python3.12/site-packages/torchdiffeq/_impl/fixed_adams.py:220, in AdamsBashforthMoulton._step_func(self, func, t0, dt, t1, y0)
    218         break
    219 if not converged:
--> 220     warnings.warn('Functional iteration did not converge. Solution may be incorrect.', file=sys.stderr)
    221     self.prev_f.pop()
    222 self._update_history(t0, f)

TypeError: 'file' is an invalid keyword argument for warn()