code: def test_riemannian_gradient_evolution(circuit, hamiltonian):
      """Test that the optimizer produces the correct unitary to append."""
      # pylint: disable=no-member
      nqubits = max(max(ps.wires) for ps in hamiltonian.ops) + 1
      wires = range(nqubits)
      dev = qml.device("default.qubit", wires=nqubits)
  
      @qml.qnode(dev)
      def get_state():
          circuit()
          return qml.state()
  
      @qml.qnode(dev)
      def test_circuit():
          circuit()
          return qml.expval(hamiltonian)
  
      phi = get_state()
      rho = np.outer(phi, phi.conj())
      hamiltonian_np = hamiltonian.sparse_matrix(
          wire_order=wires
      ).toarray()
      riemannian_gradient_np = (
          hamiltonian_np @ rho - rho @ hamiltonian_np
      )
  
      phi_exact = (
          expm(-0.1 * riemannian_gradient_np * 2**nqubits) @ phi
      )
      rho_exact = np.outer(phi_exact, phi_exact.conj())
      opt = RiemannianGradientOptimizer(
          circuit=test_circuit, stepsize=0.1, exact=True
      )
      opt.step_and_cost()
      cost_pl = opt.circuit()
      cost_exact = np.trace(rho_exact @ hamiltonian_np)
      assert np.allclose(cost_pl, cost_exact, atol=1e-4)
  
file_path: pennylane/tests/optimize/test_riemannian_gradient_optimizer.py
imports: import pytest
  from scipy.sparse.linalg import expm
  import numpy
  import pennylane
  from pennylane.optimize import RiemannianGradientOptimizer
label_desc: Use image node_id 6 for calling a global function with example usage: test_riemannian_gradient_evolution(circuit, hamiltonian) and returns: qml, qml