class_docstr: A generic test case for training loops.
class_docstr_tok: ["A","generic","test","case","for","training","loops","."]
docstr: Test whether interrupting the given training loop type can be resumed using checkpoints.
docstr_tok: ["Test","whether","interrupting","the","given","training","loop","type","can","be","resumed","using","checkpoints","."]
code: def test_checkpoints(self):
      """Test whether interrupting the given training loop type can be resumed using checkpoints."""
      # Train a model in one shot
      model = TransE(
          triples_factory=self.triples_factory,
          random_seed=self.random_seed,
      )
      training_loop = self._with_model(model)
      losses = training_loop.train(
          triples_factory=self.triples_factory,
          num_epochs=self.num_epochs,
          batch_size=self.batch_size,
          use_tqdm=False,
          use_tqdm_batch=False,
      )
  
      with tempfile.TemporaryDirectory() as directory:
          name = "checkpoint.pt"
  
          # Train a model for the first half
          model = TransE(
              triples_factory=self.triples_factory,
              random_seed=self.random_seed,
          )
          training_loop = self._with_model(model)
          training_loop.train(
              triples_factory=self.triples_factory,
              num_epochs=int(self.num_epochs // 2),
              batch_size=self.batch_size,
              checkpoint_name=name,
              checkpoint_directory=directory,
              checkpoint_frequency=0,
          )
  
          # Continue training of the first part
          model = TransE(
              triples_factory=self.triples_factory,
              random_seed=123,
          )
          training_loop = self._with_model(model)
          losses_2 = training_loop.train(
              triples_factory=self.triples_factory,
              num_epochs=self.num_epochs,
              batch_size=self.batch_size,
              checkpoint_name=name,
              checkpoint_directory=directory,
              checkpoint_frequency=0,
          )
  
      self.assertEqual(losses, losses_2)
  
imports: import tempfile
  from typing import Any, ClassVar, MutableMapping, Optional, Type
  import torch
  import unittest_templates
  from torch.optim import Adam, Optimizer
  from pykeen.datasets import Nations
  from pykeen.losses import Loss
  from pykeen.models import ConvE, Model, TransE
  from pykeen.sampling.filtering import Filterer
  from pykeen.trackers.base import PythonResultTracker
  from pykeen.training import TrainingLoop
  from pykeen.training.training_loop import NonFiniteLossError, NoTrainingBatchError
  from pykeen.triples import TriplesFactory
label_desc: Use image node_id 8 for calling the TrainingLoopTestCase obj's underlying member method code with example usage: obj.test_checkpoints() without return types