NeuroDiffGym / neurodiffeq

A library for solving differential equations using neural networks based on PyTorch, used by multiple research groups around the world, including at Harvard IACS.
http://pypi.org/project/neurodiffeq/
MIT License
680 stars 89 forks source link

Is there a way to access the train/valid loss history for Solver1D, like for solve? #161

Closed lbertge closed 2 years ago

lbertge commented 2 years ago

(this issue is specifically directed for the ODE solver, but probably can be extended to the other solvers in the package):

The currently-deprecated function solve used to return both the solution and the loss history, like so:

solution_ex, loss_ex = solve(
    ode=exponential, condition=init_val_ex, t_min=0.0, t_max=2.0
)

Following the API's suggestion, I switched to using the the Solver1D class, which now is formatted as such:

solver = Solver1D(
    ode_system = exponential,
    conditions = [init_val_ex],
    t_min=0.0,
    t_max=3.0,
    ... # other parameters
)

monitor = Monitor1D(...)
solver.fit(
    max_epochs=1000,
    callbacks=[monitor.to_callback()]
)

I can access the solution function via solver.get_solution(), but is there an analogous way to access the loss history? I attempted to look through the documentation without much luck. My thinking is either

shuheng-liu commented 2 years ago

Hi Albert, you can access the loss history (as well as the history of other custom metrics) via

print(solver.metrics_history['train_loss'])
print(solver.metrics_history['valid_loss'])
# etc.
lbertge commented 2 years ago

Thank you!