code: def test_donot_substitute_same_key_multiple_times():
      already_called = False
  
      def inc_only_once(x):
          nonlocal already_called
          if already_called:
              raise RuntimeError
          already_called = True
          return x + 1
  
      # This is the graph topology of a Z.T @ Z after blockwise fusion as given in
      # https://github.com/dask/dask/issues/10645
      dsk = {
          # Note that there is some logic in there that actually checks the type
          # of this and an integer is inlined while an array is not. However, data
          # keys are also flagged as forbidden to be fused so this should not be a
          # problem
          "A": 42,  # Array
          "B": (inc_only_once, "A"),  # Add
          "C": (add, "B", "B"),  # matmul
          "D": (inc, "C"),  # getitem
      }
  
      # fuse accepts dependencies to avoid having to recompute it. However,
      # internally it actually requires it to be in the format of dict[Key,
      # list[Key]] which is rarely used elsewhere since most applications are
      # using lists.
      # It uses these lists to infer duplicates in dependencies and avoids fusing
      # those sicne substituting the same key multiple times also causes them to
      # be computed multiple times. A better logic would replace those with a
      # SubGraphCallable
      dependencies = {"A": set(), "B": {"A"}, "C": {"B"}, "D": {"C"}}
      fused_dsk = fuse(
          dsk,
          keys=["A", "D"],
          dependencies=dependencies,
      )[0]
      from dask.core import get
  
      assert get(fused_dsk, "D") > 1
  
imports: from __future__ import annotations
  import itertools
  import pickle
  from functools import partial
  import pytest
  import dask
  from dask.base import tokenize
  from dask.core import get_dependencies
  from dask.local import get_sync
  from dask.optimization import SubgraphCallable, cull, functions_of, fuse, fuse_linear, inline, inline_functions
  from dask.utils import apply, partial_by_order
  from dask.utils_test import add, inc
label_desc: Use image node_id 9 for calling a global function with example usage: test_donot_substitute_same_key_multiple_times() and returns: unknown