> ## Documentation Index
> Fetch the complete documentation index at: https://docs.haiqu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Observable Backpropagation

#### Haiqu.observable\_backpropagation(circuit, observables, max\_qwc\_groups=50, max\_error\_total=0.05, max\_error\_per\_slice=0.005, log=True)

Optimize the observables for a circuit with observable backpropagation.

This method wraps the Qiskit Operator Backpropagation (OBP) functionality to preprocess your circuits and observables for
efficient execution.

* **Parameters:**
  * **circuit** (*QuantumCircuit* *|* *CircuitModel*) -- The quantum circuit to optimize.
  * **observables** (*SparsePauliOp* *|* *list* \*(\**SparsePauliOp* *)*) -- The observable(s) to optimize. Can be a single `SparsePauliOp` or
    list of `SparsePauliOp`. The order of Pauli terms follows the
    Qiskit reversed-order convention.
  * **max\_qwc\_groups** (*int*) -- Maximum number of qubit-wise commuting groups to create. Defaults to 50.
    Treat with caution as increasing this value may lead to SIGNIFICANTLY higher computational costs!
  * **max\_error\_total** (*float*) -- Maximum error allowed for the entire circuit. Defaults to 0.05.
  * **max\_error\_per\_slice** (*float*) -- Maximum error allowed per slice of the circuit. Defaults to 0.005.
  * **log** (*bool*) -- If `True` (default), logs the reduced circuits to the Haiqu cloud.
* **Returns:**
  A list of reduced circuits and a list of backpropagated observables.
* **Return type:**
  tuple\[list, list]

#### Examples

```python theme={null}
>>> from qiskit import QuantumCircuit
>>> from qiskit.quantum_info import SparsePauliOp
>>> qc = QuantumCircuit(2)
>>> qc.h(0)
>>> qc.cx(0, 1)
>>> obs = [SparsePauliOp("ZZ"), SparsePauliOp("XX")]
>>> optimized_circuits, optimized_obs = haiqu.observable_backpropagation(circuit=qc, observables=obs, log=False)
>>> [len(qc) for qc in optimized_circuits]
[0, 0]
>>> optimized_obs
[SparsePauliOp(['ZI'],
               coeffs=[1.+0.j]),
 SparsePauliOp(['IZ'],
               coeffs=[1.+0.j])]
```
