Operator utilities (qiskit_addon_obp.utils.operations)¶
Utility functions for operator backpropagation.
- apply_op_to(op1, op1_qargs, op2, op2_qargs, *, apply_as_transform=False)[source]¶
Apply the operator
op2to the operatorop1.These operators do not necessarily need to act on the same number of qubits, as they are assumed to act on a larger system. The position in the system of each operator is defined by the corresponding
qargs. The output operator will be defined onunion(op1_qargs, op2_qargs).By default, this function applies
op1toop2in the following way:op2 @ op1By setting
apply_as_transform=True, this function will applyop1toop2in the following way:op2.adjoint() @ op1 @ op2- Parameters:
op1 (SparsePauliOp) – The operator on which
op2will be applied.op2 (SparsePauliOp) – The operator to apply to
op1.apply_as_transform (bool) – Whether to apply
op2toop1as a transformation.
- Returns:
The tuple
(op, qargs)whereopis the inputop1withop2left-applied andqargsis a list of qubit indices for the new operatorop. The qubit IDs in the outputopcorrespond to the global qubit ID in the same index inqargs.For example, if the output
opis aSparsePauliOp("YX")andqargsis [3, 4], the X term on qubit 0 of the operator corresponds to global qubit ID 3.- Raises:
ValueError – The number of unique operator qargs must match the number of qubits in the corresponding operator.
- Return type:
- apply_reset_to(op, qubit_id, inplace=False)[source]¶
Apply a reset operation to a Pauli operator.
This function applies a reset operation to
opin the following way:<0|op|0>Terms containing Pauli X or Y terms on qubit-
qubit_idwill have their weight reduced to0.0. Terms containing Pauli Z onqubit_idwill have that Pauli Z replaced by an identity.- Parameters:
op (SparsePauliOp) – The operator to which the reset will be applied.
qubit_id (int) – The index of the qubit on which to apply the reset.
inplace (bool) – Whether to modify the operator in-place.
- Returns:
The transformed operator
- Return type:
- to_global_op(op, qargs, n_qubits)[source]¶
Convert a local operator to a global operator by inserting identities on qubits which aren’t used.
- Parameters:
op (SparsePauliOp) – Local operator to expand.
n_qubits (int) – Number of qubits in the global system.
- Returns:
An operator on
n_qubitsqubits- Raises:
ValueError – Qubit ID out of range
- Return type:
- reduce_op(global_op)[source]¶
Create a lean representation of a global Pauli operator.
This function returns a lean representation of the input operator such that all of the qubits associated solely with Pauli-I terms have been removed. A list of indices is also returned indicating on which qubits the lean operator acts.
- For example:
>>> global_op = SparsePauliOp(["IXI", "IIZ"]) >>> reduced_op, qargs = reduce_op(global_op) >>> reduced_op SparsePauliOp(['XI', 'IZ'], coeffs=[1.+0.j, 1.+0.j]) >>> qargs [0, 1]
- Parameters:
global_op (SparsePauliOp) – The global operator for which to generate a lean representation
- Returns:
A lean representation of the input operator with qubits associated solely with identity terms removed.
A list of indices specifying the qubits on which the lean operator acts.
- Raises:
ValueError – Input operator may not be the identity operator.
- Return type: