cuquantum.cutensornet.contraction_optimizer_info_get_attribute_dtype

cuquantum.cutensornet.contraction_optimizer_info_get_attribute_dtype(int attr)

Get the Python data type of the corresponding optimizer info attribute.

Parameters

attr (ContractionOptimizerInfoAttribute) – The attribute to query.

Returns

The data type of the queried attribute.

Note

This API has no C counterpart and is a convenient helper for allocating memory for contraction_optimizer_info_get_attribute() and contraction_optimizer_info_set_attribute().

Note

Unlike other enum values, for ContractionOptimizerInfoAttribute.PATH the following usage pattern is expected:

val = ContractionOptimizerInfoAttribute.PATH
dtype = contraction_optimizer_info_get_attribute_dtype(val)

# setter
path = np.asarray([(1, 3), (1, 2), (0, 1)], dtype=np.int32)
path_obj = dtype(path.size//2, path.ctypes.data)
contraction_optimizer_info_set_attribute(
    handle, info, val, path_obj.get_data(), path_obj.get_size())

# getter
# num_contractions is the number of input tensors minus one
path = np.empty(2*num_contractions, dtype=np.int32)
path_obj = dtype(num_contractions, path.ctypes.data)
contraction_optimizer_info_get_attribute(
    handle, info, val, path_obj.get_data(), path_obj.get_size())
# now path is filled
print(path)

See also the documentation of ContractionPath. This design is subject to change in a future release.