paddle_quantum.trotter

Trotter Hamiltonian time evolution circuit module.

paddle_quantum.trotter.construct_trotter_circuit(circuit, hamiltonian, tau, steps, method='suzuki', order=1, grouping=None, coefficient=None, permutation=None)

Add time-evolving circuits to a user-specified circuit.

This circuit could approximate the time-evolving operator of a system given its Hamiltonian H, i.e., \(U_{\rm cir}~ e^{-iHt}\).

Parameters:
  • circuit (Circuit) – Circuit object to which a time evolution circuit will be added.

  • hamiltonian (Hamiltonian) – Hamiltonian of the system whose time evolution is to be simulated.

  • tau (float) – Evolution time of each trotter block.

  • steps (int) – Number of trotter blocks that will be added in total. (Hint: steps * tau should be the total evolution time.)

  • method (str | None) – How the time evolution circuit will be constructed. Defaults to 'suzuki', i.e., using Trotter-Suzuki decomposition. Set to 'custom' to use a customized simulation strategy. (Needs to be specified with arguments permutation and coefficient.)

  • order (int | None) – Order of the Trotter-Suzuki decomposition. Only works when method='suzuki'. Defaults to 1.

  • grouping (str | None) – Whether the Hamiltonian’s ordering will be rearranged in a user-specified way. Supports 'xyz' and 'even_odd' grouping methods. Defaults to None.

  • coefficient (ndarray | Tensor | None) – Custom coefficients corresponding to terms of the Hamiltonian. Only works for method='custom'. Defaults to None.

  • permutation (ndarray | None) – Custom permutation of the Hamiltonian. Only works for method='custom'. Defaults to None.

Raises:
  • ValueError – The order of the trotter-suzuki decomposition should be either 1, 2 or 2k (k an integer)

  • ValueError – Shape of the permutation and coefficient array don't match

  • ValueError – Grouping method grouping is not supported, valid key words: ‘xyz’, ‘even_odd’

  • ValueError – The method method is not supported, valid method keywords: ‘suzuki’, ‘custom’

Hint

For a more detailed explanation of how this function works, users may refer to the tutorials on Paddle Quantum’s website: https://qml.baidu.com/tutorials/overview.html.

paddle_quantum.trotter.optimal_circuit(circuit, theta, which_qubits)

Add an optimized circuit with the Hamiltonian ‘XXYYZZ’.

Parameters:
  • circuit (Circuit) – Circuit where the gates are to be added.

  • theta (Tensor | float) – Three rotation angles.

  • which_qubits (Iterable) – List of the index of the qubit that each Pauli operator acts on.

paddle_quantum.trotter.add_n_pauli_gate(circuit, theta, pauli_word, which_qubits)

Add a rotation gate for a tensor product of Pauli operators, for example \(e^{-\theta/2 * X \otimes I \otimes X \otimes Y}\).

Parameters:
  • circuit (Circuit) – Circuit where the gates are to be added.

  • theta (Tensor | float) – Rotation angle.

  • pauli_word (str) – Pauli operators in a string format, e.g., "XXZ".

  • which_qubits (Iterable) – List of the index of the qubit that each Pauli operator in the pauli_word acts on.

Raises:

ValueError – The which_qubits should be either list, tuple, or np.ndarray.

paddle_quantum.trotter.get_suzuki_permutation(length, order)

Calculate the permutation array corresponding to the Suzuki decomposition.

Parameters:
  • length (int) – Number of terms in the Hamiltonian, i.e., how many terms to be permuted.

  • order (int) – Order of the Suzuki decomposition.

Returns:

Permutation array.

Return type:

ndarray

paddle_quantum.trotter.get_suzuki_p_values(k)

Calculate the parameter p(k) in the Suzuki recurrence relationship.

Parameters:

k (int) – Order of the Suzuki decomposition.

Returns:

A list of length five of form [p, p, (1 - 4 * p), p, p].

Return type:

list

paddle_quantum.trotter.get_suzuki_coefficients(length, order)

Calculate the coefficient array corresponding to the Suzuki decomposition.

Parameters:
  • length (int) – Number of terms in the Hamiltonian, i.e., how many terms to be permuted.

  • order (int) – Order of the Suzuki decomposition.

Returns:

Coefficient array.

Return type:

ndarray

paddle_quantum.trotter.get_1d_heisenberg_hamiltonian(length, j_x=1.0, j_y=1.0, j_z=1.0, h_z=0.0, periodic_boundary_condition=True)

Generate the Hamiltonian of a one-dimensional Heisenberg chain.

Parameters:
  • length (int) – Chain length.

  • j_x (float) – Coupling strength Jx on the x direction. Defaults to 1..

  • j_y (float) – Coupling strength Jy on the y direction. Defaults to 1..

  • j_z (float) – Coupling strength Jz on the z direction. Defaults to 1..

  • h_z (float) – Magnet field along z-axis. A uniform field will be added for single float input. Defaults to 0..

  • periodic_boundary_condition (bool) – Whether to consider the periodic boundary, i.e., l + 1 = 0. Defaults to True.

Returns:

Hamiltonian of this Heisenberg chain.

Return type:

Hamiltonian