---
title: PhasedQubitSparsePauliList (latest version)
description: API reference for qiskit.quantum_info.PhasedQubitSparsePauliList in the latest version of qiskit
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit/qiskit.quantum_info.PhasedQubitSparsePauliList
---

# PhasedQubitSparsePauliList

*class* `qiskit.quantum_info.PhasedQubitSparsePauliList(data, /, num_qubits=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/quantum_info/__init__.py)

Bases: [`object`](https://docs.python.org/3/library/functions.html#object)

A list of Pauli operators with phases stored in a qubit-sparse format.

## Representation

Each individual Pauli operator in the list is a tensor product of single-qubit Pauli operators of the form $P = (-i)^n\bigotimes_n A^{(n)}_i$, for $A^{(n)}_i \in \{I, X, Y, Z\}$, and an integer $n$ called the phase exponent. The internal representation of a [`PhasedQubitSparsePauliList`](#qiskit.quantum_info.PhasedQubitSparsePauliList "qiskit.quantum_info.PhasedQubitSparsePauliList") stores only the non-identity single-qubit Pauli operators.

### Indexing

[`PhasedQubitSparsePauliList`](#qiskit.quantum_info.PhasedQubitSparsePauliList "qiskit.quantum_info.PhasedQubitSparsePauliList") behaves as [a Python sequence](https://docs.python.org/3/glossary.html#term-sequence) (the standard form, not the expanded [`collections.abc.Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)). The elements of the list can be indexed by integers, as well as iterated through. Whether through indexing or iterating, elements of the list are returned as [`PhasedQubitSparsePauli`](/docs/api/qiskit/qiskit.quantum_info.PhasedQubitSparsePauli "qiskit.quantum_info.PhasedQubitSparsePauli") instances.

## Construction

[`PhasedQubitSparsePauliList`](#qiskit.quantum_info.PhasedQubitSparsePauliList "qiskit.quantum_info.PhasedQubitSparsePauliList") defines several constructors. The default constructor will attempt to delegate to one of the more specific constructors, based on the type of the input. You can always use the specific constructors to have more control over the construction.

| Method                                                                                                                                                                                                  | Summary                                                                                                                                                                                                                                                  |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`from_label()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.from_label "qiskit.quantum_info.PhasedQubitSparsePauliList.from_label")                                                                | Convert a dense string label into a single-element [`PhasedQubitSparsePauliList`](#qiskit.quantum_info.PhasedQubitSparsePauliList "qiskit.quantum_info.PhasedQubitSparsePauliList").                                                                     |
| [`from_list()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.from_list "qiskit.quantum_info.PhasedQubitSparsePauliList.from_list")                                                                   | Construct from a list of dense string labels.                                                                                                                                                                                                            |
| [`from_sparse_list()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.from_sparse_list "qiskit.quantum_info.PhasedQubitSparsePauliList.from_sparse_list")                                              | Elements given as a list of tuples of the phase exponent, sparse string labels, and the qubits they apply to.                                                                                                                                            |
| [`from_pauli()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.from_pauli "qiskit.quantum_info.PhasedQubitSparsePauliList.from_pauli")                                                                | Raise a single [`Pauli`](/docs/api/qiskit/qiskit.quantum_info.Pauli "qiskit.quantum_info.Pauli") into a single-element [`PhasedQubitSparsePauliList`](#qiskit.quantum_info.PhasedQubitSparsePauliList "qiskit.quantum_info.PhasedQubitSparsePauliList"). |
| [`from_phased_qubit_sparse_paulis()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.from_phased_qubit_sparse_paulis "qiskit.quantum_info.PhasedQubitSparsePauliList.from_phased_qubit_sparse_paulis") | Construct from a list of [`PhasedQubitSparsePauli`](/docs/api/qiskit/qiskit.quantum_info.PhasedQubitSparsePauli "qiskit.quantum_info.PhasedQubitSparsePauli")s.                                                                                          |

### \_\_new\_\_

`__new__(data, /, num_qubits=None)`

The default constructor of [`PhasedQubitSparsePauliList`](#qiskit.quantum_info.PhasedQubitSparsePauliList "qiskit.quantum_info.PhasedQubitSparsePauliList").

This delegates to one of [the explicit conversion-constructor methods](#phased-qubit-sparse-pauli-list-convert-constructors), based on the type of the `data` argument. If `num_qubits` is supplied and constructor implied by the type of `data` does not accept a number, the given integer must match the input.

**Parameters**

- **data** – The data type of the input. This can be another [`PhasedQubitSparsePauliList`](#qiskit.quantum_info.PhasedQubitSparsePauliList "qiskit.quantum_info.PhasedQubitSparsePauliList"), in which case the input is copied, or it can be a list in a valid format for either [`from_list()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.from_list "qiskit.quantum_info.PhasedQubitSparsePauliList.from_list") or [`from_sparse_list()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.from_sparse_list "qiskit.quantum_info.PhasedQubitSparsePauliList.from_sparse_list").
- **num\_qubits** ([*int*](https://docs.python.org/3/library/functions.html#int)*|None*) – Optional number of qubits for the list. For most data inputs, this can be inferred and need not be passed. It is only necessary for empty lists or the sparse-list format. If given unnecessarily, it must match the data input.

In addition to the conversion-based constructors, the method [`empty()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.empty "qiskit.quantum_info.PhasedQubitSparsePauliList.empty") can be used to construct an empty list of phased qubit-sparse Paulis acting on a given number of qubits.

## Conversions

An existing [`PhasedQubitSparsePauliList`](#qiskit.quantum_info.PhasedQubitSparsePauliList "qiskit.quantum_info.PhasedQubitSparsePauliList") can be converted into other formats.

| Method                                                                                                                                               | Summary                                                                                  |
| ---------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| [`to_sparse_list()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.to_sparse_list "qiskit.quantum_info.PhasedQubitSparsePauliList.to_sparse_list") | Express the observable in a sparse list format with elements `(phase, paulis, indices)`. |

## Attributes

### num\_qubits

The number of qubits the operators in the list act on.

This is not inferable from any other shape or values, since identities are not stored explicitly.

### num\_terms

The number of elements in the list.

## Methods

### apply\_layout

`apply_layout(layout, num_qubits=None)`

Apply a transpiler layout to this phased qubit sparse Pauli list.

This enables remapping of qubit indices, e.g. if the list is defined in terms of virtual qubit labels.

**Parameters**

- **layout** ([*TranspileLayout*](/docs/api/qiskit/qiskit.transpiler.TranspileLayout "qiskit.transpiler.TranspileLayout")  *|*[*list*](https://docs.python.org/3/library/stdtypes.html#list)*\[*[*int*](https://docs.python.org/3/library/functions.html#int)*] | None*) – The layout to apply. Most uses of this function should pass the [`QuantumCircuit.layout`](/docs/api/qiskit/qiskit.circuit.QuantumCircuit#layout "qiskit.circuit.QuantumCircuit.layout") field from a circuit that was transpiled for hardware. In addition, you can pass a list of new qubit indices. If given as explicitly `None`, no remapping is applied (but you can still use `num_qubits` to expand the qubits in the list).
- **num\_qubits** ([*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The number of qubits to expand the list elements to. If not supplied, the output will be as wide as the given [`TranspileLayout`](/docs/api/qiskit/qiskit.transpiler.TranspileLayout "qiskit.transpiler.TranspileLayout"), or the same width as the input if the `layout` is given in another form.

**Returns**

A new [`QubitSparsePauli`](/docs/api/qiskit/qiskit.quantum_info.QubitSparsePauli "qiskit.quantum_info.QubitSparsePauli") with the provided layout applied.

### clear

`clear()`

Clear all the elements from the list, making it equal to the empty list again.

This does not change the capacity of the internal allocations, so subsequent addition or subtraction operations resulting from composition may not need to reallocate.

**Examples**

```python
>>> pauli_list = PhasedQubitSparsePauliList.from_list(["IXXXYY", "ZZYZII"])
>>> pauli_list.clear()
>>> assert pauli_list == PhasedQubitSparsePauliList.empty(pauli_list.num_qubits)
```

### copy

`copy()`

Get a copy of this qubit sparse Pauli list.

**Examples**

```python
>>> phased_qubit_sparse_pauli_list = PhasedQubitSparsePauliList.from_list(["IXZXYYZZ", "ZXIXYYZZ"])
>>> assert phased_qubit_sparse_pauli_list == phased_qubit_sparse_pauli_list.copy()
>>> assert phased_qubit_sparse_pauli_list is not phased_qubit_sparse_pauli_list.copy()
```

### empty

*static* `empty(num_qubits)`

Get the empty list for a given number of qubits.

The empty list contains no elements, and is the identity element for joining two [`PhasedQubitSparsePauliList`](#qiskit.quantum_info.PhasedQubitSparsePauliList "qiskit.quantum_info.PhasedQubitSparsePauliList") instances.

**Examples**

Get the empty list on 100 qubits:

```python
>>> PhasedQubitSparsePauliList.empty(100)
<PhasedQubitSparsePauliList with 0 elements on 100 qubits: []>
```

### from\_label

*static* `from_label(label, /)`

Construct a list with a single-term from a dense string label.

The label must be a sequence of the alphabet `'IXYZ'`. The label is interpreted analogously to a bitstring. In other words, the right-most letter is associated with qubit 0, and so on. This is the same as the labels for [`Pauli`](/docs/api/qiskit/qiskit.quantum_info.Pauli "qiskit.quantum_info.Pauli") and [`SparsePauliOp`](/docs/api/qiskit/qiskit.quantum_info.SparsePauliOp "qiskit.quantum_info.SparsePauliOp").

**Parameters**

**label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) – the dense label.

**Examples**

```python
>>> PhasedQubitSparsePauliList.from_label("IIIIXZI")
<PhasedQubitSparsePauliList with 1 element on 7 qubits: [X_2 Z_1]>
>>> label = "IYXZI"
>>> pauli = Pauli(label)
>>> assert PhasedQubitSparsePauliList.from_label(label) == PhasedQubitSparsePauliList.from_pauli(pauli)
```

> **See also**
>
> **[`from_list()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.from_list "qiskit.quantum_info.PhasedQubitSparsePauliList.from_list")**
>
> A generalization of this method that constructs a list from multiple labels.

### from\_list

*static* `from_list(iter, /, *, num_qubits=None)`

Construct a phased qubit-sparse Pauli list from a list of dense labels.

This is analogous to [`SparsePauliOp.from_list()`](/docs/api/qiskit/qiskit.quantum_info.SparsePauliOp#from_list "qiskit.quantum_info.SparsePauliOp.from_list"). In this dense form, you must supply all identities explicitly in each label.

The label must be a sequence of the alphabet `'IXYZ'`. The label is interpreted analogously to a bitstring. In other words, the right-most letter is associated with qubit 0, and so on. This is the same as the labels for [`Pauli`](/docs/api/qiskit/qiskit.quantum_info.Pauli "qiskit.quantum_info.Pauli") and [`SparsePauliOp`](/docs/api/qiskit/qiskit.quantum_info.SparsePauliOp "qiskit.quantum_info.SparsePauliOp").

**Parameters**

- **iter** ([*list*](https://docs.python.org/3/library/stdtypes.html#list)*\[*[*str*](https://docs.python.org/3/library/stdtypes.html#str)*]*) – List of dense string labels.
- **num\_qubits** ([*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – It is not necessary to specify this if you are sure that `iter` is not an empty sequence, since it can be inferred from the label lengths. If `iter` may be empty, you must specify this argument to disambiguate how many qubits the operators act on. If this is given and `iter` is not empty, the value must match the label lengths.

**Examples**

Construct a qubit sparse Pauli list from a list of labels:

```python
>>> PhasedQubitSparsePauliList.from_list([
...     "IIIXX",
...     "IIYYI",
...     "IXXII",
...     "ZZIII",
... ])
<PhasedQubitSparsePauliList with 4 elements on 5 qubits:
    [X_1 X_0, Y_2 Y_1, X_3 X_2, Z_4 Z_3]>
```

Use `num_qubits` to disambiguate potentially empty inputs:

```python
>>> PhasedQubitSparsePauliList.from_list([], num_qubits=10)
<PhasedQubitSparsePauliList with 0 elements on 10 qubits: []>
```

This method is equivalent to calls to [`from_sparse_list()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.from_sparse_list "qiskit.quantum_info.PhasedQubitSparsePauliList.from_sparse_list") with the explicit qubit-arguments field set to decreasing integers:

```python
>>> labels = ["XYXZ", "YYZZ", "XYXZ"]
>>> from_list = PhasedQubitSparsePauliList.from_list(labels)
>>> from_sparse_list = PhasedQubitSparsePauliList.from_sparse_list([
...     (label, (3, 2, 1, 0))
...     for label in labels
... ])
>>> assert from_list == from_sparse_list
```

> **See also**
>
> **[`from_sparse_list()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.from_sparse_list "qiskit.quantum_info.PhasedQubitSparsePauliList.from_sparse_list")**
>
> Construct the list from labels without explicit identities, but with the qubits each single-qubit operator term applies to listed explicitly.

### from\_pauli

*static* `from_pauli(pauli, /)`

Construct a [`PhasedQubitSparsePauliList`](#qiskit.quantum_info.PhasedQubitSparsePauliList "qiskit.quantum_info.PhasedQubitSparsePauliList") from a single [`Pauli`](/docs/api/qiskit/qiskit.quantum_info.Pauli "qiskit.quantum_info.Pauli") instance.

The output list will have a single term. Note that the phase is dropped.

**Parameters**

**pauli** ([`Pauli`](/docs/api/qiskit/qiskit.quantum_info.Pauli "qiskit.quantum_info.Pauli")) – the single Pauli to convert.

**Examples**

```python
>>> label = "IYXZI"
>>> pauli = Pauli(label)
>>> PhasedQubitSparsePauliList.from_pauli(pauli)
<PhasedQubitSparsePauliList with 1 element on 5 qubits: [Y_3 X_2 Z_1]>
>>> assert PhasedQubitSparsePauliList.from_label(label) == PhasedQubitSparsePauliList.from_pauli(pauli)
```

### from\_phased\_qubit\_sparse\_paulis

*static* `from_phased_qubit_sparse_paulis(obj, /, num_qubits=None)`

Construct a [`PhasedQubitSparsePauliList`](#qiskit.quantum_info.PhasedQubitSparsePauliList "qiskit.quantum_info.PhasedQubitSparsePauliList") out of individual [`PhasedQubitSparsePauli`](/docs/api/qiskit/qiskit.quantum_info.PhasedQubitSparsePauli "qiskit.quantum_info.PhasedQubitSparsePauli") instances.

All the terms must have the same number of qubits. If supplied, the `num_qubits` argument must match the terms.

**Parameters**

- **obj** (*Iterable\[*[*PhasedQubitSparsePauli*](/docs/api/qiskit/qiskit.quantum_info.PhasedQubitSparsePauli "qiskit.quantum_info.PhasedQubitSparsePauli")*]*) – Iterable of individual terms to build the list from.
- **num\_qubits** ([*int*](https://docs.python.org/3/library/functions.html#int) *| None*) – The number of qubits the elements of the list should act on. This is usually inferred from the input, but can be explicitly given to handle the case of an empty iterable.

**Returns**

The corresponding list.

### from\_sparse\_list

*static* `from_sparse_list(iter, /, num_qubits)`

Construct a phased qubit sparse Pauli list from a list of labels and the qubits each item applies to.

This is analogous to [`SparsePauliOp.from_sparse_list()`](/docs/api/qiskit/qiskit.quantum_info.SparsePauliOp#from_sparse_list "qiskit.quantum_info.SparsePauliOp.from_sparse_list").

The “labels” and “indices” fields of the tuples are associated by zipping them together. For example, this means that a call to [`from_list()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.from_list "qiskit.quantum_info.PhasedQubitSparsePauliList.from_list") can be converted to the form used by this method by setting the “indices” field of each triple to `(num_qubits-1, ..., 1, 0)`.

**Parameters**

- **iter** ([*list*](https://docs.python.org/3/library/stdtypes.html#list)*\[*[*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple)*\[*[*int*](https://docs.python.org/3/library/functions.html#int)*,* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*, Sequence\[*[*int*](https://docs.python.org/3/library/functions.html#int)*]]]*) – tuples of phase exponents, labels, and the qubits each single-qubit term applies to.
- **num\_qubits** ([*int*](https://docs.python.org/3/library/functions.html#int)) – the number of qubits the operators in the list act on.

**Examples**

Construct a simple list:

```python
>>> PhasedQubitSparsePauliList.from_sparse_list(
...     [(0, "ZX", (1, 4)), (1, "YY", (0, 3))],
...     num_qubits=5,
... )
<PhasedQubitSparsePauliList with 2 elements on 5 qubits: [X_4 Z_1, (-i)Y_3 Y_0]>
```

This method can replicate the behavior of [`from_list()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.from_list "qiskit.quantum_info.PhasedQubitSparsePauliList.from_list"), if the qubit-arguments field of the tuple is set to decreasing integers:

```python
>>> labels = ["XYXZ", "YYZZ", "XYXZ"]
>>> from_list = PhasedQubitSparsePauliList.from_list(labels)
>>> from_sparse_list = PhasedQubitSparsePauliList.from_sparse_list([
...     (label, (3, 2, 1, 0))
...     for label in labels
... ])
>>> assert from_list == from_sparse_list
```

> **See also**
>
> **[`to_sparse_list()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.to_sparse_list "qiskit.quantum_info.PhasedQubitSparsePauliList.to_sparse_list")**
>
> The reverse of this method.

### to\_pauli\_list

`to_pauli_list()`

Return a [`PauliList`](/docs/api/qiskit/qiskit.quantum_info.PauliList "qiskit.quantum_info.PauliList") representing the same list of Paulis.

### to\_sparse\_list

`to_sparse_list()`

Express the list in terms of a sparse list format.

This can be seen as counter-operation of [`PhasedQubitSparsePauliList.from_sparse_list()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.from_sparse_list "qiskit.quantum_info.PhasedQubitSparsePauliList.from_sparse_list"), however the order of terms is not guaranteed to be the same at after a roundtrip to a sparse list and back.

**Examples**

```python
>>> phased_qubit_sparse_list = PhasedQubitSparsePauliList.from_list(["IIXIZ", "IIZIX"])
>>> reconstructed = PhasedQubitSparsePauliList.from_sparse_list(phased_qubit_sparse_list.to_sparse_list(), qubit_sparse_list.num_qubits)
```

> **See also**
>
> **[`from_sparse_list()`](#qiskit.quantum_info.PhasedQubitSparsePauliList.from_sparse_list "qiskit.quantum_info.PhasedQubitSparsePauliList.from_sparse_list")**
>
> The constructor that can interpret these lists.
