code: def test_expvalD(symbols, geometry, charge, d_ref):
      r"""Test that expval(D) is correct."""
      mol = qchem.Molecule(symbols, geometry, charge=charge)
      args = []
      dev = qml.device("default.qubit", wires=6)
  
      def dipole(mol, idx):
          @qml.qnode(dev)
          def circuit(*args):
              qml.PauliX(0)
              qml.PauliX(1)
              qml.DoubleExcitation(0.0, wires=[0, 1, 2, 3])
              qml.DoubleExcitation(0.0, wires=[0, 1, 4, 5])
              d_qubit = qchem.dipole_moment(mol)(*args)[idx]
              return qml.expval(d_qubit)
  
          return circuit
  
      for i in range(3):  # loop on x, y, z components
          d = dipole(mol, i)(*args)
          assert np.allclose(d, d_ref[i])
  
file_path: pennylane/tests/qchem/test_dipole.py
imports: import pytest
  import pennylane
  from pennylane import PauliX, PauliY, PauliZ
  from pennylane import numpy
  from pennylane import qchem
  from pennylane.fermi import from_string
  from pennylane.operation import disable_new_opmath, enable_new_opmath
label_desc: Use image node_id 5 for calling a global function with example usage: test_expvalD(symbols, geometry, charge, d_ref) and returns: circuit, qml