def test_save_and_load_weights_w_likelihood(self, tmpdir_fn):
        """
        Verify that save/load does not break likelihood.

        Note: since load_weights() calls load_weights_from_checkpoint(), it will be used
        for all but one test.
        Note: Using DLinear since it supports both past and future covariates
        """
        model_dir = os.path.join(tmpdir_fn)
        manual_name = "save_manual"
        auto_name = "save_auto"
        # create manually saved model checkpoints folder
        checkpoint_path_manual = os.path.join(model_dir, manual_name)
        os.mkdir(checkpoint_path_manual)
        checkpoint_file_name = "checkpoint_0.pth.tar"
        model_path_manual = os.path.join(checkpoint_path_manual, checkpoint_file_name)

        model_auto_save = self.helper_create_DLinearModel(
            work_dir=tmpdir_fn,
            model_name=auto_name,
            save_checkpoints=True,
            likelihood=GaussianLikelihood(prior_mu=0.5),
        )
        model_auto_save.fit(self.series, epochs=1)
        pred_auto = model_auto_save.predict(n=4, series=self.series)

        model_manual_save = self.helper_create_DLinearModel(
            work_dir=tmpdir_fn,
            model_name=manual_name,
            save_checkpoints=False,
            likelihood=GaussianLikelihood(prior_mu=0.5),
        )
        model_manual_save.fit(self.series, epochs=1)
        model_manual_save.save(model_path_manual)
        pred_manual = model_manual_save.predict(n=4, series=self.series)

        # predictions are identical when using the same likelihood
        assert np.array_equal(pred_auto.values(), pred_manual.values())

        # model with identical likelihood
        model_same_likelihood = self.helper_create_DLinearModel(
            work_dir=tmpdir_fn,
            model_name="same_likelihood",
            likelihood=GaussianLikelihood(prior_mu=0.5),
        )
        model_same_likelihood.load_weights(model_path_manual, map_location="cpu")
        model_same_likelihood.predict(n=4, series=self.series)
        # cannot check predictions since this model is not fitted, random state is different

        # loading models weights with respective methods
        model_manual_same_likelihood = self.helper_create_DLinearModel(
            work_dir=tmpdir_fn,
            model_name="same_likelihood",
            likelihood=GaussianLikelihood(prior_mu=0.5),
        )
        model_manual_same_likelihood.load_weights(model_path_manual, map_location="cpu")
        preds_manual_from_weights = model_manual_same_likelihood.predict(
            n=4, series=self.series
        )

        model_auto_same_likelihood = self.helper_create_DLinearModel(
            work_dir=tmpdir_fn,
            model_name="same_likelihood",
            likelihood=GaussianLikelihood(prior_mu=0.5),
        )
        model_auto_same_likelihood.load_weights_from_checkpoint(
            auto_name, work_dir=tmpdir_fn, best=False, map_location="cpu"
        )
        preds_auto_from_weights = model_auto_same_likelihood.predict(
            n=4, series=self.series
        )
        # check that weights from checkpoint give identical predictions as weights from manual save
        assert preds_manual_from_weights == preds_auto_from_weights

        # model with explicitly no likelihood
        model_no_likelihood = self.helper_create_DLinearModel(
            work_dir=tmpdir_fn, model_name="no_likelihood", likelihood=None
        )
        with pytest.raises(ValueError) as error_msg:
            model_no_likelihood.load_weights_from_checkpoint(
                auto_name,
                work_dir=tmpdir_fn,
                best=False,
                map_location="cpu",
            )
        assert str(error_msg.value).startswith(
            "The values of the hyper-parameters in the model and loaded checkpoint should be identical.\n"
            "incorrect"
        )

        # model with missing likelihood (as if user forgot them)
        model_no_likelihood_bis = DLinearModel(
            input_chunk_length=4,
            output_chunk_length=1,
            model_name="no_likelihood_bis",
            add_encoders=None,
            work_dir=tmpdir_fn,
            save_checkpoints=False,
            random_state=42,
            force_reset=True,
            n_epochs=1,
            # likelihood=likelihood,
            **tfm_kwargs,
        )
        with pytest.raises(ValueError) as error_msg:
            model_no_likelihood_bis.load_weights_from_checkpoint(
                auto_name,
                work_dir=tmpdir_fn,
                best=False,
                map_location="cpu",
            )
        assert str(error_msg.value).startswith(
            "The values of the hyper-parameters in the model and loaded checkpoint should be identical.\n"
            "missing"
        )

        # model with the same likelihood but different parameters (output remains the same so does not matter)
        model_same_likelihood_other_prior = self.helper_create_DLinearModel(
            work_dir=tmpdir_fn,
            model_name="same_likelihood_other_prior",
            likelihood=GaussianLikelihood(),
        )
        with pytest.raises(ValueError) as error_msg:
            model_same_likelihood_other_prior.load_weights_from_checkpoint(
                auto_name, work_dir=tmpdir_fn, best=False, map_location="cpu"
            )
        assert str(error_msg.value).startswith(
            "The values of the hyper-parameters in the model and loaded checkpoint should be identical.\n"
            "incorrect"
        )

        # model with a different likelihood
        model_other_likelihood = self.helper_create_DLinearModel(
            work_dir=tmpdir_fn,
            model_name="other_likelihood",
            likelihood=LaplaceLikelihood(),
        )
        with pytest.raises(ValueError) as error_msg:
            model_other_likelihood.load_weights(model_path_manual, map_location="cpu")
        assert str(error_msg.value).startswith(
            "The values of the hyper-parameters in the model and loaded checkpoint should be identical.\n"
            "incorrect"
        )

        Verify that save/load does not break likelihood.

        Note: since load_weights() calls load_weights_from_checkpoint(), it will be used
        for all but one test.
        Note: Using DLinear since it supports both past and future covariates
        
darts/tests/models/forecasting/test_torch_forecasting_model.py