code: def test_error_on_wrong_keys():
      """Check that ValueError is raised when the sets of keys of the task metrics, preds, and targets do not match."""
      multitask_metrics = MultitaskWrapper(
          {
              "Classification": BinaryAccuracy(),
              "Regression": MeanSquaredError(),
          }
      )
  
      # Classification preds, but not regression preds
      wrong_key_preds = {"Classification": _classification_preds}
  
      # Classification targets, but not regression targets
      wrong_key_targets = {"Classification": _classification_target}
  
      # Classification metric, but not regression metric
      wrong_key_multitask_metrics = MultitaskWrapper(
          {
              "Classification": BinaryAccuracy(),
          }
      )
  
      with pytest.raises(
          ValueError,
          match=re.escape(
              "Expected arguments `task_preds` and `task_targets` to have the same keys as the wrapped `task_metrics`. "
              "Found task_preds.keys() = dict_keys(['Classification']), task_targets.keys() = "
              "dict_keys(['Classification', 'Regression']) and self.task_metrics.keys() = "
              "odict_keys(['Classification', 'Regression'])"
          ),
      ):
          multitask_metrics.update(wrong_key_preds, _multitask_targets)
  
      with pytest.raises(
          ValueError,
          match=re.escape(
              "Expected arguments `task_preds` and `task_targets` to have the same keys as the wrapped `task_metrics`. "
              "Found task_preds.keys() = dict_keys(['Classification', 'Regression']), task_targets.keys() = "
              "dict_keys(['Classification']) and self.task_metrics.keys() = odict_keys(['Classification', 'Regression'])"
          ),
      ):
          multitask_metrics.update(_multitask_preds, wrong_key_targets)
  
      with pytest.raises(
          ValueError,
          match=re.escape(
              "Expected arguments `task_preds` and `task_targets` to have the same keys as the wrapped `task_metrics`. "
              "Found task_preds.keys() = dict_keys(['Classification', 'Regression']), task_targets.keys() = "
              "dict_keys(['Classification', 'Regression']) and self.task_metrics.keys() = odict_keys(['Classification'])"
          ),
      ):
          wrong_key_multitask_metrics.update(
              _multitask_preds, _multitask_targets
          )
  
file_path: torchmetrics/tests/unittests/wrappers/test_multitask.py
imports: import re
  import pytest
  import torch
  from torchmetrics import MetricCollection
  from torchmetrics.classification import BinaryAccuracy, BinaryF1Score
  from torchmetrics.regression import MeanAbsoluteError, MeanSquaredError
  from torchmetrics.wrappers import MultitaskWrapper
  from unittests import BATCH_SIZE, NUM_BATCHES
  from unittests.helpers import seed_all
label_desc: Use image node_id 4 for calling a global function with example usage: test_error_on_wrong_keys() without return types