qml.labs.trotter_error.perturbation_error

perturbation_error(product_formula, fragments, states, max_order, timestep=1.0, num_workers=1, backend='serial', parallel_mode='state')[source]

Computes the perturbation theory error using the effective Hamiltonian \(\hat{\epsilon} = \hat{H}_{eff} - \hat{H}\) for a given product formula.

For a state \(\left| \psi \right\rangle\) the perturbation theory error is given by the expectation value \(\left\langle \psi \right| \hat{\epsilon} \left| \psi \right\rangle\).

Parameters:
  • product_formula (ProductFormula) – the ProductFormula used to obtain the effective Hamiltonian

  • fragments (Sequence[Fragments]) – the set of Fragment objects to compute the perturbation error from

  • states (Sequence[AbstractState]) – the states to compute expectation values from

  • max_order (float) – the maximum commutator order to compute in BCH

  • timestep (float) – time step for the Trotter error operator.

  • num_workers (int) – the number of concurrent units used for the computation. Default value is set to 1.

  • backend (string) – the executor backend from the list of supported backends. Available options : “mp_pool”, “cf_procpool”, “cf_threadpool”, “serial”, “mpi4py_pool”, “mpi4py_comm”. Default value is set to “serial”.

  • parallel_mode (str) – the mode of parallelization to use. Options are “state” or “commutator”. “state” parallelizes the computation of expectation values per state, while “commutator” parallelizes the application of commutators to each state. Default value is set to “state”.

Returns:

the list of dictionaries of expectation values computed from the Trotter error operator and the input states.

The dictionary is indexed by the commutator orders and its value is the error obtained from the commutators of that order.

Return type:

List[Dict[int, float]]

Example

>>> import numpy as np
>>> from pennylane.labs.trotter_error import HOState, ProductFormula, vibrational_fragments, perturbation_error
>>>
>>> frag_labels = [0, 1, 1, 0]
>>> frag_coeffs = [1/2, 1/2, 1/2, 1/2]
>>> pf = ProductFormula(frag_labels, coeffs=frag_coeffs)
>>>
>>> n_modes = 2
>>> r_state = np.random.RandomState(42)
>>> freqs = r_state.random(n_modes)
>>> taylor_coeffs = [
>>>     np.array(0),
>>>     r_state.random(size=(n_modes, )),
>>>     r_state.random(size=(n_modes, n_modes)),
>>>     r_state.random(size=(n_modes, n_modes, n_modes))
>>> ]
>>> frags = dict(enumerate(vibrational_fragments(n_modes, freqs, taylor_coeffs)))
>>>
>>> gridpoints = 5
>>> state1 = HOState(n_modes, gridpoints, {(0, 0): 1})
>>> state2 = HOState(n_modes, gridpoints, {(1, 1): 1})
>>>
>>> errors = perturbation_error(pf, frags, [state1, state2], order=3)
>>> print(errors)
[{3: 0.9189251160920876j}, {3: 4.7977166824268505j}]