qpe_toolbox.circuit.circuits_opt ================================ .. py:module:: qpe_toolbox.circuit.circuits_opt Functions --------- .. autoapisummary:: qpe_toolbox.circuit.circuits_opt.svd_optimal_gate_update qpe_toolbox.circuit.circuits_opt.tn_fit Module Contents --------------- .. py:function:: svd_optimal_gate_update(tensor, left_inds) Solve for the SVD-optimal isometric update of a variational tensor. ``tensor`` is the environment of a variational tensor: the rest of a tensor network, fully contracted, with that tensor removed. This is the closed-form solution of the associated *unconstrained linear* problem: the isometry :math:`X` maximizing :math:`\mathrm{Re}\,\mathrm{Tr}(X^\dagger B)` is :math:`X = U V^\dagger`, where :math:`B = U S V^\dagger` is the SVD of the environment. The singular values :math:`S` are not returned, only their sum. :param tensor: Contracted environment tensor. :type tensor: :quimb-api:`Tensor` :param left_inds: Subset of ``tensor``'s indices forming the left side of the SVD bipartition; the remaining indices form the right side. :type left_inds: sequence of str :returns: * **new_isometry** (:quimb-api:`Tensor`) -- Optimal unitary (isometric if not square) tensor, with the same indices as ``tensor`` but not necessarily in the same order. * **objective** (*float*) -- Sum of the singular values of :math:`B`, i.e. the achieved value of :math:`\mathrm{Re}\,\mathrm{Tr}(X^\dagger B)`. .. py:function:: tn_fit(tn, tn_target, *, tags='SU4SWAP', steps=100, tol=1e-08, contract_optimize='auto-hq') Fit tensor network `tn` to target tensor network `tn_target`. :param tn: The tensor network to be optimized (in-place). :type tn: TensorNetwork :param tn_target: The target tensor network (usually a state we want to approximate). :type tn_target: TensorNetwork :param tags: Tags selecting which tensors of `tn` to optimize (any tag matches). Default is ``"SU4SWAP"``. :type tags: str or sequence of str, optional :param steps: Number of sweeps. :type steps: int :param tol: Convergence tolerance on the change of the overlap. :type tol: float :param contract_optimize: Contraction strategy for the environments. :type contract_optimize: str :raises TypeError: If a tensor selected by `tags` is parametrized. :raises ValueError: If a tensor selected by `tags` is not a whole two-qubit gate. A :quimb-api:`Circuit` built with the default ``gate_contract='auto-split-gate'`` splits gates that are not full rank (e.g. identity or CNOT): build it with ``gate_contract=False``. .. rubric:: Notes Progress is shown via a :mod:`tqdm` bar; set the ``TQDM_DISABLE`` environment variable to silence it.