code: def expectation(self, operator: Union[PauliTerm, PauliSum]):
          
          if not isinstance(operator, PauliSum):
              operator = PauliSum([operator])
  
          return sum(_term_expectation(self.wf, term, n_qubits=self.n_qubits) for term in operator)
docs: Compute the expectation of an operator.
  
          :param operator: The operator
          :return: The operator's expectation value