qiskit/mapper/_mapping.py
def swap_mapper_layer_update(i, first_layer, best_layout, best_d,
                             best_circ, layer_list):
    """Update the QASM string for an iteration of swap_mapper.

    i = layer number
    first_layer = True if this is the first layer with multi-qubit gates
    best_layout = layout returned from swap algorithm
    best_d = depth returned from swap algorithm
    best_circ = swap circuit returned from swap algorithm
    layer_list = list of circuit objects for each layer

    Return DAGCircuit object to append to the output DAGCircuit.
    """
    layout = best_layout
    layout_max_index = max(map(lambda x: x[1]+1, layout.values()))
    dagcircuit_output = DAGCircuit()
    dagcircuit_output.add_qreg("q", layout_max_index)
    # Identity wire-map for composing the circuits
    identity_wire_map = {('q', j): ('q', j) for j in range(layout_max_index)}

    # If this is the first layer with multi-qubit gates,
    # output all layers up to this point and ignore any
    # swap gates. Set the initial layout.
    if first_layer:
        logger.debug("update_qasm_and_layout: first multi-qubit gate layer")
        # Output all layers up to this point
        for j in range(i + 1):
            dagcircuit_output.compose_back(layer_list[j]["graph"], layout)
    # Otherwise, we output the current layer and the associated swap gates.
    else:
        # Output any swaps
        if best_d > 0:
            logger.debug("update_qasm_and_layout: swaps in this layer, "
                         "depth %d", best_d)
            dagcircuit_output.compose_back(best_circ, identity_wire_map)
        else:
            logger.debug("update_qasm_and_layout: no swaps in this layer")
        # Output this layer
        dagcircuit_output.compose_back(layer_list[i]["graph"], layout)
    return dagcircuit_output
Update the QASM string for an iteration of swap_mapper.

    i = layer number
    first_layer = True if this is the first layer with multi-qubit gates
    best_layout = layout returned from swap algorithm
    best_d = depth returned from swap algorithm
    best_circ = swap circuit returned from swap algorithm
    layer_list = list of circuit objects for each layer

    Return DAGCircuit object to append to the output DAGCircuit.
    
Update the QASM string for an iteration of swap_mapper.

Return DAGCircuit object to append to the output DAGCircuit.
Update the QASM string for an iteration of swap_mapper . Return DAGCircuit object to append to the output DAGCircuit .
def swap_mapper_layer_update(i, first_layer, best_layout, best_d,
                             best_circ, layer_list):
    layout = best_layout
    layout_max_index = max(map(lambda x: x[1]+1, layout.values()))
    dagcircuit_output = DAGCircuit()
    dagcircuit_output.add_qreg("q", layout_max_index)
    identity_wire_map = {('q', j): ('q', j) for j in range(layout_max_index)}
    if first_layer:
        logger.debug("update_qasm_and_layout: first multi-qubit gate layer")
        for j in range(i + 1):
            dagcircuit_output.compose_back(layer_list[j]["graph"], layout)
    else:
        if best_d > 0:
            logger.debug("update_qasm_and_layout: swaps in this layer, "
                         "depth %d", best_d)
            dagcircuit_output.compose_back(best_circ, identity_wire_map)
        else:
            logger.debug("update_qasm_and_layout: no swaps in this layer")
        dagcircuit_output.compose_back(layer_list[i]["graph"], layout)
    return dagcircuit_output
def swap_mapper_layer_update ( i , first_layer , best_layout , best_d , best_circ , layer_list ) : layout = best_layout layout_max_index = max ( map ( lambda x : x [ 1 ] + 1 , layout . values ( ) ) ) dagcircuit_output = DAGCircuit ( ) dagcircuit_output . add_qreg ( "q" , layout_max_index ) identity_wire_map = { ( 'q' , j ) : ( 'q' , j ) for j in range ( layout_max_index ) } if first_layer : logger . debug ( "update_qasm_and_layout: first multi-qubit gate layer" ) for j in range ( i + 1 ) : dagcircuit_output . compose_back ( layer_list [ j ] [ "graph" ] , layout ) else : if best_d > 0 : logger . debug ( "update_qasm_and_layout: swaps in this layer, " "depth %d" , best_d ) dagcircuit_output . compose_back ( best_circ , identity_wire_map ) else : logger . debug ( "update_qasm_and_layout: no swaps in this layer" ) dagcircuit_output . compose_back ( layer_list [ i ] [ "graph" ] , layout ) return dagcircuit_output
Update the QASM string for an iteration of swap_mapper.
Update the QASM string for an iteration of swap_mapper .
"""Update the QASM string for an iteration of swap_mapper.

    i = layer number
    first_layer = True if this is the first layer with multi-qubit gates
    best_layout = layout returned from swap algorithm
    best_d = depth returned from swap algorithm
    best_circ = swap circuit returned from swap algorithm
    layer_list = list of circuit objects for each layer

    Return DAGCircuit object to append to the output DAGCircuit.
    """ # Identity wire-map for composing the circuits # If this is the first layer with multi-qubit gates, # output all layers up to this point and ignore any # swap gates. Set the initial layout. # Output all layers up to this point # Otherwise, we output the current layer and the associated swap gates. # Output any swaps # Output this layer
i
first_layer
best_layout
best_d
best_circ
layer_list