qiskit/transpiler/passes/commutation_analysis.py
def run(self, dag):
        """
        Run the pass on the DAG, and write the discovered commutation relations
        into the property_set.
        """
        # Initiate the commutation set
        self.property_set['commutation_set'] = defaultdict(list)

        # Build a dictionary to keep track of the gates on each qubit
        for wire in dag.wires:
            wire_name = "{0}[{1}]".format(str(wire[0].name), str(wire[1]))
            self.property_set['commutation_set'][wire_name] = []

        # Add edges to the dictionary for each qubit
        for node in dag.topological_op_nodes():
            for (_, _, edge_data) in dag.edges(node):

                edge_name = edge_data['name']
                self.property_set['commutation_set'][(node, edge_name)] = -1

        for wire in dag.wires:
            wire_name = "{0}[{1}]".format(str(wire[0].name), str(wire[1]))

            for current_gate in dag.nodes_on_wire(wire):

                current_comm_set = self.property_set['commutation_set'][wire_name]
                if not current_comm_set:
                    current_comm_set.append([current_gate])

                if current_gate not in current_comm_set[-1]:
                    prev_gate = current_comm_set[-1][-1]
                    if _commute(current_gate, prev_gate):
                        current_comm_set[-1].append(current_gate)

                    else:
                        current_comm_set.append([current_gate])

                temp_len = len(current_comm_set)
                self.property_set['commutation_set'][(current_gate, wire_name)] = temp_len - 1
def run(self, dag):
        """
        Run the pass on the DAG, and write the discovered commutation relations
        into the property_set.
        """
        # Initiate the commutation set
        self.property_set['commutation_set'] = defaultdict(list)

        # Build a dictionary to keep track of the gates on each qubit
        for wire in dag.wires:
            wire_name = "{0}[{1}]".format(str(wire[0].name), str(wire[1]))
            self.property_set['commutation_set'][wire_name] = []

        # Add edges to the dictionary for each qubit
        for node in dag.topological_op_nodes():
            for (_, _, edge_data) in dag.edges(node):

                edge_name = edge_data['name']
                self.property_set['commutation_set'][(node, edge_name)] = -1

        for wire in dag.wires:
            wire_name = "{0}[{1}]".format(str(wire[0].name), str(wire[1]))

            for current_gate in dag.nodes_on_wire(wire):

                current_comm_set = self.property_set['commutation_set'][wire_name]
                if not current_comm_set:
                    current_comm_set.append([current_gate])

                if current_gate not in current_comm_set[-1]:
                    prev_gate = current_comm_set[-1][-1]
                    if _commute(current_gate, prev_gate):
                        current_comm_set[-1].append(current_gate)

                    else:
                        current_comm_set.append([current_gate])

                temp_len = len(current_comm_set)
                self.property_set['commutation_set'][(current_gate, wire_name)] = temp_len - 1
def run ( self , dag ) : # Initiate the commutation set self . property_set [ 'commutation_set' ] = defaultdict ( list ) # Build a dictionary to keep track of the gates on each qubit for wire in dag . wires : wire_name = "{0}[{1}]" . format ( str ( wire [ 0 ] . name ) , str ( wire [ 1 ] ) ) self . property_set [ 'commutation_set' ] [ wire_name ] = [ ] # Add edges to the dictionary for each qubit for node in dag . topological_op_nodes ( ) : for ( _ , _ , edge_data ) in dag . edges ( node ) : edge_name = edge_data [ 'name' ] self . property_set [ 'commutation_set' ] [ ( node , edge_name ) ] = - 1 for wire in dag . wires : wire_name = "{0}[{1}]" . format ( str ( wire [ 0 ] . name ) , str ( wire [ 1 ] ) ) for current_gate in dag . nodes_on_wire ( wire ) : current_comm_set = self . property_set [ 'commutation_set' ] [ wire_name ] if not current_comm_set : current_comm_set . append ( [ current_gate ] ) if current_gate not in current_comm_set [ - 1 ] : prev_gate = current_comm_set [ - 1 ] [ - 1 ] if _commute ( current_gate , prev_gate ) : current_comm_set [ - 1 ] . append ( current_gate ) else : current_comm_set . append ( [ current_gate ] ) temp_len = len ( current_comm_set ) self . property_set [ 'commutation_set' ] [ ( current_gate , wire_name ) ] = temp_len - 1
Run the pass on the DAG, and write the discovered commutation relations
        into the property_set.
Run the pass on the DAG and write the discovered commutation relations into the property_set .