English
Languages
English
Bengali
French
German
Japanese
Korean
Portuguese
Spanish
Tamil

qiskit.quantum_info.SparsePauliOp.from_sparse_list

static SparsePauliOp.from_sparse_list(obj, num_qubits, do_checks=True, dtype=<class 'complex'>)[source]

Construct from a list of local Pauli strings and coefficients.

Each list element is a 3-tuple of a local Pauli string, indices where to apply it, and a coefficient.

For example, the 5-qubit Hamiltonian

\[H = Z_1 X_4 + 2 Y_0 Y_3\]

can be constructed as

# via triples and local Paulis with indices
op = SparsePauliOp.from_sparse_list([("ZX", [1, 4], 1), ("YY", [0, 3], 2)], num_qubits=5)

# equals the following construction from "dense" Paulis
op = SparsePauliOp.from_list([("XIIZI", 1), ("IYIIY", 2)])
Parameters
  • obj (Iterable[Tuple[str, List[int], complex]]) – The list 3-tuples specifying the Paulis.

  • num_qubits (int) – The number of qubits of the operator.

  • do_checks (bool) – The flag of checking if the input indices are not duplicated.

  • dtype (type) – The dtype of coeffs (Default complex).

Returns

The SparsePauliOp representation of the Pauli terms.

Return type

SparsePauliOp

Raises
  • QiskitError – If the list of Paulis is empty.

  • QiskitError – If the number of qubits is incompatible with the indices of the Pauli terms.

  • QiskitError – If the designated qubit is already assigned.