qml.labs.trotter_error.effective_hamiltonian¶
- effective_hamiltonian(product_formula, fragments, order, timestep=1.0, num_workers=1, backend='serial')[source]¶
Compute the effective Hamiltonian \(\hat{H}_{eff} = \hat{H} + \hat{\epsilon}\) that corresponds to a given product formula.
- Parameters:
product_formula (ProductFormula) – A product formula used to approximate the time-evolution operator for a Hamiltonian.
fragments (Dict[Hashable,
Fragment) – The fragments that sum to the Hamiltonian. The keys in the dictionary must match the labels used to build theProductFormulaobject.order (int) – The order of the approximatation.
timestep (float) – The timestep for simulation.
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”.
Example
>>> import numpy as np >>> from pennylane.labs.trotter_error.fragments import vibrational_fragments >>> from pennylane.labs.trotter_error.product_formulas import ProductFormula, effective_hamiltonian >>> >>> n_modes = 4 >>> r_state = np.random.RandomState(42) >>> freqs = r_state.random(4) >>> 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)) >>> ] >>> >>> delta = 0.001 >>> frag_labels = [0, 1, 1, 0] >>> frag_coeffs = [1/2, 1/2, 1/2, 1/2] >>> >>> pf = ProductFormula(frag_labels, coeffs=frag_coeffs) >>> frags = dict(enumerate(vibrational_fragments(n_modes, freqs, taylor_coeffs))) >>> type(effective_hamiltonian(pf, frags, order=5, timestep=delta)) <class 'pennylane.labs.trotter_error.realspace.realspace_operator.RealspaceSum'>