code: def test_state_metrics_ingredients_not_attached():
      y_pred = torch.randint(0, 2, size=(15, 10, 4)).float()
      y = torch.randint(0, 2, size=(15, 10, 4)).long()
  
      def update_fn(engine, batch):
          y_pred, y = batch
          return y_pred, y
  
      evaluator = Engine(update_fn)
  
      precision = Precision(average=False)
      recall = Recall(average=False)
      F1 = precision * recall * 2 / (precision + recall + 1e-20)
      F1 = MetricsLambda(lambda t: torch.mean(t).item(), F1)
  
      F1.attach(evaluator, "F1")
  
      def data(y_pred, y):
          for i in range(y_pred.shape[0]):
              yield (y_pred[i], y[i])
  
      d = data(y_pred, y)
      state = evaluator.run(
          d, max_epochs=1, epoch_length=y_pred.shape[0]
      )
  
      assert set(state.metrics.keys()) == set(["F1"])
  
imports: import os
  import numpy
  import pytest
  import torch
  from pytest import approx
  from sklearn.metrics import f1_score, precision_score, recall_score
  import ignite.distributed
  from ignite.engine import Engine
  from ignite.metrics import Accuracy, Metric, MetricsLambda, Precision, Recall
label_desc: Use image node_id 8 for calling a global function with example usage: test_state_metrics_ingredients_not_attached() and returns: y_pred,  y