qiskit-documentation/docs/api/qiskit/0.26/qiskit.opflow.expectations....

54 lines
3.5 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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: ExpectationFactory (v0.26)
description: API reference for qiskit.opflow.expectations.ExpectationFactory in qiskit v0.26
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.opflow.expectations.ExpectationFactory
---
<span id="qiskit-opflow-expectations-expectationfactory" />
# qiskit.opflow\.expectations.ExpectationFactory
<Class id="qiskit.opflow.expectations.ExpectationFactory" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.17/qiskit/opflow/expectations/expectation_factory.py" signature="ExpectationFactory" modifiers="class">
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.
### \_\_init\_\_
<Function id="qiskit.opflow.expectations.ExpectationFactory.__init__" signature="__init__()">
Initialize self. See help(type(self)) for accurate signature.
</Function>
## Methods
| | |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`__init__`](#qiskit.opflow.expectations.ExpectationFactory.__init__ "qiskit.opflow.expectations.ExpectationFactory.__init__")() | Initialize self. |
| [`build`](#qiskit.opflow.expectations.ExpectationFactory.build "qiskit.opflow.expectations.ExpectationFactory.build")(operator\[, backend, include\_custom]) | A factory method for convenient automatic selection of an Expectation based on the Operator to be converted and backend used to sample the expectation value. |
### build
<Function id="qiskit.opflow.expectations.ExpectationFactory.build" signature="build(operator, backend=None, include_custom=True)" modifiers="static">
A factory method for convenient automatic selection of an Expectation based on the Operator to be converted and backend used to sample the expectation value.
**Parameters**
* **operator** (`OperatorBase`) The Operator whose expectation value will be taken.
* **backend** (`Union`\[`Backend`, `BaseBackend`, `QuantumInstance`, `None`]) The backend which will be used to sample the expectation value.
* **include\_custom** (`bool`) Whether the factory will include the (Aer) specific custom expectations if their behavior against the backend might not be as expected. For instance when using Aer qasm\_simulator with paulis the Aer snapshot can be used but the outcome lacks shot noise and hence does not intuitively behave overall as people might expect when choosing a qasm\_simulator. It is however fast as long as the more state vector like behavior is acceptable.
**Return type**
`ExpectationBase`
**Returns**
The expectation algorithm which best fits the Operator and backend.
**Raises**
**ValueError** If operator is not of a composition for which we know the best Expectation method.
</Function>
</Class>