class_docstr: Commutation DAG tests.
docstr: Test a the DAG and its attributes for a more complicated circuit.
docstr_tok: ["Test","a","the","DAG","and","its","attributes","for","a","more","complicated","circuit","."]
code: def test_dag_pattern(self):
      "Test a the DAG and its attributes for a more complicated circuit."
      # pylint: disable=protected-access
  
      def circuit():
          qml.CNOT(wires=[3, 0])
          qml.PauliX(wires=4)
          qml.PauliZ(wires=0)
          qml.CNOT(wires=[4, 2])
          qml.CNOT(wires=[0, 1])
          qml.CNOT(wires=[3, 4])
          qml.CNOT(wires=[1, 2])
          qml.PauliX(wires=1)
          qml.CNOT(wires=[1, 0])
          qml.PauliX(wires=1)
          qml.CNOT(wires=[1, 2])
          qml.CNOT(wires=[0, 3])
  
      dag = qml.transforms.commutation_dag(circuit)()
  
      wires = [3, 0, 4, 2, 1]
      consecutive_wires = Wires(range(len(wires)))
      wires_map = OrderedDict(zip(wires, consecutive_wires))
  
      nodes = [
          qml.CNOT(wires=[3, 0]),
          qml.PauliX(wires=4),
          qml.PauliZ(wires=0),
          qml.CNOT(wires=[4, 2]),
          qml.CNOT(wires=[0, 1]),
          qml.CNOT(wires=[3, 4]),
          qml.CNOT(wires=[1, 2]),
          qml.PauliX(wires=1),
          qml.CNOT(wires=[1, 0]),
          qml.PauliX(wires=1),
          qml.CNOT(wires=[1, 2]),
          qml.CNOT(wires=[0, 3]),
      ]
  
      for node in nodes:
          node._wires = Wires(
              [wires_map[wire] for wire in node.wires.tolist()]
          )
  
      edges = [
          (0, 2, {"commute": False}),
          (0, 4, {"commute": False}),
          (1, 3, {"commute": False}),
          (2, 8, {"commute": False}),
          (3, 5, {"commute": False}),
          (4, 6, {"commute": False}),
          (5, 11, {"commute": False}),
          (6, 7, {"commute": False}),
          (7, 8, {"commute": False}),
          (8, 9, {"commute": False}),
          (8, 11, {"commute": False}),
          (9, 10, {"commute": False}),
      ]
  
      direct_successors = [
          [2, 4],
          [3],
          [8],
          [5],
          [6],
          [11],
          [7],
          [8],
          [9, 11],
          [10],
          [],
          [],
      ]
      successors = [
          [2, 4, 6, 7, 8, 9, 10, 11],
          [3, 5, 11],
          [8, 9, 10, 11],
          [5, 11],
          [6, 7, 8, 9, 10, 11],
          [11],
          [7, 8, 9, 10, 11],
          [8, 9, 10, 11],
          [9, 10, 11],
          [10],
          [],
          [],
      ]
      direct_predecessors = [
          [],
          [],
          [0],
          [1],
          [0],
          [3],
          [4],
          [6],
          [2, 7],
          [8],
          [9],
          [5, 8],
      ]
      predecessors = [
          [],
          [],
          [0],
          [1],
          [0],
          [1, 3],
          [0, 4],
          [0, 4, 6],
          [0, 2, 4, 6, 7],
          [0, 2, 4, 6, 7, 8],
          [0, 2, 4, 6, 7, 8, 9],
          [0, 1, 2, 3, 4, 5, 6, 7, 8],
      ]
  
      assert dag.observables == []
  
      for i in range(0, 12):
          assert dag.get_node(i).op.name == nodes[i].name
          assert dag.get_node(i).op.wires == nodes[i].wires
          assert dag.direct_successors(i) == direct_successors[i]
          assert (
              dag.get_node(i).successors
              == successors[i]
              == dag.successors(i)
          )
          assert dag.direct_predecessors(i) == direct_predecessors[i]
          assert (
              dag.get_node(i).predecessors
              == predecessors[i]
              == dag.predecessors(i)
          )
  
      for i, edge in enumerate(dag.get_edges()):
          assert edges[i] == edge
  
file_path: pennylane/tests/transforms/test_commutation_dag.py
imports: from collections import OrderedDict
  import pytest
  from pennylane.wires import Wires
  import pennylane.numpy
  import pennylane
label_desc: Use image node_id 6 for calling the TestCommutationDAG obj's underlying member method code with example usage: obj.test_dag_pattern() without return types