code: def _partial_cycle_mixer(
      graph: Union[nx.DiGraph, rx.PyDiGraph], edge: Tuple
  ) -> Hamiltonian:
      r"""Calculates the partial cycle-mixer Hamiltonian for a specific edge.
  
      For an edge :math:`(i, j)`, this function returns:
  
      .. math::
  
          \sum_{k \in V, k\neq i, k\neq j, (i, k) \in E, (k, j) \in E}\left[
          X_{ij}X_{ik}X_{kj} + Y_{ij}Y_{ik}X_{kj} + Y_{ij}X_{ik}Y_{kj} - X_{ij}Y_{ik}Y_{kj}\right]
  
      Args:
          graph (nx.DiGraph or rx.PyDiGraph): the directed graph specifying possible edges
          edge (tuple): a fixed edge
  
      Returns:
          qml.Hamiltonian: the partial cycle-mixer Hamiltonian
      """
      if not isinstance(graph, (nx.DiGraph, rx.PyDiGraph)):
          raise ValueError(
              f"Input graph must be a nx.DiGraph or rx.PyDiGraph, got {type(graph).__name__}"
          )
  
      coeffs = []
      ops = []
  
      is_rx = isinstance(graph, rx.PyDiGraph)
      edges_to_qubits = edges_to_wires(graph)
      graph_nodes = graph.node_indexes() if is_rx else graph.nodes
      graph_edges = sorted(graph.edge_list()) if is_rx else graph.edges
  
      # In RX each node is assigned to an integer index starting from 0;
      # thus, we use the following lambda function to get node-values.
      get_nvalues = (
          lambda T: (
              graph.nodes().index(T[0]),
              graph.nodes().index(T[1]),
          )
          if is_rx
          else T
      )
  
      for node in graph_nodes:
          out_edge = (edge[0], node)
          in_edge = (node, edge[1])
          if (
              node not in edge
              and out_edge in graph_edges
              and in_edge in graph_edges
          ):
              wire = edges_to_qubits[get_nvalues(edge)]
              out_wire = edges_to_qubits[get_nvalues(out_edge)]
              in_wire = edges_to_qubits[get_nvalues(in_edge)]
  
              t = (
                  qml.PauliX(wires=wire)
                  @ qml.PauliX(wires=out_wire)
                  @ qml.PauliX(wires=in_wire)
              )
              ops.append(t)
  
              t = (
                  qml.PauliY(wires=wire)
                  @ qml.PauliY(wires=out_wire)
                  @ qml.PauliX(wires=in_wire)
              )
              ops.append(t)
  
              t = (
                  qml.PauliY(wires=wire)
                  @ qml.PauliX(wires=out_wire)
                  @ qml.PauliY(wires=in_wire)
              )
              ops.append(t)
  
              t = (
                  qml.PauliX(wires=wire)
                  @ qml.PauliY(wires=out_wire)
                  @ qml.PauliY(wires=in_wire)
              )
              ops.append(t)
  
              coeffs.extend([0.25, 0.25, 0.25, -0.25])
  
      return Hamiltonian(coeffs, ops)
  
file_path: pennylane/pennylane/qaoa/cycle.py
imports: import itertools
  from typing import Dict, Tuple, Iterable, List, Union
  import networkx
  import rustworkx
  import numpy
  import pennylane
  from pennylane.ops import Hamiltonian
label_desc: Use image node_id 4 for calling a global function with example usage: _partial_cycle_mixer(graph, edge) and returns: Hamiltonian