BasePauli¶
- class BasePauli(matrix=None, phase_exp=None, order='xz')[source]¶
Bases:
BaseOperator
,AdjointMixin
,MultiplyMixin
Base class for Pauli and PauliList.
Symplectic representation of a list of N-qubit Paulis with phases using numpy arrays for symplectic matrices and phase vectors.
Init method for BasePauli
A BasePauli object represents a list N-qubit Pauli operators with phases. Numpy arrays are used to represent the symplectic matrix represention of these Paulis. The phases of the Paulis are stored encoded. The phases of the Pauli operators are internally encoded in the ‘-iZX’ Pauli encoding (See the pauli_rep module for more details). That is a Pauli operator is represented as symplectic vector V and a phase exponent phase_exp such that:
(-i)^phase_exp Z^z X^x
where V = [x, z] and phase_exp is a vector of Z_4 elements (0,1,2,3). A list of Pauli operators is represented as a symplectic matrix S and a phase exponent vector phase_exp such that the rows or S are the symplectic vector representations of the Paulis and the phase_exp vector store the phase exponent of each associated Pauli Operator.
- Parameters:
matrix (
Optional
[ndarray
]) – Input GF(2) symplectic matrixphase_exp (optional) – Phase exponent vector for imput matrix. A value of None will result in an a complex coefficients of 1 for each Pauli operator. Defaults to None.
order (
str
) – Set to ‘xz’ or ‘zx’. Defines which side the x and z parts of the input matrix
Raises: QiskitError: matrix and phase_exp sizes are not compatible
Examples
>>> matrix = numpy.array([[1,1,0,0],[0,1,0,1]]) >>> base_pauli = BasePauli(matrix)
See also
Pauli, PauliList
Methods
- adjoint()¶
Return the adjoint of the Operator.
- Return type:
Self
- all_commutes(other)[source]¶
_summary_
- Parameters:
other (BasePauli) – _description_
- Returns:
_description_
- Return type:
np.ndarray
- commutes(other, qargs=None)[source]¶
Return True if Pauli that commutes with other.
- Parameters:
other (PaulisBase) – another PaulisBase operator.
qargs (list) – qubits to apply dot product on (default: None).
- Returns:
- Boolean array of True if Pauli’s commute, False if
they anti-commute.
- Return type:
np.array
- Raises:
QiskitError – if number of qubits of other does not match qargs.
- compose(other, qargs=None, front=False, inplace=False)[source]¶
Return the composition of Paulis lists
To be consistent with other compose functions in Qiskit, composition is defined via left multiplication. That is
A.compose(B) = B.A = B.dot(A) = A.compose(B, front=False)
where . is the Pauli group multiplication and so B is applied after A. Likewise
A.compose(B, front=True) = A.B = A.dot(B)
That is B is applied first or at the front.
This compose is:
[A_1,A_2,…,A_k].compose([B_1,B_2,…,B_k]) = [A_1.compose(B_1),…,A_k.compose(B_k)]
or
[A].compose([B_1,B_2,…,B_k])) = [A.compose(B_1),…,A.compose(B_k)]
Note
This method does compose coordinate wise (which is different from the PauliTable compose which should be corrected at some point).
- Parameters:
other (
BasePauli
) – BasePaulifront (bool) – (default: False)
qargs (list or None) – Optional, qubits to apply compose on on (default: None->All).
inplace (bool) – If True update in-place (default: False).
- Returns:
Compositon of self and other
- Return type:
- Raises:
QiskitError – if number of qubits of other does not match qargs.
- conjugate(inplace=False)[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}
- dot(other, qargs=None)¶
Return the right multiplied operator self * other.
- Parameters:
other (Operator) – an operator object.
qargs (list or None) – Optional, a list of subsystem positions to apply other on. If None apply on all subsystems (default: None).
- Returns:
The right matrix multiplied Operator.
- Return type:
Operator
Note
The dot product can be obtained using the
@
binary operator. Hencea.dot(b)
is equivalent toa @ b
.
- 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 (BasePauli or QuantumCircuit) – The Clifford circuit 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.
- expand(other)[source]¶
Return the reverse-order tensor product with another CLASS.
- Parameters:
other (CLASS) – a CLASS object.
- Returns:
- the tensor product \(b \otimes a\), where \(a\)
is the current CLASS, and \(b\) is the other CLASS.
- Return type:
CLASS
- input_dims(qargs=None)¶
Return tuple of input dimension for specified subsystems.
- output_dims(qargs=None)¶
Return tuple of output dimension for specified subsystems.
- 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.
- 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')[source]¶
Set the Pauli encoding
- Parameters:
encoding (optional) – Pauli encoding.
pauli_rep.DEFAULT_EXTERNAL_PAULI_REP_FORMAT. (Defaults to)
- classmethod set_phase_encoding(encoding='-i')[source]¶
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)[source]¶
_summary_
- Parameters:
phase_encoding (Optional[str], optional) – _description_. Defaults to None.
- Raises:
QiskitError – _description_
- classmethod set_qubit_order(qubit_order=None)[source]¶
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')[source]¶
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')[source]¶
Set the external symplectic matrix format
- Parameters:
encoding (optional) – Symplectic matrix tensor encoding.
pauli_rep.DEFAULT_EXTERNAL_TENSOR_ENCODING. (Defaults to)
- tensor(other)[source]¶
Return the tensor product with another CLASS.
- Parameters:
other (CLASS) – a CLASS object.
- Returns:
- the tensor product \(a \otimes b\), where \(a\)
is the current CLASS, and \(b\) is the other CLASS.
- Return type:
CLASS
Note
The tensor product can be obtained using the
^
binary operator. Hencea.tensor(b)
is equivalent toa ^ b
.
- to_label(output_pauli_encoding=None, no_phase=False, return_phase=False, syntax=None, qubit_order=None, index_start=0, squeeze=True, index_str='')[source]¶
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
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).
- 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_encoding¶
Return the phase encoding
- 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
- syntax¶
Returns the syntax
- tensor_encoding¶
Return the external symplectic matrix encoding
- x¶
Returns the X part of symplectic representation as a 2d matrix.
Note: The Pauli class over writes this method to return a 1d array instead of a 2d array. Use the self._x method if a 2d array is needed as _x method is markeded as @final
Examples
>>> matrix = numpy.array([[1,0,0,0],[0,1,1,1]], dtype=numpy.bool_) >>> phase_exp = numpy.array([0,1]) >>> base_pauli = BasePauli(matrix, phase_exp) >>> base_pauli.x.astype(int) array([[1, 0], [0, 1]])
See also
_x, z, _z
- z¶
The z array for the symplectic representation.