code: def test_grover_diffusion_matrix(n_wires):
      """Test that the Grover diffusion matrix is the same as when constructed in a different way"""
      wires = list(range(n_wires))
  
      # Test-oracle
      oracle = np.identity(2**n_wires)
      oracle[0, 0] = -1
  
      # s1 = H|0>, Hadamard on a single qubit in the ground state
      s1 = np.array([1, 1]) / np.sqrt(2)
  
      # uniform superposition state
      s = functools.reduce(np.kron, list(itertools.repeat(s1, n_wires)))
      # Grover matrix
      G_matrix = qml.GroverOperator(wires=wires).matrix()
  
      amplitudes = G_matrix @ oracle @ s
      probs = amplitudes**2
  
      # Create Grover diffusion matrix G in alternative way
      oplist = list(
          itertools.repeat(Hadamard.compute_matrix(), n_wires - 1)
      )
      oplist.append(PauliZ.compute_matrix())
  
      ctrl_str = "0" * (n_wires - 1)
      CX = MultiControlledX(
          control_values=ctrl_str,
          wires=wires,
          work_wires=None,
      ).matrix()
  
      M = functools.reduce(np.kron, oplist)
      G = M @ CX @ M
  
      amplitudes2 = G @ oracle @ s
      probs2 = amplitudes2**2
  
      assert np.allclose(probs, probs2)
  
file_path: pennylane/tests/templates/test_subroutines/test_grover.py
imports: import functools
  import itertools
  import pytest
  import numpy
  import pennylane
  from pennylane.ops import Hadamard, PauliZ, MultiControlledX
label_desc: Use image node_id 8 for calling a global function with example usage: test_grover_diffusion_matrix(n_wires) without return types