Exemple #1
0
 def _from_label(label):
     """Return the symplectic representation of a Pauli stabilizer string"""
     # Check if first character is '+' or '-'
     phase = False
     if label[0] in ['-', '+']:
         phase = (label[0] == '-')
         label = label[1:]
     return PauliTable._from_label(label), phase
Exemple #2
0
 def from_list(obj):
     """Construct from a list [(pauli_str, coeffs)]"""
     obj = list(obj)  # To convert zip or other iterable
     num_qubits = len(PauliTable._from_label(obj[0][0]))
     size = len(obj)
     coeffs = np.zeros(size, dtype=complex)
     labels = np.zeros(size, dtype='<U{}'.format(num_qubits))
     for i, item in enumerate(obj):
         labels[i] = item[0]
         coeffs[i] = item[1]
     table = PauliTable.from_labels(labels)
     return SparsePauliOp(table, coeffs)