cuquantum.contract_path¶
- cuquantum.contract_path(subscripts, *operands, options=None, optimize=None)[source]¶
Evaluate the “best” contraction order by allowing the creation of intermediate tensors.
Explicit as well as implicit form is supported for the Einstein summation expression. In addition to the subscript format, the interleaved format is also supported as a means of specifying the operands and their mode labels. See
Network
for more detail on the types of operands as well as for examples.- Parameters
subscripts – The mode labels (subscripts) defining the Einstein summation expression as a comma-separated sequence of characters. Unicode characters are allowed in the expression thereby expanding the size of the tensor network that can be specified using the Einstein summation convention.
operands – A sequence of tensors (ndarray-like objects). The currently supported types are
numpy.ndarray
,cupy.ndarray
, andtorch.Tensor
.qualifiers – Specify the tensor qualifiers as a
numpy.ndarray
oftensor_qualifiers_dtype
objects of length equal to the number of operands.options – Specify options for the tensor network as a
NetworkOptions
object. Alternatively, adict
containing the parameters for theNetworkOptions
constructor can also be provided. If not specified, the value will be set to the default-constructedNetworkOptions
object.optimize – This parameter specifies options for path optimization as an
OptimizerOptions
object. Alternatively, a dictionary containing the parameters for theOptimizerOptions
constructor can also be provided. If not specified, the value will be set to the default-constructedOptimizerOptions
object.
- Returns
A 2-tuple (
path
,opt_info
):path
: A sequence of pairs of operand ordinals representing the best contraction order in thenumpy.einsum_path()
format.opt_info
: An object of typeOptimizerInfo
containing information about the best contraction order.
- Return type
Note
It is encouraged for users to maintain the library handle themselves so as to reduce the context initialization time:
from cuquantum import cutensornet as cutn from cuquantum import contract, NetworkOptions handle = cutn.create() network_opts = NetworkOptions(handle=handle, ...) path, info = contract_path(..., options=network_opts, ...) # ... the same handle can be reused for further calls ... # when it's done, remember to destroy the handle cutn.destroy(handle)
Note
Users may use this API to compute path without device memory allocation. One way to achieve this is via dummy
cupy.ndarray
operands, e.g, path finding without dummy arrays.