47 lines
5.0 KiB
Plaintext
47 lines
5.0 KiB
Plaintext
---
|
|
title: expectations
|
|
description: API reference for qiskit.opflow.expectations
|
|
in_page_toc_min_heading_level: 2
|
|
python_api_type: module
|
|
python_api_name: qiskit.opflow.expectations
|
|
---
|
|
|
|
<span id="module-qiskit.opflow.expectations" />
|
|
|
|
<span id="qiskit-opflow-expectations" />
|
|
|
|
# qiskit.opflow\.expectations
|
|
|
|
<span id="expectations-qiskit-opflow-expectations" />
|
|
|
|
## Expectations
|
|
|
|
<span id="module-qiskit.opflow.expectations" />
|
|
|
|
`qiskit.opflow.expectations`
|
|
|
|
<Admonition title="Deprecated since version 0.24.0" type="danger">
|
|
The [`qiskit.opflow`](opflow#module-qiskit.opflow "qiskit.opflow") module is deprecated and will be removed no earlier than 3 months after the release date. For code migration guidelines, visit [https://qisk.it/opflow\_migration](https://qisk.it/opflow_migration).
|
|
</Admonition>
|
|
|
|
Expectations are converters which enable the computation of the expectation value of an Observable with respect to some state function. They traverse an Operator tree, replacing [`OperatorStateFn`](qiskit.opflow.state_fns.OperatorStateFn "qiskit.opflow.state_fns.OperatorStateFn") measurements with equivalent measurements which are more amenable to computation on quantum or classical hardware. For example, if one would like to measure the expectation value of an Operator `o` expressed as a sum of Paulis with respect to some state function, but only has access to diagonal measurements on Quantum hardware, we can create a measurement \~StateFn(o), use a [`PauliExpectation`](qiskit.opflow.expectations.PauliExpectation "qiskit.opflow.expectations.PauliExpectation") to convert it to a diagonal measurement and circuit pre-rotations to append to the state, and sample this circuit on Quantum hardware with a [`CircuitSampler`](qiskit.opflow.converters.CircuitSampler "qiskit.opflow.converters.CircuitSampler"). All in all, this would be: `my_sampler.convert(my_expect.convert(~StateFn(o)) @ my_state).eval()`.
|
|
|
|
### Expectation Base Class
|
|
|
|
The ExpectationBase class gives an interface for algorithms to ask for Expectations as execution settings. For example, if an algorithm contains an expectation value step within it, such as [`VQE`](qiskit.algorithms.VQE "qiskit.algorithms.VQE"), the algorithm can give the opportunity for the user to pass an ExpectationBase of their choice to be used in that expectation value step.
|
|
|
|
| | |
|
|
| -------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
|
|
| [`ExpectationBase`](qiskit.opflow.expectations.ExpectationBase "qiskit.opflow.expectations.ExpectationBase")() | Deprecated: A base for Expectation value converters. |
|
|
|
|
### Expectations
|
|
|
|
| | |
|
|
| ----------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
| [`ExpectationFactory`](qiskit.opflow.expectations.ExpectationFactory "qiskit.opflow.expectations.ExpectationFactory")() | Deprecated: factory class for convenient automatic selection of an Expectation based on the Operator to be converted and backend used to sample the expectation value. |
|
|
| [`AerPauliExpectation`](qiskit.opflow.expectations.AerPauliExpectation "qiskit.opflow.expectations.AerPauliExpectation")() | An Expectation converter for using Aer's operator snapshot to take expectations of quantum state circuits over Pauli observables. |
|
|
| [`MatrixExpectation`](qiskit.opflow.expectations.MatrixExpectation "qiskit.opflow.expectations.MatrixExpectation")() | An Expectation converter which converts Operator measurements to be matrix-based so they can be evaluated by matrix multiplication. |
|
|
| [`PauliExpectation`](qiskit.opflow.expectations.PauliExpectation "qiskit.opflow.expectations.PauliExpectation")(\[group\_paulis]) | An Expectation converter for Pauli-basis observables by changing Pauli measurements to a diagonal (\{Z, I}^n) basis and appending circuit post-rotations to the measured state function. |
|
|
| [`CVaRExpectation`](qiskit.opflow.expectations.CVaRExpectation "qiskit.opflow.expectations.CVaRExpectation")(alpha\[, expectation]) | Deprecated: Compute the Conditional Value at Risk (CVaR) expectation value. |
|
|
|