qpe_toolbox.hamiltonian.trotterization ====================================== .. py:module:: qpe_toolbox.hamiltonian.trotterization .. autoapi-nested-parse:: Trotter-Suzuki decompositions of Hamiltonian time evolution, as MPOs or gate sequences. Functions --------- .. autoapisummary:: qpe_toolbox.hamiltonian.trotterization.exp_Pauli_string_as_MPO qpe_toolbox.hamiltonian.trotterization.trotter1_approx_as_MPO qpe_toolbox.hamiltonian.trotterization.trotter2_approx_as_MPO qpe_toolbox.hamiltonian.trotterization.trotter4_approx_as_MPO qpe_toolbox.hamiltonian.trotterization.trotter_approx_as_MPO qpe_toolbox.hamiltonian.trotterization.rotation_gates qpe_toolbox.hamiltonian.trotterization.trotter_evolution_gates qpe_toolbox.hamiltonian.trotterization.trotter_evolution_powers Module Contents --------------- .. py:function:: exp_Pauli_string_as_MPO(term, dt, n_qubits) Construct the MPO representation of the unitary exponential of a Pauli string. Given a Hamiltonian term of the form: H = c * P where ``c`` is a scalar coefficient and ``P`` is a tensor product of Pauli operators acting on a subset of qubits, this function builds the Matrix Product Operator (MPO) corresponding to: exp(-i * dt * c * P) using the identity: exp(-i α P) = cos(α) I - i sin(α) P where ``P^2 = I``. The Pauli string is expanded to the full system size by inserting identity operators on inactive qubits. :param term: A tuple ``(coeff, pauli_string, active_qubits)`` where: - ``coeff`` (float): Scalar coefficient multiplying the Pauli string. - ``pauli_string`` (str): String of Pauli operators (e.g. ``"ZYXXZ"``). - ``active_qubits`` (list[int]): Indices of qubits where the Pauli operators act. The length must match ``pauli_string``. :type term: tuple :param dt: Evolution time. :type dt: float :param n_qubits: Total number of qubits in the system. :type n_qubits: int :returns: MPO, in ``'lrud'`` order, representing the operator: exp(-i * dt * coeff * P) where ``P`` is the full Pauli string embedded in the ``n_qubits`` system. :rtype: :quimb-api:`MatrixProductOperator` :raises ValueError: If the length of ``pauli_string`` does not match the number of ``active_qubits``, or if ``active_qubits`` contains a repeated or out-of-range qubit. .. py:function:: trotter1_approx_as_MPO(hamiltonian, dt, *, cutoff=1e-10, max_bond=None, reverse_order=False) Construct the first-order Trotter-Suzuki approximation as a Matrix Product Operator (MPO). This function builds an MPO representation of the first-order product formula for the time-evolution operator .. math:: U(dt) \approx \prod_j e^{-i dt \, H_j}, where ``hamiltonian.terms = [H_0, H_1, ..., H_{m-1}]`` is a decomposition of the Hamiltonian into terms that can each be exponentiated individually as MPOs. :param hamiltonian: Includes Pauli strings, positions and couplings. :type hamiltonian: :class:`~qpe_toolbox.hamiltonian.Hamiltonian` :param dt: Time step used in the Trotter approximation. :type dt: float :param cutoff: Singular value truncation threshold used during MPO compression. Default is ``1e-10``. :type cutoff: float, optional :param max_bond: Maximum allowed bond dimension during MPO compression. Default is ``None`` (no limit). :type max_bond: int, optional :param reverse_order: If ``False`` (default), terms are applied in forward order. If ``True``, terms are applied in reverse index order. :type reverse_order: bool, optional :returns: MPO representation of the first-order Trotter approximation. :rtype: :quimb-api:`MatrixProductOperator` .. py:function:: trotter2_approx_as_MPO(hamiltonian, dt, *, cutoff=1e-10, max_bond=None, verbosity=0) Construct the second-order symmetric Trotter-Suzuki approximation as an MPO. This function builds the second-order product formula .. math:: U(dt) \approx U_1(dt/2)\,U_1^{\mathrm{rev}}(dt/2), where :math:`U_1` is the first-order Trotter approximation and :math:`U_1^{\mathrm{rev}}` uses the reverse operator ordering. :param hamiltonian: Includes Pauli strings, positions and couplings. :type hamiltonian: :class:`~qpe_toolbox.hamiltonian.Hamiltonian` :param dt: Time step used in the Trotter approximation. :type dt: float or complex :param cutoff: Singular value truncation threshold used during MPO compression. Default is ``1e-10``. :type cutoff: float, optional :param max_bond: Maximum allowed bond dimension during MPO compression. Default is ``None`` (no limit). :type max_bond: int, optional :param verbosity: Verbosity level. If >= 1, print progress. :type verbosity: int, default ``0`` :returns: MPO representation of the second-order Trotter approximation. :rtype: :quimb-api:`MatrixProductOperator` .. py:function:: trotter4_approx_as_MPO(hamiltonian, dt, *, cutoff=1e-10, max_bond=None, verbosity=0) Construct the fourth-order Trotter-Suzuki approximation as an MPO. This function implements the standard symmetric fourth-order composition .. math:: U_4(dt) = U_2(s\,dt)\, U_2((1 - 2s)\,dt)\, U_2(s\,dt), where :math:`U_2` is the second-order Trotter approximation and .. math:: s = \frac{1}{2 - 2^{1/3}} is the symmetry factor. :param hamiltonian: Includes Pauli strings, positions and couplings. :type hamiltonian: :class:`~qpe_toolbox.hamiltonian.Hamiltonian` :param dt: Time step used in the Trotter approximation. :type dt: float :param cutoff: Singular value truncation threshold used during MPO compression. Default is ``1e-10``. :type cutoff: float, optional :param max_bond: Maximum allowed bond dimension during MPO compression. Default is ``None`` (no limit). :type max_bond: int, optional :param verbosity: Verbosity level. If >= 1, print progress. :type verbosity: int, default ``0`` :returns: MPO representation of the fourth-order Trotter approximation. :rtype: :quimb-api:`MatrixProductOperator` .. py:function:: trotter_approx_as_MPO(hamiltonian, dt, *, trotter_order=1, cutoff=1e-10, max_bond=None, verbosity=0) Construct a Trotter-Suzuki approximation of a Hamiltonian evolution operator as an MPO. This function dispatches to a specific Trotter-Suzuki decomposition according to the requested approximation order. The Hamiltonian is assumed to provide a decomposition into elementary terms through ``hamiltonian.terms``. Depending on ``trotter_order``, the approximation is built using: .. math:: U(dt) \approx \begin{cases} \text{1st-order product formula}, & \text{if trotter\_order} = 1, \\ \text{2nd-order symmetric formula}, & \text{if trotter\_order} = 2, \\ \text{4th-order Suzuki formula}, & \text{if trotter\_order} = 4. \end{cases} :param hamiltonian: Includes Pauli strings, positions and couplings. :type hamiltonian: :class:`~qpe_toolbox.hamiltonian.Hamiltonian` :param dt: Time step used in the Trotter approximation. :type dt: float :param trotter_order: Order of the Trotter-Suzuki decomposition. Default is ``1``. :type trotter_order: {1, 2, 4}, optional :param cutoff: Singular value truncation threshold used during MPO compression. Default is ``1e-10``. :type cutoff: float, optional :param max_bond: Maximum allowed MPO bond dimension during compression. Default is ``None`` (no limit). :type max_bond: int, optional :param verbosity: Verbosity level. If >= 1, print progress. :type verbosity: int, default ``0`` :returns: Compressed MPO representation of the Trotterized time-evolution operator. :rtype: :quimb-api:`MatrixProductOperator` :raises ValueError: If the requested ``trotter_order`` is not implemented. .. py:function:: rotation_gates(term, dt, phys_reg) Generate a gate sequence for exponentiating a Pauli-string term. Implements .. math:: e^{-i dt \theta P} where :math:`P` is a tensor product of Pauli operators and :math:`\theta` is the associated coefficient in the term. The implementation uses basis rotations, ``CNOT`` chains, and a single ``RZ`` rotation. :param term: Hamiltonian term ``(theta, pauli_string, qubits)``. :type term: tuple :param dt: Time step or Trotter slice. :type dt: float :param phys_reg: Physical qubit register: mapping from the term's logical qubit indices to circuit qubits. :type phys_reg: sequence of int :returns: Abstract quantum gate instructions suitable for circuit construction. :rtype: list .. py:function:: trotter_evolution_gates(hamiltonian, evolution_time, n_trotter_steps, *, trotter_order=1) Build the gate sequence of one Trotterized evolution :math:`U(t)`. :param hamiltonian: Hamiltonian object from the QPE-Toolbox ``Hamiltonian`` class. :type hamiltonian: Hamiltonian :param evolution_time: Evolution time ``t``. :type evolution_time: float :param n_trotter_steps: Number of Trotter steps, a positive integer. The Trotter step size is ``dt = evolution_time / n_trotter_steps``. :type n_trotter_steps: int :param trotter_order: Order of the Trotter decomposition. :type trotter_order: int, default ``1`` :returns: Lazily yields the gates of the Trotterized :math:`U(t)` on data-register-local qubits, without controls, as expected by ``qpe_circuit``, ``qpe_gates`` and the Hadamard test. The generator is one-shot: it can be consumed only once. :rtype: generator of :quimb-api:`Gate` .. py:function:: trotter_evolution_powers(hamiltonian, evolution_time, n_trotter_steps, n_powers, *, trotter_order=1) Build the Trotterized evolution unitaries :math:`U(t \, 2^k)` for the QPE sequence. The Trotter step size ``dt = evolution_time / n_trotter_steps`` is kept constant across powers: power ``k`` uses ``n_trotter_steps * 2**k`` steps. :param hamiltonian: Hamiltonian object from the QPE-Toolbox ``Hamiltonian`` class. :type hamiltonian: Hamiltonian :param evolution_time: Total evolution time ``t``. :type evolution_time: float :param n_trotter_steps: Number of Trotter steps for the ``U(t)`` evolution, a positive integer. :type n_trotter_steps: int :param n_powers: Number of powers to build, indexed by ``k = 0, ..., n_powers - 1``. :type n_powers: int :param trotter_order: Order of the Trotter decomposition. :type trotter_order: int, default ``1`` :returns: **unitaries** -- ``unitaries[k]`` lazily yields the gates of the Trotterized :math:`U(t \, 2^k)` on data-register-local qubits, without controls, as expected by ``qpe_circuit`` and ``qpe_gates``. Each generator is one-shot: it can be consumed only once. :rtype: list of generator of :quimb-api:`Gate`