code: def test_caching(gradient_fn):
      """Test that cache execute returns the cached result if the same script is executed
      multiple times, both in multiple times in a batch and in separate batches.
      """
      dev = DefaultQubit()
  
      qs = qml.tape.QuantumScript(
          [qml.PauliX(0)], [qml.expval(qml.PauliZ(0))]
      )
  
      cache = {}
  
      with qml.Tracker(dev) as tracker:
          results = qml.execute(
              [qs, qs], dev, cache=cache, gradient_fn=gradient_fn
          )
          results2 = qml.execute(
              [qs, qs], dev, cache=cache, gradient_fn=gradient_fn
          )
  
      assert len(cache) == 1
      assert cache[qs.hash] == -1.0
  
      assert list(results) == [-1.0, -1.0]
      assert list(results2) == [-1.0, -1.0]
  
      assert tracker.totals["batches"] == 1
      assert tracker.totals["executions"] == 1
      assert cache[qs.hash] == -1.0
  
file_path: pennylane/tests/interfaces/default_qubit_2_integration/test_execute_default_qubit_2.py
imports: import pytest
  import pennylane
  from pennylane import numpy
  from pennylane.workflow.execution import _preprocess_expand_fn
  from pennylane.devices import DefaultQubit
label_desc: Use image node_id 2 for calling a global function with example usage: test_caching(gradient_fn) without return types