Ejemplo n.º 1
0
            tmp = pauli_group(number_of_qubits, case="tensor")
            # sort on the weight of the Pauli operator
            return sorted(tmp,
                          key=lambda x: -np.count_nonzero(
                              np.array(x.to_label(), "c") == b"I"))
        elif case == "tensor":
            # the Pauli set is in tensor order II IX IY IZ XI ...
            for k in range(4**number_of_qubits):
                z = np.zeros(number_of_qubits, dtype=bool)
                x = np.zeros(number_of_qubits, dtype=bool)
                # looping over all the qubits
                for j in range(number_of_qubits):
                    # making the Pauli for each j fill it in from the
                    # end first
                    element = (k // (4**j)) % 4
                    if element == 1:
                        x[j] = True
                    elif element == 2:
                        z[j] = True
                        x[j] = True
                    elif element == 3:
                        z[j] = True
                temp_set.append(Pauli(z, x))
            return temp_set
        else:
            raise QiskitError(
                f"Only support 'weight' or 'tensor' cases but you have {case}."
            )

    raise QiskitError("Only support number of qubits is less than 5")