def test_metric_learning_pipeline():
    """
    Test if classification pipeline can run and compute metrics.
    In this test we check that LoaderMetricCallback works with
    CMCMetric (ICallbackLoaderMetric).
    """
    with TemporaryDirectory() as tmp_dir:
        dataset_train = MnistMLDataset(root=tmp_dir, download=True)
        sampler = BatchBalanceClassSampler(
            labels=dataset_train.get_labels(),
            num_classes=3,
            num_samples=10,
            num_batches=10,
        )
        train_loader = DataLoader(
            dataset=dataset_train, batch_sampler=sampler, num_workers=0
        )
        dataset_val = MnistQGDataset(root=tmp_dir, gallery_fraq=0.2)
        val_loader = DataLoader(dataset=dataset_val, batch_size=1024)

        model = DummyModel(num_features=28 * 28, num_classes=NUM_CLASSES)
        optimizer = Adam(model.parameters(), lr=0.001)

        sampler_inbatch = HardTripletsSampler(norm_required=False)
        criterion = TripletMarginLossWithSampler(
            margin=0.5, sampler_inbatch=sampler_inbatch
        )

        callbacks = OrderedDict(
            {
                "cmc": dl.ControlFlowCallbackWrapper(
                    dl.CMCScoreCallback(
                        embeddings_key="embeddings",
                        labels_key="targets",
                        is_query_key="is_query",
                        topk=[1],
                    ),
                    loaders="valid",
                ),
                "control": dl.PeriodicLoaderCallback(
                    valid_loader_key="valid",
                    valid_metric_key="cmc",
                    minimize=False,
                    valid=2,
                ),
            }
        )

        runner = CustomRunner(input_key="features", output_key="embeddings")
        runner.train(
            model=model,
            criterion=criterion,
            optimizer=optimizer,
            callbacks=callbacks,
            loaders=OrderedDict({"train": train_loader, "valid": val_loader}),
            verbose=False,
            valid_loader="valid",
            num_epochs=4,
        )
        assert "cmc01" in runner.loader_metrics

    Test if classification pipeline can run and compute metrics.
    In this test we check that LoaderMetricCallback works with
    CMCMetric (ICallbackLoaderMetric).
    
tests/catalyst/runners/test_reid.py