qml.labs.trotter_error.bch_expansion¶
- bch_expansion(product_formula, order)[source]¶
Compute the Baker-Campbell-Hausdorff expansion of a
ProductFormula
object.- Parameters:
product_formula (ProductFormula) – The
ProductFormula
object whose BCH expansion will be computed.order (int) – The maximum order of the expansion to return.
- Returns:
A list of dictionaries. The
ith
dictionary contains theith
order commutators and their coefficients.- Return type:
List[Dict[Tuple[Hashable], complex]]
Example
In this example we compute the BCH expansion of the second order Trotter-Suzuki formula. The output is a list of dictionaries where each dictionary is indexed by a tuple representing a right-nested commutator. For example,
('A', 'A', 'B')
represents the commutator \([A, [A, B]]\).>>> from pprint import pp >>> from pennylane.labs.trotter_error import ProductFormula, bch_expansion >>> frag_labels = ["A", "B", "C", "B", "A"] >>> frag_coeffs = [1/2, 1/2, 1, 1/2, 1/2] >>> second_order = ProductFormula(frag_labels, frag_coeffs) >>> pp(bch_expansion(second_order, order=3)) [defaultdict(<class 'complex'>, {('A',): (1+0j), ('B',): (1+0j), ('C',): (1+0j)}), defaultdict(<class 'complex'>, {}), defaultdict(<class 'complex'>, {('A', 'A', 'B'): (-0.04166666666666667+0j), ('B', 'A', 'B'): (-0.08333333333333333+0j), ('C', 'A', 'B'): (-0.08333333333333334+0j), ('A', 'A', 'C'): (-0.04166666666666667+0j), ('B', 'A', 'C'): (-0.08333333333333334+0j), ('B', 'B', 'C'): (-0.04166666666666667+0j), ('C', 'A', 'C'): (-0.08333333333333333+0j), ('C', 'B', 'C'): (-0.08333333333333333+0j)})]
code/api/api/pennylane.labs.trotter_error.bch_expansion
Download Python script
Download Notebook
View on GitHub