:py:mod:`cotengra.pathfinders.path_simulated_annealing` ======================================================= .. py:module:: cotengra.pathfinders.path_simulated_annealing Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: cotengra.pathfinders.path_simulated_annealing.compute_contracted_info cotengra.pathfinders.path_simulated_annealing.linspace_generator cotengra.pathfinders.path_simulated_annealing._describe_tree cotengra.pathfinders.path_simulated_annealing._score_tree cotengra.pathfinders.path_simulated_annealing._slice_tree_basic cotengra.pathfinders.path_simulated_annealing._slice_tree_reslice cotengra.pathfinders.path_simulated_annealing._slice_tree_drift cotengra.pathfinders.path_simulated_annealing.simulated_anneal_tree cotengra.pathfinders.path_simulated_annealing._do_anneal cotengra.pathfinders.path_simulated_annealing.parallel_temper_tree .. py:function:: compute_contracted_info(legsa, legsb, appearances, size_dict) Compute the contracted legs, cost and size of a pair of legs. :param legsa: The legs of the first tensor. :type legsa: dict[str, int] :param legsb: The legs of the second tensor. :type legsb: dict[str, int] :param appearances: The total number of appearances of each index in the contraction. :type appearances: dict[str, int] :param size_dict: The size of each index. :type size_dict: dict[str, int] :returns: * **legsab** (*dict[str, int]*) -- The contracted legs. * **cost** (*int*) -- The cost of the contraction. * **size** (*int*) -- The size of the resulting tensor. .. py:function:: linspace_generator(start, stop, num, log=False) Generate a sequence of ``num`` evenly spaced floats between ``start`` and ``stop``. :param start: The starting value. :type start: float :param stop: The stopping value. :type stop: float :param num: The number of values to generate. :type num: int :param log: Whether to generate the sequence in log space. :type log: bool, optional :Yields: *float* .. py:function:: _describe_tree(tree, info='concise') .. py:function:: _score_tree(scorer, tree, target_size=None) .. py:function:: _slice_tree_basic(tree, current_target_size, rng) .. py:function:: _slice_tree_reslice(tree, current_target_size, rng) .. py:function:: _slice_tree_drift(tree, current_target_size, rng) .. py:function:: simulated_anneal_tree(tree, tfinal=0.05, tstart=2, tsteps=50, numiter=50, minimize=None, target_size=None, target_size_initial=None, slice_mode='basic', seed=None, progbar=False, inplace=False) Perform a simulated annealing optimization of this contraction tree, based on "Multi-Tensor Contraction for XEB Verification of Quantum Circuits" by Gleb Kalachev, Pavel Panteleev, Man-Hong Yung (arXiv:2108.05665), and the "treesa" implementation in OMEinsumContractionOrders.jl by Jin-Guo Liu and Pan Zhang. :param tfinal: The final temperature. :type tfinal: float, optional :param tstart: The starting temperature. :type tstart: float, optional :param tsteps: The number of temperature steps. :type tsteps: int, optional :param numiter: The number of sweeps at each temperature step. :type numiter: int, optional :param minimize: The objective function to minimize. :type minimize: {'flops', 'combo', 'write', 'size', ...}, optional :param target_size: The target size to slice the contraction to. A schedule is used to reach this only at the final temperature step. :type target_size: int, optional :param target_size_initial: The initial target size to use in the slicing schedule. If None, then the current size is used. :type target_size_initial: int, optional :param slice_mode: The mode for slicing the contraction tree within each annealing iteration. 'basic' always unslices a random index and then slices to the target size. 'reslice' unslices all indices and then slices to the target size. 'drift' unslices a random index with probability 1/4 and slices to the target size with probability 3/4. It is therefore not guaranteed to reach the target size, but may be more explorative for long annealing schedules. :type slice_mode: {'basic', 'reslice', 'drift'}, optional :param seed: A random seed. :type seed: int, optional :param progbar: Whether to show live progress. :type progbar: bool, optional :param inplace: Whether to perform the optimization inplace. :type inplace: bool, optional :rtype: ContractionTree .. py:function:: _do_anneal(tree, *args, **kwargs) .. py:function:: parallel_temper_tree(tree_or_trees, tfinal=0.01, tstart=1, tsteps=50, num_trees=8, numiter=50, minimize=None, target_size=None, slice_mode='drift', parallel_slice_mode='temperature', swappiness=1.0, max_time=None, seed=None, parallel='auto', info=None, progbar=False, inplace=False) Perform parallel tempering optimization of a contraction tree. This anneals ``num_trees`` different trees at a range of temperatures between ``tfinal`` and ``tstart``. After each step, trees are exchanged between neighboring temperatures according to the Metropolis-Hastings criterion. :param tree_or_trees: The tree or trees to optimize. If less than ``num_trees`` are given, then they will be cycled. If more than ``num_trees`` are given, then the length will override ``num_trees``. :type tree_or_trees: ContractionTree or sequence of ContractionTree :param tfinal: The final temperature. :type tfinal: float, optional :param tstart: The starting temperature. :type tstart: float, optional :param tsteps: The number of temperature steps, each with ``numiter`` iterations. After each step, trees are exchanged between neighboring temperatures. :type tsteps: int, optional :param num_trees: The number of trees and thus temperatures to optimize in parallel. :type num_trees: int, optional :param numiter: The number of iterations to perform at each step. The total number of sweeps (per parallel temperature) is ``numiter * tsteps``. :type numiter: int, optional :param minimize: The objective function to minimize. :type minimize: {'flops', 'combo', 'write', 'size', ...}, optional :param target_size: The target size of the contraction. :type target_size: int, optional :param slice_mode: The mode for slicing the contraction tree within each annealing iteration. :type slice_mode: {'basic', 'reslice', 'drift'}, optional :param parallel_slice_mode: The parallel mode for slicing the contraction tree. If 'temperature', then the target size decreases with temperature. If 'time', then the target size decreases with time. If 'constant', then the target size is constant. :type parallel_slice_mode: {'temperature', 'time', 'constant'}, optional :param seed: A random seed. :type seed: int, optional :param parallel: Whether to parallelize the search. :type parallel: 'auto', False, True, int, or distributed.Client :param progbar: Whether to show live progress. :type progbar: bool, optional :param inplace: Whether to perform the optimization inplace. :type inplace: bool, optional