qiskit/tools/apps/optimization.py
def group_paulis(pauli_list):
    """
    Groups a list of (coeff,Pauli) tuples into tensor product basis (tpb) sets

    Args:
        pauli_list (list): a list of (coeff, Pauli object) tuples.
    Returns:
        list: A list of tpb sets, each one being a list of (coeff, Pauli
            object) tuples.
    """
    n = len(pauli_list[0][1].v)
    pauli_list_grouped = []
    pauli_list_sorted = []
    for p_1 in pauli_list:
        if p_1 not in pauli_list_sorted:
            pauli_list_temp = []
            # pauli_list_temp.extend(p_1) # this is going to signal the total
            # post-rotations of the set (set master)
            pauli_list_temp.append(list(p_1))
            pauli_list_temp.append(copy.deepcopy(list(p_1)))
            pauli_list_temp[0][0] = 0
            for p_2 in pauli_list:
                if p_2 not in pauli_list_sorted and p_1[1] != p_2[1]:
                    j = 0
                    for i in range(n):
                        if not ((p_2[1].v[i] == 0 and p_2[1].w[i] == 0) or
                                (p_1[1].v[i] == 0 and p_1[1].w[i] == 0) or
                                (p_2[1].v[i] == p_1[1].v[i] and
                                 p_2[1].w[i] == p_1[1].w[i])):
                            break
                        else:
                            # update master
                            if p_2[1].v[i] == 1 or p_2[1].w[i] == 1:
                                pauli_list_temp[0][1].v[i] = p_2[1].v[i]
                                pauli_list_temp[0][1].w[i] = p_2[1].w[i]

                        j += 1

                    if j == n:
                        pauli_list_temp.append(p_2)
                        pauli_list_sorted.append(p_2)
            pauli_list_grouped.append(pauli_list_temp)

    return pauli_list_grouped

    Groups a list of (coeff,Pauli) tuples into tensor product basis (tpb) sets

    Args:
        pauli_list (list): a list of (coeff, Pauli object) tuples.
    Returns:
        list: A list of tpb sets, each one being a list of (coeff, Pauli
            object) tuples.
    
Groups a list of (coeff,Pauli) tuples into tensor product basis (tpb) sets
Groups a list of ( coeff Pauli ) tuples into tensor product basis ( tpb ) sets
def group_paulis(pauli_list):
    n = len(pauli_list[0][1].v)
    pauli_list_grouped = []
    pauli_list_sorted = []
    for p_1 in pauli_list:
        if p_1 not in pauli_list_sorted:
            pauli_list_temp = []
            pauli_list_temp.append(list(p_1))
            pauli_list_temp.append(copy.deepcopy(list(p_1)))
            pauli_list_temp[0][0] = 0
            for p_2 in pauli_list:
                if p_2 not in pauli_list_sorted and p_1[1] != p_2[1]:
                    j = 0
                    for i in range(n):
                        if not ((p_2[1].v[i] == 0 and p_2[1].w[i] == 0) or
                                (p_1[1].v[i] == 0 and p_1[1].w[i] == 0) or
                                (p_2[1].v[i] == p_1[1].v[i] and
                                 p_2[1].w[i] == p_1[1].w[i])):
                            break
                        else:
                            if p_2[1].v[i] == 1 or p_2[1].w[i] == 1:
                                pauli_list_temp[0][1].v[i] = p_2[1].v[i]
                                pauli_list_temp[0][1].w[i] = p_2[1].w[i]
                        j += 1
                    if j == n:
                        pauli_list_temp.append(p_2)
                        pauli_list_sorted.append(p_2)
            pauli_list_grouped.append(pauli_list_temp)
    return pauli_list_grouped
def group_paulis ( pauli_list ) : n = len ( pauli_list [ 0 ] [ 1 ] . v ) pauli_list_grouped = [ ] pauli_list_sorted = [ ] for p_1 in pauli_list : if p_1 not in pauli_list_sorted : pauli_list_temp = [ ] pauli_list_temp . append ( list ( p_1 ) ) pauli_list_temp . append ( copy . deepcopy ( list ( p_1 ) ) ) pauli_list_temp [ 0 ] [ 0 ] = 0 for p_2 in pauli_list : if p_2 not in pauli_list_sorted and p_1 [ 1 ] != p_2 [ 1 ] : j = 0 for i in range ( n ) : if not ( ( p_2 [ 1 ] . v [ i ] == 0 and p_2 [ 1 ] . w [ i ] == 0 ) or ( p_1 [ 1 ] . v [ i ] == 0 and p_1 [ 1 ] . w [ i ] == 0 ) or ( p_2 [ 1 ] . v [ i ] == p_1 [ 1 ] . v [ i ] and p_2 [ 1 ] . w [ i ] == p_1 [ 1 ] . w [ i ] ) ) : break else : if p_2 [ 1 ] . v [ i ] == 1 or p_2 [ 1 ] . w [ i ] == 1 : pauli_list_temp [ 0 ] [ 1 ] . v [ i ] = p_2 [ 1 ] . v [ i ] pauli_list_temp [ 0 ] [ 1 ] . w [ i ] = p_2 [ 1 ] . w [ i ] j += 1 if j == n : pauli_list_temp . append ( p_2 ) pauli_list_sorted . append ( p_2 ) pauli_list_grouped . append ( pauli_list_temp ) return pauli_list_grouped
Groups a list of (coeff,Pauli) tuples into tensor product basis (tpb) sets
Groups a list of ( coeff Pauli ) tuples into tensor product basis ( tpb ) sets
"""
    Groups a list of (coeff,Pauli) tuples into tensor product basis (tpb) sets

    Args:
        pauli_list (list): a list of (coeff, Pauli object) tuples.
    Returns:
        list: A list of tpb sets, each one being a list of (coeff, Pauli
            object) tuples.
    """ # pauli_list_temp.extend(p_1) # this is going to signal the total # post-rotations of the set (set master) # update master
A list of tpb sets, each one being a list of (coeff, Pauli
object) tuples.
A list of tpb sets each one being a list of ( coeff Pauli object ) tuples .
list
pauli_list
a list of (coeff, Pauli object) tuples.
a list of ( coeff Pauli object ) tuples .