quimb.tensor.contraction

Functions relating to tensor network contraction.

Attributes

Functions

get_contract_strategy()

Get the default contraction strategy - the option supplied as

set_contract_strategy(strategy)

Get the default contraction strategy - the option supplied as

contract_strategy(strategy[, set_globally])

A context manager to temporarily set the default contraction strategy

empty_symbol_map()

Get a default dictionary that will populate with symbol entries as they

inds_to_symbols(inputs)

Map a sequence of inputs terms, containing any hashable indices, to

inds_to_eq(inputs[, output])

Turn input and output indices of any sort into a single 'equation'

get_contract_backend()

Get the default backend used for tensor contractions, via 'cotengra'.

set_contract_backend(backend)

Set the default backend used for tensor contractions, via 'cotengra'.

contract_backend(backend[, set_globally])

A context manager to temporarily set the default backend used for tensor

get_tensor_linop_backend()

Get the default backend used for tensor network linear operators, via

set_tensor_linop_backend(backend)

Set the default backend used for tensor network linear operators, via

tensor_linop_backend(backend[, set_globally])

A context manager to temporarily set the default backend used for tensor

array_contract(arrays, inputs[, output, optimize, backend])

array_contract_expression(*args[, optimize])

array_contract_tree(*args[, optimize])

array_contract_path(*args[, optimize])

array_contract_pathinfo(*args, **kwargs)

Module Contents

quimb.tensor.contraction._CONTRACT_STRATEGY = 'greedy'
quimb.tensor.contraction._TEMP_CONTRACT_STRATEGIES
quimb.tensor.contraction.get_contract_strategy()[source]

Get the default contraction strategy - the option supplied as optimize to cotengra.

quimb.tensor.contraction.set_contract_strategy(strategy)[source]

Get the default contraction strategy - the option supplied as optimize to cotengra.

quimb.tensor.contraction.contract_strategy(strategy, set_globally=False)[source]

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.

Parameters:

set_globally (bool, optimize) – 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.

quimb.tensor.contraction.get_symbol[source]
quimb.tensor.contraction.empty_symbol_map()[source]

Get a default dictionary that will populate with symbol entries as they are accessed.

quimb.tensor.contraction.inds_to_symbols(inputs)[source]

Map a sequence of inputs terms, containing any hashable indices, to single unicode letters, appropriate for einsum.

Parameters:

inputs (sequence of sequence of hashable) – The input indices per tensor.

Returns:

symbols – The mapping from index to symbol.

Return type:

dict[hashable, str]

quimb.tensor.contraction.inds_to_eq(inputs, output=None)[source]

Turn input and output indices of any sort into a single ‘equation’ string where each index is a single ‘symbol’ (unicode character).

Parameters:
  • inputs (sequence of sequence of hashable) – The input indices per tensor.

  • output (sequence of hashable) – The output indices.

Returns:

eq – The string to feed to einsum/contract.

Return type:

str

quimb.tensor.contraction._CONTRACT_BACKEND = None
quimb.tensor.contraction._TENSOR_LINOP_BACKEND = None
quimb.tensor.contraction._TEMP_CONTRACT_BACKENDS
quimb.tensor.contraction._TEMP_TENSOR_LINOP_BACKENDS
quimb.tensor.contraction.get_contract_backend()[source]

Get the default backend used for tensor contractions, via ‘cotengra’.

quimb.tensor.contraction.set_contract_backend(backend)[source]

Set the default backend used for tensor contractions, via ‘cotengra’.

quimb.tensor.contraction.contract_backend(backend, set_globally=False)[source]

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.

Parameters:

set_globally (bool, optimize) – 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.

quimb.tensor.contraction.get_tensor_linop_backend()[source]

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.

quimb.tensor.contraction.set_tensor_linop_backend(backend)[source]

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.

quimb.tensor.contraction.tensor_linop_backend(backend, set_globally=False)[source]

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.

Parameters:

set_globally (bool, optimize) – 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.

quimb.tensor.contraction.array_contract(arrays, inputs, output=None, optimize=None, backend=None, **kwargs)[source]
quimb.tensor.contraction.array_contract_expression(*args, optimize=None, **kwargs)[source]
quimb.tensor.contraction.array_contract_tree(*args, optimize=None, **kwargs)[source]
quimb.tensor.contraction.array_contract_path(*args, optimize=None, **kwargs)[source]
quimb.tensor.contraction.array_contract_pathinfo(*args, **kwargs)[source]