PhasedQubitSparsePauli
class qiskit.quantum_info.PhasedQubitSparsePauli
Bases: object
A Pauli operator stored in a qubit-sparse format.
Representation
A Pauli operator is a tensor product of single-qubit Pauli operators of the form , for and an integer called the phase exponent. The internal representation of a PhasedQubitSparsePauli
stores only the non-identity single-qubit Pauli operators.
Internally, each single-qubit Pauli operator is stored with a numeric value. See the documentation of QubitSparsePauli
for a description of the formatting of the numeric value associated with each Pauli, as well as descriptions of the paulis
and indices
attributes that store each Pauli and its associated qubit index.
Additionally, the phase of the operator can be retrieved through the phase
attribute, which returns the group phase exponent, matching the behaviour of the same attribute in Pauli
.
Construction
PhasedQubitSparsePauli
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() | Convert a dense string label into a PhasedQubitSparsePauli . |
from_sparse_label() | Build a PhasedQubitSparsePauli from a tuple of a phase, a sparse string label, and the qubits they apply to. |
from_pauli() | Raise a single Pauli into a PhasedQubitSparsePauli . |
from_raw_parts() | Build the list from the raw data arrays and the phase. |
__new__
__new__(data, /, num_qubits=None)
The default constructor of QubitSparsePauli
.
This delegates to one of the explicit conversion-constructor methods, 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
QubitSparsePauli
, in which case the input is copied, or it can be a valid format for eitherfrom_label()
orfrom_sparse_label()
. - num_qubits (int|None) – Optional number of qubits for the operator. For most data inputs, this can be inferred and need not be passed. It is only necessary for the sparse-label format. If given unnecessarily, it must match the data input.
Attributes
indices
Read-only view onto the indices of each non-identity single-qubit term.
The indices will always be in sorted order.
num_qubits
The number of qubits the term is defined on.
paulis
Read-only view onto the individual single-qubit terms.
The only valid values in the array are those with a corresponding Pauli
.
phase
Read-only view onto the phase.
Methods
commutes
commutes(other)
Check if self` commutes with another phased qubit sparse pauli.
Parameters
other (PhasedQubitSparsePauli) – the phased qubit sparse Pauli to check for commutation with.
compose
compose(other)
Composition with another PhasedQubitSparsePauli
.
Parameters
other (PhasedQubitSparsePauli) – the qubit sparse Pauli to compose with.
copy
copy()
Get a copy of this term.
from_label
static from_label(label, /)
Construct 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
and SparsePauliOp
.
Parameters
label (str) – the dense label.
Examples
>>> QubitSparsePauli.from_label("IIIIXZI")
<QubitSparsePauli on 7 qubits: X_2 Z_1>
>>> label = "IYXZI"
>>> pauli = Pauli(label)
>>> assert QubitSparsePauli.from_label(label) == QubitSparsePauli.from_pauli(pauli)
from_pauli
static from_pauli(pauli, /)
Construct a PhasedQubitSparsePauli
from a single Pauli
instance.
Parameters
pauli (Pauli
) – the single Pauli to convert.
Examples
>>> label = "iIYXZI"
>>> pauli = Pauli(label)
>>> PhasedQubitSparsePauli.from_pauli(pauli)
<PhasedQubitSparsePauli on 5 qubits: iY_3 X_2 Z_1>
>>> assert PhasedQubitSparsePauli.from_label(label) == PhasedQubitSparsePauli.from_pauli(pauli)
from_raw_parts
static from_raw_parts(num_qubits, paulis, indices, phase=0)
Construct a PhasedQubitSparsePauli
from raw Numpy arrays that match the required data representation described in the class-level documentation.
The data from each array is copied into fresh, growable Rust-space allocations.
Parameters
- num_qubits – number of qubits the operator acts on.
- paulis – list of the single-qubit terms. This should be a Numpy array with dtype
uint8
(which is compatible withPauli
). - indices – sorted list of the qubits each single-qubit term corresponds to. This should be a Numpy array with dtype
uint32
. - phase – The phase exponent of the operator.
Examples
Construct a operator acting on qubit 50 of 100 qubits.
>>> num_qubits = 100
>>> terms = np.array([PhasedQubitSparsePauli.Pauli.Z], dtype=np.uint8)
>>> indices = np.array([50], dtype=np.uint32)
>>> phase = 0
>>> PhasedQubitSparsePauli.from_raw_parts(num_qubits, terms, indices, phase)
<PhasedQubitSparsePauli on 100 qubits: Z_50>
from_sparse_label
static from_sparse_label(sparse_label, num_qubits)
Construct a phased qubit sparse Pauli from a sparse label, given as a tuple of an int for the phase exponent, a string of Paulis, and the indices of the corresponding qubits.
This is analogous to SparsePauliOp.from_sparse_list()
.
Parameters
- sparse_label (tuple[int, str, Sequence[int]]) – labels and the qubits each single-qubit term applies to.
- num_qubits (int) – the number of qubits the operator acts on.
Examples
Construct a simple Pauli:
>>> PhasedQubitSparsePauli.from_sparse_label(
... (0, "ZX", (1, 4)),
... num_qubits=5,
... )
<PhasedQubitSparsePauli on 5 qubits: X_4 Z_1>
This method can replicate the behavior of from_label()
, if the qubit-arguments field of the tuple is set to decreasing integers:
>>> label = "XYXZ"
>>> from_label = PhasedQubitSparsePauli.from_label(label)
>>> from_sparse_label = PhasedQubitSparsePauli.from_sparse_label(
... (0, label, (3, 2, 1, 0)),
... num_qubits=4
... )
>>> assert from_label == from_sparse_label
identity
static identity(num_qubits)
Get the identity operator for a given number of qubits.
Examples
Get the identity on 100 qubits:
>>> QubitSparsePauli.identity(100)
<QubitSparsePauli on 100 qubits: >
to_pauli
to_pauli()
Return a Pauli
representing the same Pauli.
to_phased_qubit_sparse_pauli_list
to_phased_qubit_sparse_pauli_list()
Convert this Pauli into a single element PhasedQubitSparsePauliList
.