observe(...) workflow is used when you want expectation values of one or more observables rather than a full measurement distribution or the complete state vector.
Related pages:
When to use observe
Useobserve(...) when your goal is to compute expectation values of observables 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 expectation values (a scalar for a single observable, or lists when batching observables and/or parameter sets). Unlike state-vector calculation, it does not expose the full quantum state.
Basic example
Output:-0.013999999999999999
Understanding the result
When you pass a single observable and a single parameter set, 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. When batching is used, return shapes are:- single observable + list of parameter sets ->
list[float] - list of observables + single parameter set ->
list[float] - list of observables + list of parameter sets ->
list[list[float]], indexed as[observable_index][parameter_index]
Choosing execution settings
As with the other execution functions, you can configure the execution using standard arguments such as:- estimate
- num_shots
- parameters
- run_via_classiq
- verbose
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 (parameter sweep)
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.
Batch of observables
You can also evaluate multiple observables in one call by passing a list inobservable.
- first index -> observable
- second index -> parameter set
observables keyword and legacy hamiltonian support
For ExecutionSession.observe(...) and ExecutionSession.submit_observe(...), the canonical keyword is observables.
The legacy hamiltonian keyword is still supported for backward compatibility (with a deprecation warning), so existing code continues to run during the transition period.
In
ExecutionSession.observe(...), when both the observable input and parameters are lists, observables=... returns a nested list ([observable][parameter]). Calls that still use legacy hamiltonian=... keep the historical flat-list shape for backward compatibility.Summary
Useobserve(...) when you care about expectation values of one or more observables.
Observe:
- returns a scalar or list-shaped output, depending on input
- is ideal for cost functions and iterative algorithms
- supports both single and batch parameterized execution