save_expectation_value#

save_expectation_value(self, operator, qubits, label='expectation_value', unnormalized=False, pershot=False, conditional=False)[source]#

Save the expectation value of a Hermitian operator.

Parameters:
  • operator (Pauli or SparsePauliOp or Operator) – a Hermitian operator.

  • qubits (list) – circuit qubits to apply instruction.

  • label (str) – the key for retrieving saved data from results.

  • unnormalized (bool) – If True return save the unnormalized accumulated or conditional accumulated expectation value over all shot [Default: False].

  • pershot (bool) – if True save a list of expectation values for each shot of the simulation rather than the average over all shots [Default: False].

  • conditional (bool) – if True save the average or pershot data conditional on the current classical register values [Default: False].

Returns:

with attached instruction.

Return type:

QuantumCircuit

Raises:
  • ValueError – if the input operator is not Hermitian.

  • TypeError – if the input operator is of invalid type.

Note

This method appends a SaveExpectationValue instruction to the quantum circuit.