qml.labs.trotter_error.effective_hamiltonian¶
- effective_hamiltonian(product_formula, fragments, order, timestep=1.0)[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 theProductFormula
object.order (int) – The order of the approximatation.
timestep (float) – The timestep for simulation.
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'>
code/api/api/pennylane.labs.trotter_error.effective_hamiltonian
Download Python script
Download Notebook
View on GitHub