code: def _display_layers(circ: Circuit, qubits: Qubits) -> Circuit:
      
      N = len(qubits)
      qubit_idx = dict(zip(qubits, range(N)))
      gate_layers = DAGCircuit(circ).layers()
  
      layers = []
      lcirc = Circuit()
      layers.append(lcirc)
      unused = [True] * N
  
      for gl in gate_layers:
          assert isinstance(gl, Circuit)
          for gate in gl:
              indices = [qubit_idx[q] for q in gate.qubits]
  
              if not all(unused[min(indices):max(indices)+1]):
                  # New layer
                  lcirc = Circuit()
                  layers.append(lcirc)
                  unused = [True] * N
  
              unused[min(indices):max(indices)+1] = \
                  [False] * (max(indices) - min(indices) + 1)
              lcirc += gate
  
      return Circuit(layers)
docs: Separate a circuit into groups of gates that do not visually overlap