Measurement

This section covers the API reference for obtaining the expectation value of a (molecular) Hamiltonian, either from a state vector simulation, or from sample measurements.

Expectation value of Hamiltonian

qibochem.measurement.result.expectation(circuit: Circuit, hamiltonian: SymbolicHamiltonian)

Expectation value using state vector simulations

Parameters:
  • circuit (qibo.models.Circuit) – Quantum circuit ansatz

  • hamiltonian (qibo.hamiltonians.SymbolicHamiltonian) – Molecular Hamiltonian

Returns:

Expectation value of the Hamiltonian for the given circuit

Return type:

float

qibochem.measurement.result.expectation_from_samples(circuit: Circuit, hamiltonian: SymbolicHamiltonian, n_shots: int = 1000, grouping=None, n_shots_per_pauli_term: bool = True, shot_allocation=None) float

Calculate expectation value of some Hamiltonian using sample measurements from running a Qibo quantum circuit

Parameters:
  • circuit (qibo.models.Circuit) – Quantum circuit ansatz

  • hamiltonian (qibo.hamiltonians.SymbolicHamiltonian) – Molecular Hamiltonian

  • n_shots (int) – Number of times the circuit is run. Default: 1000

  • grouping (str) – Whether or not to group Hamiltonian terms together to reduce the measurement cost. Available options: None: (Default) No grouping of Hamiltonian terms, and "qwc": Terms that commute qubitwise are grouped together

  • n_shots_per_pauli_term (bool) – Whether or not n_shots is used for each Pauli term (or group of terms) in the Hamiltonian, or for all the (group of) terms in the Hamiltonian. Default: True; n_shots are used to get the expectation value for each term (group of terms) in the Hamiltonian.

  • shot_allocation – Iterable containing the number of shots to be allocated to each term (or group of terms) in the Hamiltonian respectively if the n_shots_per_pauli_term argument is False. Default: None; shots are allocated based on the magnitudes of the coefficients of the Hamiltonian terms.

Returns:

Hamiltonian expectation value for the given circuit using sample measurements

Return type:

float

Measurement cost reduction

The following functions are used for reducing and optimising the measurement cost of obtaining the Hamiltonian expectation value using sample measurements instead of a state vector simulation.

qibochem.measurement.optimization.measurement_basis_rotations(hamiltonian, grouping=None)

Split up and sort the Hamiltonian terms to get the basis rotation gates to be applied to a quantum circuit for the respective (group of) terms in the Hamiltonian

Parameters:
  • hamiltonian (qibo.hamiltonians.SymbolicHamiltonian) – Hamiltonian of interest

  • grouping (str) – Whether or not to group Hamiltonian terms together, i.e. use the same set of measurements to get the expectation values of a group of terms simultaneously. Default value of None will not group any terms together, while "qwc" will group qubitwise commuting terms together, and return the measurement gates associated with each group of terms

Returns:

List of two-tuples; the first item in the tuple is a group of Pauli terms (sympy.Expr), and the

second is a list of measurement gates (qibo.gates.M) that can be used to get the expectation value for the corresponding expression.

Return type:

list