qiskit-documentation/docs/api/qiskit/0.27/qiskit.opflow.expectations.mdx

39 lines
4.5 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
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" />
# Expectations
<span id="module-qiskit.opflow.expectations" />
`qiskit.opflow.expectations`
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") | A base for Expectation value converters. |
# Expectations
| | |
| ------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`ExpectationFactory`](qiskit.opflow.expectations.ExpectationFactory "qiskit.opflow.expectations.ExpectationFactory") | A 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 Aers 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") | 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") | Compute the Conditional Value at Risk (CVaR) expectation value. |