luigibonati / mlcolvar

A unified framework for machine learning collective variables for enhanced sampling simulations
MIT License
89 stars 24 forks source link

When validation set is disabled metrics callbacks are not returned #95

Closed EnricoTrizio closed 11 months ago

EnricoTrizio commented 11 months ago

If the validation set is disabled the metrics are not returned anymore

Metrics are updated at the end of the validation epoch, as implemented in mlcolvar.utils.trainer.MetricsCallback

class MetricsCallback(Callback):

Lightning callback which saves logged metrics into a dictionary.
The metrics are recorded at the end of each validation epoch.

   def __init__(self):
        super().__init__()
        self.metrics = {"epoch": []}

    def on_validation_epoch_end(self, trainer, pl_module):
        metrics = trainer.callback_metrics
        if not trainer.sanity_checking:
            self.metrics["epoch"].append(trainer.current_epoch)
            for key, val in metrics.items():
                val = val.item()
                if key in self.metrics:
                    self.metrics[key].append(val)
                else:
                    self.metrics[key] = [val]
luigibonati commented 11 months ago

I thought this was already fixed this in this commit: https://github.com/luigibonati/mlcolvar/pull/88/commits/2a43254d617d3f0c3c1285d733e2cc39a8a7f3a3

coming from this PR: https://github.com/luigibonati/mlcolvar/pull/88

EnricoTrizio commented 11 months ago

My fault, sorry