PauliRep Class #62
dsvandet
started this conversation in
Project Notes
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
These notes are related to the PaulRep class for dealing with different string representations for Pauli Operators
TODO: A detailed requirement is required
Location of Code
Currently the class is located at dsvandet/qiskit-terra/tree/paulilist_representations.
TODO
The following needs to be done:
PauliRep Class
Note: This material was originally is the #6 Discussion but has been moved here as a stand alone discussion topic
PauliRep Class: Representations
The BasePauli class internally stores a list of Pauli operators a symplectic matrix plus a phase vector. The symplectic matrix is actually stored as two matrices: an$X$ and and $Z$ type matrix. If phases are not of interest then the symplectic representation is the same for a wide range of representations (see below) of Pauli operators. The only point that needs to be mentioned is that you need to know which is the $X$ and $Z$ parts. If phases are included, then how the symplectic representation and phase combine to create a Pauli changes.
The symplectic representation within the BasePauli, Pauli and PauliList classes is stored as a pair of boolean numpy arrays. This representation is good when these matrices are dense but quickly become inefficient once when the matrices are sparse - especially as the number of qubits grows.
TODO: Change PauliBase and associated classes (Pauli and PauliList) so that different storage methods are possible. One possible internal storage is alist format. At the very least we should be and to read in and give output in alist format.
Given the minimal generating set for the$n$ -qubit Paulis $\langle iI,X_1,X_2,\dots,X_n,Z_1,Z_2,\dots,Z_n \rangle$ any Pauli operator $P\in\mathcal{P}_n$ can be represented by a pair $(\phi{},S)$ where $\phi\in{1,-1,i,-i}$ is the phase and $S$ is the symplectic representation of the Pauli operator relative to the standard generating set.
Note You can also represent the symplectic matrix in terms of a different generating set. This is to be discussed in another thread.
There are several ways to represent a Pauli operator and some of these are given here. Without loss of generality we use the standard normalized generating set for$\mathcal{P}_n$ . In the following representations $\delta_j,\rho_j \in F_2$ for all $j$ .
XZ
ZX
XZY
YZX
The
XZY
andYZX
representations can be simplified to a single representationwhere$P_j \in {I,X,Z,Y}$ and then the difference only occurs when expanding the Y operators into $iXY$ or $-iZX$ . This happens internally since the $X$ and $Z$ components are stored.
Example: consider the Pauli operator$P=-iXZY = -i X\otimes Z \otimes Y$ . Below is how $P$ could be represented in the different formats above:
XZ
ZX
XZY
YZX
Issue: The string format for the$P=-iXZY$ could be interpreted as either $-i X\otimes Z\otimes Y$ or $-iX\otimes Z - Z\otimes X$ .
YZX
format could cause confusion if the parenthesis as not used as the string representation forIt is also sometimes useful to represent the phase$\phi$ is differently. The following are some examples:
i.
format-i
formatis
format-is
formatThe order of the qubits is also important when representing the different formats in an extended symplectic form. Internally Qiskit reads Pauli operator strings from left to right. That is if$P=-iXZY$ and qubits are labeled $0,1,2$ then the $Y$ component is acting on qubit $0$ , the $Z$ component is acting on qubit $1$ et cetera. You could also have the more natural ordering of right to left. Below gives the example below for these two options in symplectic representation - the $X$ and $Z$ components are show in $[X|Z]$ order:
XZ
ZX
XZY
YZX
Note that the symplectic representation (apart for qubit order differences) is the same throughout the different formats. This is also true when different phase formats are introduced.
A additional input parameter has been added to the Pauli class init method to allow users to input or output in different orders:
For example:
This parameter does not effect the internal right-to-left ordering, only how strings representations are output or input.
String Syntax
The are several possible syntaxes for Pauli's as strings. The standard syntax in Qiskit is the "product" syntax
which works well for small numbers of qubits both in entering and reading. As the number of qubits gets larger, but usually the support of the Pauli remains small, this syntax becomes difficult and error prone in input and reading. For example consider:
The more compact syntax of$M_i$ for the tensor with identity acting on all but the $i$ -th qubit and $M$ acting on the $i$ -th qubit is far better. Input of small weight/support Pauli's is much easier. This syntax is called indexed syntax. This syntax has now been added to the PauliRep class that the BasePauli, Pauli and PauliList classes inherit. It allows one to do the following:
This will produce a Pauli with
Pauli('YIXIIXI')
. The number of qubits is taken to be largest index+1. If you want say 10 qubits with only an X on the qubit 1 then you can do the followingwhich will give you
Pauli('IIIIIIIIXI')
. This will also work when build PauliListswhich will give you
PauliList(['IIIIIXXXXI', 'YIIYIIXIXI'])
. That is the number of qubits is increased to hold all of the provide Pauli operators.The$P_1n_1P_2n_2...P_kn_k$ where $P_i$ is one of $X,Z,Y$ or $I$ and $n_1,n_2,...,n_k$ are integers.
indexed
syntax is strings of the formImplementation
The internal representation for
BasePauli
,Pauli
andPauliList
should be fixed and in some sense private - in that user programs should not be effected if we change the internal representation at a later date. Different representations are useful and so this should be provided but maintain a common internal representation.A
PauliRep
class has been created to handle different input representations and conversions. ThePauliRep
class is then added as a base class for theBasePauli
class. The current implementation can handle several different representations. Currently the following definitions are used:__PHASE_REP_FORMATS__
formats ['i','-i','is','-is'])__SYMP_REP_FORMATS__
formats ['XZ','XZY', 'ZX', 'YZX'])Issue These name are not great. phase format is okay but symplectic format is not. When the$X$ and $Z$ parts of the symplectic representation are stored separately the symplectic representation is the same for all formats chosen. pauli format is okay. A better approach is therefore something like:
__PHASE_REP_FORMATS__
formats ['i','-i','is','-is'])__SYMP_REP_FORMATS__
formats ['XZ','XZY', 'ZX', 'YZX'])TODO: Implement these changes for better naming
The different formats are setup as class variables in the PauliRep class. They are:
That is the internal representation is
-iZX
. By default Pauli product strings representations are read inleft-to-right
ordering as mentioned above. The above variables cannot change this format, they are only there for reference. The default external format is-iYZX
format which is what BasePauli and other started with.The format used to read input strings and output strings is recorded in the following class variables
The possible formats/representations are stored in a few other class variables
An input Pauli string can be in either the product syntax or the indexed syntax. The syntax of a Pauli string can be determined by the
PauliRep._syntax_type()
method. Internally the__PRODUCT_SYNTAX__
and__INDEX_SYNTAX__
are integer class variables that help distinguish the different formats. That isPauliRep._syntax_type()
will return one of__PRODUCT_SYNTAX__
or__INDEX_SYNTAX__
or raise an error.Setting the Formats
The formats to use can be set with the
set_formats
method which calls the internal_set_formats
method. This style of indirect access is followed to allow internal methods to change while maintaining a standard and consistent external API. As much as possible format checking etc should take place in the external call method.The
set_formats
method has parametersphase_format
andsymp_format
wherephase_format (str)
:is the phase a format string from__PHASE_REP_FORMATS__
. with default set to-i
. Thesymp_format (str)
is a symplectic format string from__SYMP_REP_FORMATS__
with default set toYZX
. Calling with no parameters will reset to the default external representations.Examples: To set the external format to
isXZ
To reset the external formats to the default external format of
-iYZX
The external formats can also be set via the following methods:
Information on the current formats can be obtained via the following methods:
Translating between formats
The symplectic representation for all formats and syntaxes is the same where as the phase changes depending on which format is selected.
As seen from the description of the phase formats the actual phase is not stored but instead its phase exponent is stored which is either an element of$\mathbf{Z}_4$ or a tuple of $\mathbf{Z}_2$ elements.
There are various methods to convert between different formats:
converts between the different phase representations/encodings of the phase. This method handles vectors of exponents.
Example:
The conversions are done via precomputed matrices that describe how the various indices change when converting between different formats. Tuple formats are linearized to use single integer indices for lookup and are then expanded at the end if needed.
A representation is a combined phase and symplectic format. The following method allow one to change/translate between two different representations/formats:
Here the parameter y_count is a count of the number of Y operators within the Pauli operator. This can be found using the method
_count_y(array_1, array_2)
. As the symplectic representation does not change only the phase (exponent) is required together with the y_count of the symplectic array.Example: Consider the Pauli$P=(-i)^1(XZ\otimes{}X)$ and in $P=i^0(-1)^1(Y\otimes{}X)$ .
P=Pauli(-YX)
written in-iXZ
format converted toisYZX
format: In-iXZ
isYZX
formatThere are methods to convert between phase exponents and phases. These methods are:
These methods handle vectors of exponents/phases.
Beta Was this translation helpful? Give feedback.
All reactions