Pauli¶
- class Pauli(data=None, *, x=None, z=None, phase_exp=None, input_pauli_encoding='-iYZX', input_qubit_order='right-to-left', order='xz', tuple_order='zx', num_qubits=None)[source]¶
Bases:
BasePauli
N-qubit Pauli operator
Initialize the Pauli
Initialiazation of the N-qubit Pauli operator
- Parameters:
data (Union[str, tuple, List, np.ndarray, BasePauli, None]) – Input data.
x (Union[List, np.ndarray, None], optional) – X part. Defaults to None.
z (Union[List, np.ndarray, None], optional) – Z part. Defaults to None.
phase_exp (Union[str, np.ndarray, None], optional) – Phase expression of Pauli. Defaults to None.
input_pauli_encoding (str, optional) – What encoding is used for the input data. Defaults to BasePauli.EXTERNAL_PAULI_ENCODING.
input_qubit_order (str, optional) – Qubit read order. Defaults to “right-to-left”.
order (str, optional) – Order in which data lists X and Z. Defaults to ‘xz’.
tuple_order (str, optional) – Order in data for X and Z parts of tuples. Defaults to ‘zx’.
num_qubits (int, optional) – Number of qubits to use in Pauli. Defaults to None.
- Raises:
QiskitError – Something went wrong.
Examples
>>> Pauli('XYXXIZ') Pauli('XYXXIZ')
>>> Pauli('X1Y3Z12') Pauli('ZIIIIIIIIYIXI')
>>> Pauli('X', num_qubits=12) Pauli('IIIIIIIIIIIX')
>>> Pauli(np.array([[0,1,1,1]]), phase_exp="(-i,1)", num_qubits=10) Pauli('-iIIIIIIIIYZ')
>>> Pauli(np.array([[0,1,1,1]]),phase_exp="(-i,1)", num_qubits=10, order="zx") Pauli('-iIIIIIIIIYX')
>>> Pauli(None, x=[0,1],z=[1,1],phase_exp = '-i') Pauli('-iYZ')
>>> Pauli(np.array([[0,1,1,1]]), phase_exp="(-i,1)(-1,0)", num_qubits=10, order="zx", input_pauli_encoding='-isXZ') Pauli('-iIIIIIIIIYX')
>>> Pauli(([0,1],[1,1],'-i'), tuple_order='xz') Pauli('-iYZ')
>>> Pauli(([0,1],[1,1],'-i')) Pauli('-iYX')
Methods
- all_commutes(other)¶
_summary_
- Parameters:
other (BasePauli) – _description_
- Returns:
_description_
- Return type:
np.ndarray
- anticommutes(other, qargs=None)[source]¶
Return True if other Pauli anticommutes with self.
- Parameters:
other (Pauli) – another Pauli operator.
qargs (list) – qubits to apply dot product on (default: None).
- Returns:
True if Pauli’s anticommute, False if they commute.
- Return type:
bool
- append_paulis(paulis=None, pauli_labels=None)[source]¶
DEPRECATED: Append pauli at the end.
Deprecated since version unknown: append_paulis is deprecated and will be removed no earlier than 3 months after the release date. Use Pauli.expand instead.
- compose(other, qargs=None, front=False, inplace=False)[source]¶
Return the operator composition with another Pauli.
- Parameters:
other (Pauli) – a Pauli object.
qargs (list or None) – Optional, qubits to apply dot product on (default: None).
front (bool) – If True compose using right operator multiplication, instead of left multiplication [default: False].
inplace (bool) – If True update in-place (default: False).
- Returns:
The composed Pauli.
- Return type:
- Raises:
QiskitError – if other cannot be converted to an operator, or has incompatible dimensions for specified subsystems.
Note
Composition (
&
) by default is defined as left matrix multiplication for matrix operators, whiledot()
is defined as right matrix multiplication. That is thatA & B == A.compose(B)
is equivalent toB.dot(A)
whenA
andB
are of the same type.Setting the
front=True
kwarg changes this to right matrix multiplication and is equivalent to thedot()
methodA.dot(B) == A.compose(B, front=True)
.
- conjugate()[source]¶
Return the conjugate of each Pauli in the list.
- Parameters:
inplace (boolean) – If True will modify inplace. Default: False,
- Returns:
a new {cls} which has phases conjugates (if replace=False) or will change the phase of the clasing instance if replace=True
- Return type:
{cls}
- delete(qubits)[source]¶
Return a Pauli with qubits deleted.
- Parameters:
qubits (int or list) – qubits to delete from Pauli.
- Returns:
the resulting Pauli with the specified qubits removed.
- Return type:
- Raises:
QiskitError – if ind is out of bounds for the array size or number of qubits.
- delete_qubits(indices)[source]¶
DEPRECATED: Delete pauli at the indices.
This function is deprecated. Equivalent functionality can be obtained using the
delete()
method.Deprecated since version unknown: append_paulis is deprecated and will be removed no earlier than 3 months after the release date. For equivalent functionality use Pauli.delete instead.
- Parameters:
indices (list[int]) – the indices of to-be-deleted paulis
- Returns:
self
- Return type:
- equiv(other)[source]¶
Return True if Pauli’s are equivalent up to group phase.
- Parameters:
other (Pauli) – an operator object.
- Returns:
True if the Pauli’s are equivalent up to group phase.
- Return type:
bool
- evolve(other, qargs=None, frame='h')[source]¶
Heisenberg picture evolution of a Pauli by a Clifford.
This returns the Pauli \(P^\prime = C^\dagger.P.C\).
By choosing the parameter frame=’s’, this function returns the Schrödinger evolution of the Pauli \(P^\prime = C.P.C^\dagger\). This option yields a faster calculation.
- Parameters:
other (Pauli or Clifford or QuantumCircuit) – The Clifford operator to evolve by.
qargs (list) – a list of qubits to apply the Clifford to.
frame (string) – ‘h’ for Heisenberg or ‘s’ for Schrödinger framework.
- Returns:
the Pauli \(C^\dagger.P.C\).
- Return type:
- Raises:
QiskitError – if the Clifford number of qubits and qargs don’t match.
- static from_label(label)[source]¶
DEPRECATED: Construct a Pauli from a string label.
This function is deprecated use
Pauli(label)
instead.Deprecated since version unknown: from_label is deprecated and will be removed no earlier than 3 months after the release date. Use Pauli(label) instead.
- Parameters:
label (str) – Pauli string label.
- Returns:
the constructed Pauli.
- Return type:
- Raises:
QiskitError – If the input list is empty or contains invalid
Pauli strings. –
- input_dims(qargs=None)¶
Return tuple of input dimension for specified subsystems.
- insert_paulis(indices=None, paulis=None, pauli_labels=None)[source]¶
DEPRECATED: Insert or append pauli to the targeted indices.
This function is deprecated. Similar functionality can be obtained using the
insert()
method.If indices is None, it means append at the end.
Deprecated since version unknown: insert_paulis is deprecated and will be removed no earlier than 3 months after the release date. For similar functionality use Pauli.insert instead.
- Parameters:
indices (list[int]) – the qubit indices to be inserted
paulis (Pauli) – the to-be-inserted or appended pauli
pauli_labels (list[str]) – the to-be-inserted or appended pauli label
Note
the indices refers to the location of original paulis, e.g. if indices = [0, 2], pauli_labels = [‘Z’, ‘I’] and original pauli = ‘ZYXI’ the pauli will be updated to ZY’I’XI’Z’ ‘Z’ and ‘I’ are inserted before the qubit at 0 and 2.
- Returns:
self
- Return type:
- Raises:
QiskitError – provide both paulis and pauli_labels at the same time
- kron(other)[source]¶
DEPRECATED: Kronecker product of two paulis.
This function is deprecated. Use
expand()
instead.Order is $P_2 (other) otimes P_1 (self)$
Deprecated since version unknown: kron is deprecated and will be removed no earlier than 3 months after the release date of Qiskit Terra 0.17.0. Use expand instead, but note this does not change the operator in-place.
- output_dims(qargs=None)¶
Return tuple of output dimension for specified subsystems.
- classmethod pauli_single(num_qubits, index, pauli_label)[source]¶
DEPRECATED: Generate single qubit pauli at index with pauli_label with length num_qubits.
Deprecated since version unknown: pauli_single is deprecated and will be removed no earlier than 3 months after the release date.
- Parameters:
num_qubits (int) – the length of pauli
index (int) – the qubit index to insert the single qubit
pauli_label (str) – pauli
- Returns:
single qubit pauli
- Return type:
- power(n)¶
Return the compose of a operator with itself n times.
- Parameters:
n (int) – the number of times to compose with self (n>0).
- Returns:
the n-times composed operator.
- Return type:
Clifford
- Raises:
QiskitError – if the input and output dimensions of the operator are not equal, or the power is not a positive integer.
- classmethod random(num_qubits, seed=None)[source]¶
DEPRECATED: Return a random Pauli on number of qubits.
This function is deprecated use
random_pauli()
instead.Deprecated since version unknown: random is deprecated and will be removed no earlier than 3 months after the release date. Use qiskit.quantum_info.random_pauli instead
- Parameters:
num_qubits (int) – the number of qubits
seed (int) – Optional. To set a random seed.
- Returns:
the random pauli
- Return type:
- reshape(input_dims=None, output_dims=None, num_qubits=None)¶
Return a shallow copy with reshaped input and output subsystem dimensions.
- Parameters:
input_dims (None or tuple) – new subsystem input dimensions. If None the original input dims will be preserved [Default: None].
output_dims (None or tuple) – new subsystem output dimensions. If None the original output dims will be preserved [Default: None].
num_qubits (None or int) – reshape to an N-qubit operator [Default: None].
- Returns:
returns self with reshaped input and output dimensions.
- Return type:
BaseOperator
- Raises:
QiskitError – if combined size of all subsystem input dimension or subsystem output dimensions is not constant.
- classmethod set_pauli_encoding(encoding='-iYZX')¶
Set the Pauli encoding
- Parameters:
encoding (optional) – Pauli encoding.
pauli_rep.DEFAULT_EXTERNAL_PAULI_REP_FORMAT. (Defaults to)
- classmethod set_phase_encoding(encoding='-i')¶
Set the phase encoding
- Parameters:
encoding (optional) – phase encoding.
pauli_rep.DEFAULT_EXTERNAL_PHASE_ENCODING. (Defaults to)
- classmethod set_print_phase_encoding(phase_encoding=None)¶
_summary_
- Parameters:
phase_encoding (Optional[str], optional) – _description_. Defaults to None.
- Raises:
QiskitError – _description_
- classmethod set_qubit_order(qubit_order=None)¶
Set external qubit order
- Parameters:
qubit_order (Optional[str], optional) – _description_. Defaults to None.
- Raises:
QiskitError – _description_
- classmethod set_syntax(syntax_code=None, syntax_str='Product')¶
Sets the global input and output format
- Parameters:
syntax_code (Optional[int], optional) – sets the syntax of Pauli tensors. Possible inputs are 0 for product syntax, 1 for index syntax and 2 for latex syntax. Defaults to None.
syntax_str (Optional[str], optional) – sets the syntax of Pauli tensors. Possible inputs are Product or Latex, if another input is given the syntax is set to Order. Defaults to “Product”.
- Raises:
QiskitError – Unknown syntax: {syntax_code}. See pauli_rep for options.
- classmethod set_tensor_encoding(encoding='YZX')¶
Set the external symplectic matrix format
- Parameters:
encoding (optional) – Symplectic matrix tensor encoding.
pauli_rep.DEFAULT_EXTERNAL_TENSOR_ENCODING. (Defaults to)
- classmethod set_truncation(val)[source]¶
Set the max number of Pauli characters to display before truncation/
- Parameters:
val (int) – the number of characters.
Note
Truncation will be disabled if the truncation value is set to 0.
- static sgn_prod(p1, p2)[source]¶
DEPRECATED: Multiply two Paulis and track the phase.
This function is deprecated. The Pauli class now handles full Pauli group multiplication using
compose()
ordot()
.$P_3 = P_1 otimes P_2$: X*Y
Deprecated since version unknown: sgn_prod is deprecated and will be removed no earlier than 3 months after the release date. Use dot instead.
- tensor(other)[source]¶
Return the tensor product with another Pauli.
- Parameters:
other (Pauli) – a Pauli object.
- Returns:
- the tensor product \(a \otimes b\), where \(a\)
is the current Pauli, and \(b\) is the other Pauli.
- Return type:
Note
The tensor product can be obtained using the
^
binary operator. Hencea.tensor(b)
is equivalent toa ^ b
.
- to_cpx_matrix(sparse=False)[source]¶
_summary_
- Parameters:
sparse (bool, optional) – _description_. Defaults to False.
- Returns:
_description_
- Return type:
np.ndarray
- to_label(output_pauli_encoding=None, no_phase=False, return_phase=False, syntax=None, qubit_order=None, index_start=0, squeeze=True, index_str='')¶
Returns the string representatiojn for a Pauli or Paulis.
- Parameters:
output_pauli_encoding (optional) – Encoding used to represent phases. A value of None will result in complex phases notation. Defaults to None which will in turn use BasePauli.EXTERNAL_PAULI_ENCODING.
no_phase (optional) – When set to True, no phase will appear no matter what encoding is selected. So the symplectic matrix [1, 1] will produce the operator Y in ‘XZY’ encoding but also (XZ) in the ‘XZ’ encoding which are different operators if phases are considered. Defaults to False.
return_phase (optional) – If True return the adjusted phase for the coefficient of the returned Pauli label. This can be used even if
full_group=False
.syntax (optional) – Syntax of pauli tensor. Values are PRODUCT_SYNTAX = 0 and INDEX_SYNTAX=1. Defaults to INDEX_SYNTAX.
qubit_order (optional) – Order in which qubits are read. options aree “right-to-left” and “left-to-right”. Defaults to “right-to-left”.
index_start (optional) – Lowest value for index in index syntax tensors. Defaults to 0
squeeze (optional) – Squeezes the list of reults to a scalar if the number of Paulis is one. Defaults to True.
index_str (optional) – String that get inserted between operator and numbers in index format. Default is “”.
- Returns:
- the Pauli label(string) from the full Pauli group (if
no_phase=False
) or from the unsigned Pauli group (if
no_phase=True
).- Tuple[str or List[str], Any or List[Any]]: if
return_phase=True
returns a tuple of the Pauli label (from either the full or unsigned Pauli group) and the phase
q
for the coefficient \((-i)^(q + x.z)\) for the label from the full Pauli group.
- the Pauli label(string) from the full Pauli group (if
- Return type:
str
- to_matrix(sparse=False)[source]¶
_summary_
- Parameters:
sparse (bool, optional) – _description_. Defaults to False.
- Returns:
_description_
- Return type:
np.ndarray
- to_spmatrix()[source]¶
DEPRECATED Convert Pauli to a sparse matrix representation (CSR format).
This function is deprecated. Use
to_matrix()
with kwargsparse=True
instead.Deprecated since version unknown: to_spmatrix is deprecated and will be removed no earlier than 3 months after the release date. Use to_matrix(sparse=True) instead.
- Returns:
a sparse matrix with CSR format that represents the pauli.
- Return type:
scipy.sparse.csr_matrix
- update_x(x, indices=None)[source]¶
DEPRECATED: Update partial or entire x.
This function is deprecated. Use the setter for
x
instead.Deprecated since version unknown: update_z is deprecated and will be removed no earlier than 3 months after the release date. Use Pauli.x = val or Pauli.x[indices] = val instead.
- Parameters:
x (numpy.ndarray or list) – to-be-updated x
indices (numpy.ndarray or list or optional) – to-be-updated qubit indices
- Returns:
self
- Return type:
- Raises:
QiskitError – when updating whole x, the number of qubits must be the same.
- update_z(z, indices=None)[source]¶
DEPRECATED: Update partial or entire z.
This function is deprecated. Use the setter for
z
instead.Deprecated since version unknown: update_z is deprecated and will be removed no earlier than 3 months after the release date. Use Pauli.z = val or Pauli.z[indices] = val instead.
- Parameters:
z (numpy.ndarray or list) – to-be-updated z
indices (numpy.ndarray or list or optional) – to-be-updated qubit indices
- Returns:
self
- Return type:
- Raises:
QiskitError – when updating whole z, the number of qubits must be the same.
Attributes
- EXTERNAL_PAULI_ENCODING = '-iYZX'¶
- EXTERNAL_PHASE_ENCODING = '-i'¶
- EXTERNAL_QUBIT_ORDER = 'right-to-left'¶
- EXTERNAL_SYNTAX = 0¶
- EXTERNAL_TENSOR_ENCODING = 'YZX'¶
- PRINT_PHASE_ENCODING = None¶
- dim¶
Return tuple (input_shape, output_shape).
- name¶
Unique string identifier for operation type.
- num_clbits¶
Number of classical bits.
- num_qubits¶
Return the number of qubits if a N-qubit operator or None otherwise.
- num_y¶
Return the number of Y for each operator
- pauli_encoding¶
Pauli format.
- phase¶
Return the complex phase of the Pauli
- phase_encoding¶
Return the phase encoding
- phase_exp¶
Return the group phase exponent for the Pauli.
- pltb_int = {(0, 0): 0, (0, 1): 2, (1, 0): 1, (1, 1): 3}¶
- pltb_str = {(0, 0): 'I', (0, 1): 'Z', (1, 0): 'X', (1, 1): 'Y'}¶
- print_phase_encoding¶
Prints how the phase will be displayed in when printing.
- qargs¶
Return the qargs for the operator.
- qubit_order¶
Get external qubit order
- settings¶
Return settings.
- syntax¶
Returns the syntax
- tensor_encoding¶
Return the external symplectic matrix encoding
- x¶
The x vector for the Pauli.
- z¶
The z vector for the Pauli.