qiskit.opflow.converters.PauliBasisChange¶

class
PauliBasisChange
(destination_basis=None, traverse=True, replacement_fn=None)[Quellcode]¶ Converter for changing Paulis into other bases. By default, the diagonal basis composed only of Pauli {Z, I}^n is used as the destination basis to which to convert. Meaning, if a Pauli containing X or Y terms is passed in, which cannot be sampled or evolved natively on some Quantum hardware, the Pauli can be replaced by a composition of a change of basis circuit and a Pauli composed of only Z and I terms (diagonal), which can be evolved or sampled natively on the Quantum hardware.
The replacement function determines how the
PauliOps
should be replaced by their computed changeofbasisCircuitOps
and destinationPauliOps
. Several convenient outofthebox replacement functions have been added as static methods, such asmeasurement_replacement_fn
.This class uses the typical basis change method found in most Quantum Computing textbooks (such as on page 210 of Nielsen and Chuang’s, „Quantum Computation and Quantum Information“, ISBN: 9781107002173), which involves diagonalizing the singlequbit Paulis with H and S† gates, mapping the eigenvectors of the diagonalized origin Pauli to the diagonalized destination Pauli using CNOTS, and then dediagonalizing any single qubit Paulis to their nondiagonal destination values. Many other methods are possible, as well as variations on this method, such as the placement of the CNOT chains.
 Parameter
destination_basis (
Union
[Pauli
,PauliOp
,None
]) – The Pauli into the basis of which the operators will be converted. If None is specified, the destination basis will be the diagonal ({I, Z}^n) basis requiring only single qubit rotations.traverse (
bool
) – If true and the operator passed into convert contains subOperators, such as ListOp, traverse the Operator and apply the conversion to every applicable suboperator within it.replacement_fn (
Optional
[Callable
]) –A function specifying what to do with the basischange
CircuitOp
and destinationPauliOp
when converting an Operator and replacing converted values. By default, this will beFor StateFns (or Measurements): replacing the StateFn with ComposedOp(StateFn(d), c) where c is the conversion circuit and d is the destination Pauli, so the overall beginning and ending operators are equivalent.
For nonStateFn Operators: replacing the origin p with c·d·c†, where c is the conversion circuit and d is the destination, so the overall beginning and ending operators are equivalent.

__init__
(destination_basis=None, traverse=True, replacement_fn=None)[Quellcode]¶  Parameter
destination_basis (
Union
[Pauli
,PauliOp
,None
]) – The Pauli into the basis of which the operators will be converted. If None is specified, the destination basis will be the diagonal ({I, Z}^n) basis requiring only single qubit rotations.traverse (
bool
) – If true and the operator passed into convert contains subOperators, such as ListOp, traverse the Operator and apply the conversion to every applicable suboperator within it.replacement_fn (
Optional
[Callable
]) –A function specifying what to do with the basischange
CircuitOp
and destinationPauliOp
when converting an Operator and replacing converted values. By default, this will beFor StateFns (or Measurements): replacing the StateFn with ComposedOp(StateFn(d), c) where c is the conversion circuit and d is the destination Pauli, so the overall beginning and ending operators are equivalent.
For nonStateFn Operators: replacing the origin p with c·d·c†, where c is the conversion circuit and d is the destination, so the overall beginning and ending operators are equivalent.
Methods
__init__
([destination_basis, traverse, …]) type destination_basis
Union
[Pauli
,PauliOp
,None
]
construct_cnot_chain
(diag_pauli_op1, …)Construct a
CircuitOp
(orPauliOp
if equal to the identity) which takes the eigenvectors ofdiag_pauli_op1
to the eigenvectors ofdiag_pauli_op2
, assuming both are diagonal (or performing this operation on their diagonalized Paulis implicitly if not).convert
(operator)Given a
PauliOp
, or an Operator containingPauliOps
if_traverse
is True, converts each Pauli into the basis specified by self._destination and a basischangecircuit, callsreplacement_fn
with these two Operators, and replaces thePauliOps
with the output ofreplacement_fn
.get_cob_circuit
(origin)Construct an Operator which maps the +1 and 1 eigenvectors of the origin Pauli to the +1 and 1 eigenvectors of the destination Pauli.
get_diagonal_pauli_op
(pauli_op)Get the diagonal
PualiOp
to whichpauli_op
could be rotated with only singlequbit operations.get_diagonalizing_clifford
(pauli)Construct a
CircuitOp
with only singlequbit gates which takes the eigenvectors ofpauli
to eigenvectors composed only of 0⟩ and 1⟩ tensor products.get_tpb_pauli
(list_op)Gets the Pauli (not
PauliOp
!) whose diagonalizing singlequbit rotations is a superset of the diagonalizing singlequbit rotations for each of the Paulis inlist_op
.measurement_replacement_fn
(cob_instr_op, …)A builtin convenience replacement function which produces measurements isomorphic to an
OperatorStateFn
measurement holding the originPauliOp
.operator_replacement_fn
(cob_instr_op, …)A builtin convenience replacement function which produces Operators isomorphic to the origin
PauliOp
.pad_paulis_to_equal_length
(pauli_op1, pauli_op2)If
pauli_op1
andpauli_op2
do not act over the same number of qubits, pad identities to the end of the shorter of the two so they are of equal length.statefn_replacement_fn
(cob_instr_op, …)A builtin convenience replacement function which produces state functions isomorphic to an
OperatorStateFn
state function holding the originPauliOp
.Attributes
The destination
PauliOp
, orNone
if using the default destination, the diagonal basis.
construct_cnot_chain
(diag_pauli_op1, diag_pauli_op2)[Quellcode]¶ Construct a
CircuitOp
(orPauliOp
if equal to the identity) which takes the eigenvectors ofdiag_pauli_op1
to the eigenvectors ofdiag_pauli_op2
, assuming both are diagonal (or performing this operation on their diagonalized Paulis implicitly if not). This works by the insight that the eigenvalue of a diagonal Pauli’s eigenvector is equal to or 1 if the parity is 1 and 1 if the parity is 0, or 1  (2 * parity). Therefore, using CNOTs, we can write the parity of diag_pauli_op1’s significant bits onto some qubit, and then write out that parity onto diag_pauli_op2’s significant bits. Parameter
diag_pauli_op1 (
PauliOp
) – The originPauliOp
.diag_pauli_op2 (
PauliOp
) – The destinationPauliOp
.
 Rückgabetyp
PrimitiveOp
 Rückgabe
The
PrimitiveOp
performs the mapping.

convert
(operator)[Quellcode]¶ Given a
PauliOp
, or an Operator containingPauliOps
if_traverse
is True, converts each Pauli into the basis specified by self._destination and a basischangecircuit, callsreplacement_fn
with these two Operators, and replaces thePauliOps
with the output ofreplacement_fn
. For example, for the builtinoperator_replacement_fn
below, each PauliOp p will be replaced by the composition of the basischange CliffordCircuitOp
c with the destination PauliOp d and c†, such that p = c·d·c†, up to global phase. Parameter
operator (
OperatorBase
) – The Operator to convert. Rückgabetyp
OperatorBase
 Rückgabe
The converted Operator.

property
destination
¶ The destination
PauliOp
, orNone
if using the default destination, the diagonal basis. Rückgabetyp
Optional
[PauliOp
]

get_cob_circuit
(origin)[Quellcode]¶ Construct an Operator which maps the +1 and 1 eigenvectors of the origin Pauli to the +1 and 1 eigenvectors of the destination Pauli. It does so by
converting any i+⟩ or i+⟩ eigenvector bits in the origin to +⟩ and ⟩ with S†s, then
converting any +⟩ or +⟩ eigenvector bits in the converted origin to 0⟩ and 1⟩ with Hs, then
writing the parity of the significant (Zmeasured, rather than I) bits in the origin to a single „origin anchor bit,“ using cnots, which will hold the parity of these bits,
swapping the parity of the pauli anchor bit into a destination anchor bit using a swap gate (only if they are different, if there are any bits which are significant in both origin and dest, we set both anchors to one of these bits to avoid a swap).
writing the parity of the destination anchor bit into the other significant bits of the destination,
converting the 0⟩ and 1⟩ significant eigenvector bits to +⟩ and ⟩ eigenvector bits in the destination where the destination demands it (e.g. pauli.x == true for a bit), using Hs 8) converting the +⟩ and ⟩ significant eigenvector bits to i+⟩ and i⟩ eigenvector bits in the destination where the destination demands it (e.g. pauli.x == true and pauli.z == true for a bit), using Ss
 Parameter
origin (
Union
[Pauli
,PauliOp
]) – ThePauli
orPauliOp
to map. Rückgabetyp
Tuple
[PrimitiveOp
,PauliOp
] Rückgabe
A tuple of a
PrimitiveOp
which equals the basis change mapping and aPauliOp
which equals the destination basis. Verursacht
TypeError – Attempting to convert from nonPauli origin.
ValueError – Attempting to change a nonidentity Pauli to an identity Pauli, or vice versa.

get_diagonal_pauli_op
(pauli_op)[Quellcode]¶ Get the diagonal
PualiOp
to whichpauli_op
could be rotated with only singlequbit operations. Parameter
pauli_op (
PauliOp
) – ThePauliOp
whose diagonal to compute. Rückgabetyp
PauliOp
 Rückgabe
The diagonal
PauliOp
.

get_diagonalizing_clifford
(pauli)[Quellcode]¶ Construct a
CircuitOp
with only singlequbit gates which takes the eigenvectors ofpauli
to eigenvectors composed only of 0⟩ and 1⟩ tensor products. Equivalently, finds the basischange circuit to takepauli
to a diagonalPauliOp
composed only of Z and I tensor products.Note, underlying Pauli bits are in Qiskit endianness, so we need to reverse before we begin composing with Operator flow.
 Parameter
pauli (
Union
[Pauli
,PauliOp
]) – thePauli
orPauliOp
to whose diagonalizing circuit to compute. Rückgabetyp
OperatorBase
 Rückgabe
The diagonalizing
CircuitOp
.

get_tpb_pauli
(list_op)[Quellcode]¶ Gets the Pauli (not
PauliOp
!) whose diagonalizing singlequbit rotations is a superset of the diagonalizing singlequbit rotations for each of the Paulis inlist_op
. TPB stands for Tensor Product Basis. Parameter
list_op (
ListOp
) – theListOp
whose TPB Pauli to return. Rückgabetyp
Pauli
 Rückgabe
The TBP Pauli.

static
measurement_replacement_fn
(cob_instr_op, dest_pauli_op)[Quellcode]¶ A builtin convenience replacement function which produces measurements isomorphic to an
OperatorStateFn
measurement holding the originPauliOp
. Parameter
cob_instr_op (
PrimitiveOp
) – The basischangeCircuitOp
.dest_pauli_op (
Union
[PauliOp
,PauliSumOp
,ListOp
]) – The destination Pauli type operator.
 Rückgabetyp
OperatorBase
 Rückgabe
The
~StateFn @ CircuitOp
composition equivalent to a measurement by the originalPauliOp
.

static
operator_replacement_fn
(cob_instr_op, dest_pauli_op)[Quellcode]¶ A builtin convenience replacement function which produces Operators isomorphic to the origin
PauliOp
. Parameter
cob_instr_op (
PrimitiveOp
) – The basischangeCircuitOp
.dest_pauli_op (
Union
[PauliOp
,PauliSumOp
,ListOp
]) – The destinationPauliOp
.
 Rückgabetyp
OperatorBase
 Rückgabe
The
~CircuitOp @ PauliOp @ CircuitOp
composition isomorphic to the originalPauliOp
.

pad_paulis_to_equal_length
(pauli_op1, pauli_op2)[Quellcode]¶ If
pauli_op1
andpauli_op2
do not act over the same number of qubits, pad identities to the end of the shorter of the two so they are of equal length. Padding is applied to the end of the Paulis. Note that the Terra represents Paulis in bigendian order, so this will appear as padding to the beginning of the Pauli x and z bit arrays. Parameter
pauli_op1 (
PauliOp
) – A pauli_op to possibly pad.pauli_op2 (
PauliOp
) – A pauli_op to possibly pad.
 Rückgabetyp
Tuple
[PauliOp
,PauliOp
] Rückgabe
A tuple containing the padded PauliOps.

static
statefn_replacement_fn
(cob_instr_op, dest_pauli_op)[Quellcode]¶ A builtin convenience replacement function which produces state functions isomorphic to an
OperatorStateFn
state function holding the originPauliOp
. Parameter
cob_instr_op (
PrimitiveOp
) – The basischangeCircuitOp
.dest_pauli_op (
Union
[PauliOp
,PauliSumOp
,ListOp
]) – The destination Pauli type operator.
 Rückgabetyp
OperatorBase
 Rückgabe
The
~CircuitOp @ StateFn
composition equivalent to a state function defined by the originalPauliOp
.