WavefunctionSimulator.expectation(prep_prog, pauli_terms, memory_map=None)[source]

Calculate the expectation value of Pauli operators given a state prepared by prep_program.

If pauli_terms is a PauliSum then the returned value is a single float, otherwise the returned value is an array of values, one for each PauliTerm in the list.


If your program contains measurements or noisy gates, this method may not do what you want. If the execution of quil_program is non-deterministic then the final wavefunction from which the expectation value is calculated only represents a stochastically generated sample and the wavefunctions returned by different wavefunction calls will generally be different.

  • prep_prog (Program) – A program that prepares the state on which we measure the expectation.
  • pauli_terms (Union[PauliSum, List[PauliTerm]]) – A Pauli representation of a quantum operator.
  • memory_map (Optional[Any]) –

    An assignment of classical registers to values, representing an initial state for the QAM’s classical memory.

    This is expected to be of type Dict[str, List[Union[int, float]]], where the keys are memory region names and the values are arrays of initialization data.

    For now, we also support input of type Dict[MemoryReference, Any], but this is deprecated and will be removed in a future release.

Return type:

Union[float, ndarray]


Either a float or array floats depending on pauli_terms.