observe(...) workflow is used when you want the expectation value of an observable rather than a full measurement distribution or the complete state vector.
Related pages:
When to use observe
Useobserve(...) when your goal is to compute the expectation value of an observable with respect to the executed quantum state.
This is especially useful in workflows such as:
- variational algorithms
- optimization loops
- cost-function evaluation
- repeated evaluation of the same circuit under different parameter values
observe(...) returns a single scalar. Unlike state-vector calculation, it does not expose the full quantum state.
Basic example
Output:-0.013999999999999999
Understanding the result
The returned value is a single scalar. It represents the expectation value of the observable with respect to the state produced by the circuit. In other words, it summarizes the behavior of the circuit relative to the operator you are interested in. This is useful when you care about one derived quantity rather than the full result space.Choosing execution settings
As with the other execution functions, you can configure the execution using standard arguments such as:- backend
- config
- num_shots
- random_seed
- parameters
Parameterized execution
Many practical uses ofobserve(...) involve parameterized circuits.
Instead of fixing all values inside the circuit, you define symbolic parameters in the
quantum function and provide their values when you execute the program.
Defining a parameterized quantum program
Supplying parameter values
Output:-0.748
Batch of expectation values
A common pattern is to evaluate the same observable for many parameter settings. Instead of callingobserve(...) repeatedly, you can pass a list of parameter dictionaries.
The function then returns a list of scalar values, one per parameter set.
Example
Output:[-0.396, -0.526, -0.6100000000000001, -0.642]
Understanding batch results
Whenparameters is a list:
- the output is a list of scalar values
- each value corresponds to one execution
- the order matches the order of the provided parameter dictionaries
observe(...) a natural fit for optimization and sweep-style workflows, where you want to evaluate the same quantity many times.
Summary
Useobserve(...) when you care about the expectation value of an observable.
Observe:
- returns a scalar
- is ideal for cost functions and iterative algorithms
- supports both single and batch parameterized execution