quimb.tensor.contraction ======================== .. py:module:: quimb.tensor.contraction .. autoapi-nested-parse:: Functions relating to tensor network contraction. Attributes ---------- .. autoapisummary:: quimb.tensor.contraction._CONTRACT_STRATEGY quimb.tensor.contraction._TEMP_CONTRACT_STRATEGIES quimb.tensor.contraction.get_symbol quimb.tensor.contraction._CONTRACT_BACKEND quimb.tensor.contraction._TENSOR_LINOP_BACKEND quimb.tensor.contraction._TEMP_CONTRACT_BACKENDS quimb.tensor.contraction._TEMP_TENSOR_LINOP_BACKENDS Functions --------- .. autoapisummary:: quimb.tensor.contraction.get_contract_strategy quimb.tensor.contraction.set_contract_strategy quimb.tensor.contraction.contract_strategy quimb.tensor.contraction.empty_symbol_map quimb.tensor.contraction.inds_to_symbols quimb.tensor.contraction.inds_to_eq quimb.tensor.contraction.get_contract_backend quimb.tensor.contraction.set_contract_backend quimb.tensor.contraction.contract_backend quimb.tensor.contraction.get_tensor_linop_backend quimb.tensor.contraction.set_tensor_linop_backend quimb.tensor.contraction.tensor_linop_backend quimb.tensor.contraction.array_contract quimb.tensor.contraction.array_contract_expression quimb.tensor.contraction.array_contract_tree quimb.tensor.contraction.array_contract_path quimb.tensor.contraction.array_contract_pathinfo Module Contents --------------- .. py:data:: _CONTRACT_STRATEGY :value: 'greedy' .. py:data:: _TEMP_CONTRACT_STRATEGIES .. py:function:: get_contract_strategy() Get the default contraction strategy - the option supplied as ``optimize`` to ``cotengra``. .. py:function:: set_contract_strategy(strategy) Get the default contraction strategy - the option supplied as ``optimize`` to ``cotengra``. .. py:function:: contract_strategy(strategy, set_globally=False) A context manager to temporarily set the default contraction strategy supplied as ``optimize`` to ``cotengra``. By default, this only sets the contract strategy for the current thread. :param set_globally: Whether to set the strategy just for this thread, or for all threads. If you are entering the context, *then* using multithreading, you might want ``True``. :type set_globally: bool, optimize .. py:data:: get_symbol .. py:function:: empty_symbol_map() Get a default dictionary that will populate with symbol entries as they are accessed. .. py:function:: inds_to_symbols(inputs) Map a sequence of inputs terms, containing any hashable indices, to single unicode letters, appropriate for einsum. :param inputs: The input indices per tensor. :type inputs: sequence of sequence of hashable :returns: **symbols** -- The mapping from index to symbol. :rtype: dict[hashable, str] .. py:function:: inds_to_eq(inputs, output=None) Turn input and output indices of any sort into a single 'equation' string where each index is a single 'symbol' (unicode character). :param inputs: The input indices per tensor. :type inputs: sequence of sequence of hashable :param output: The output indices. :type output: sequence of hashable :returns: **eq** -- The string to feed to einsum/contract. :rtype: str .. py:data:: _CONTRACT_BACKEND :value: None .. py:data:: _TENSOR_LINOP_BACKEND :value: None .. py:data:: _TEMP_CONTRACT_BACKENDS .. py:data:: _TEMP_TENSOR_LINOP_BACKENDS .. py:function:: get_contract_backend() Get the default backend used for tensor contractions, via 'cotengra'. .. seealso:: :py:obj:`set_contract_backend`, :py:obj:`get_tensor_linop_backend`, :py:obj:`set_tensor_linop_backend`, :py:obj:`tensor_contract` .. py:function:: set_contract_backend(backend) Set the default backend used for tensor contractions, via 'cotengra'. .. seealso:: :py:obj:`get_contract_backend`, :py:obj:`set_tensor_linop_backend`, :py:obj:`get_tensor_linop_backend`, :py:obj:`tensor_contract` .. py:function:: contract_backend(backend, set_globally=False) A context manager to temporarily set the default backend used for tensor contractions, via 'cotengra'. By default, this only sets the contract backend for the current thread. :param set_globally: Whether to set the backend just for this thread, or for all threads. If you are entering the context, *then* using multithreading, you might want ``True``. :type set_globally: bool, optimize .. py:function:: get_tensor_linop_backend() Get the default backend used for tensor network linear operators, via 'cotengra'. This is different from the default contraction backend as the contractions are likely repeatedly called many times. .. seealso:: :py:obj:`set_tensor_linop_backend`, :py:obj:`set_contract_backend`, :py:obj:`get_contract_backend`, :py:obj:`TNLinearOperator` .. py:function:: set_tensor_linop_backend(backend) Set the default backend used for tensor network linear operators, via 'cotengra'. This is different from the default contraction backend as the contractions are likely repeatedly called many times. .. seealso:: :py:obj:`get_tensor_linop_backend`, :py:obj:`set_contract_backend`, :py:obj:`get_contract_backend`, :py:obj:`TNLinearOperator` .. py:function:: tensor_linop_backend(backend, set_globally=False) A context manager to temporarily set the default backend used for tensor network linear operators, via 'cotengra'. By default, this only sets the contract backend for the current thread. :param set_globally: Whether to set the backend just for this thread, or for all threads. If you are entering the context, *then* using multithreading, you might want ``True``. :type set_globally: bool, optimize .. py:function:: array_contract(arrays, inputs, output=None, optimize=None, backend=None, **kwargs) .. py:function:: array_contract_expression(*args, optimize=None, **kwargs) .. py:function:: array_contract_tree(*args, optimize=None, **kwargs) .. py:function:: array_contract_path(*args, optimize=None, **kwargs) .. py:function:: array_contract_pathinfo(*args, **kwargs)