Template Class TaskBasedContractor¶
Defined in File TaskBasedContractor.hpp
Class Documentation¶
-
template<class
TensorType>
classJet::TaskBasedContractor¶ TaskBasedContractor is a tensor network contractor that contracts tensors concurrently using a task-based scheduler.
- tparam Tensor
Type of the tensors to be contracted. The only requirement for this type is that the following member functions exist:
static Tensor AddTensors(const Tensor&, const Tensor&); static Tensor ContractTensors(const Tensor&, const Tensor&);
Public Types
-
using
NameToTaskMap= std::unordered_map<std::string, tf::Task>¶ Type of the name-to-task map.
-
using
NameToTensorMap= std::unordered_map<std::string, std::unique_ptr<TensorType>>¶ Type of the name-to-tensor map.
-
using
NameToParentsMap= std::unordered_map<std::string, std::unordered_set<std::string>>¶ Type of the name-to-parents map.
-
using
TaskFlow= tf::Taskflow¶ Type of the task dependency graph.
Public Functions
-
inline
TaskBasedContractor(size_t num_threads = std::thread::hardware_concurrency())¶ Constructs a new
TaskBasedContractorobject.
-
inline const NameToTaskMap &
GetNameToTaskMap() const noexcept¶ Returns the name-to-task map of this
TaskBasedContractor.- Returns
Map which associates names to tasks.
-
inline const NameToTensorMap &
GetNameToTensorMap() const noexcept¶ Returns the name-to-tensor map of this
TaskBasedContractor.- Returns
Map which associates names to tensors.
-
inline const NameToParentsMap &
GetNameToParentsMap() const noexcept¶ Returns the name-to-parents map of this
TaskBasedContractor.- Returns
Map which associates names to a vector of parent node IDs.
-
inline const std::vector<TensorType> &
GetResults() const noexcept¶ Returns the result of the final tensor contraction after each call to AddContractionTasks().
Note
These results are only accessible after the future returned by Contract() becomes available.
- Returns
Vector of tensors.
-
inline const TensorType &
GetReductionResult() const noexcept¶ Returns the reduction of the final tensor results.
- See
- See
Note
This result is only accessible after the future returned by Contract() becomes available.
- Returns
Tensor at the end of the reduction task.
-
inline const TaskFlow &
GetTaskflow() const noexcept¶ Returns the taskflow of this
TaskBasedContractor.- Returns
Taskflow instance representing the task dependency graph.
-
inline void
AddTaskflow(tf::Taskflow &taskflow) noexcept¶ Adds another Taskflow graph to this
TaskBasedContractor.Warning
This function does not update the values returned by GetFlops() or GetMemory().
-
inline double
GetFlops() const noexcept¶ Returns the number of floating-point operations needed to perform all the contraction tasks (assuming the tensor elements are floating-point numbers).
- Returns
Number of floating-point additions and multiplications.
-
inline double
GetMemory() const noexcept¶ Returns the memory required (up to a constant sizeof() factor) to simultaneously hold all the intermediate and final results of the contraction tasks.
- Returns
Number of elements in the non-leaf tensors.
-
inline size_t
AddContractionTasks(const TensorNetwork<TensorType> &tn, const PathInfo &path_info) noexcept¶ Adds contraction tasks for a tensor network.
- Parameters
tn – Tensor network to be contracted.
path_info – Contraction path through the tensor network.
- Returns
Number of contraction tasks that are shared with previous calls to this function.
-
inline size_t
AddReductionTask() noexcept¶ Adds a reduction task to sum the result tensors.
Warning
Only one reduction task should be added per
TaskBasedContractorinstance.- Returns
Number of created reduction tasks.
-
inline size_t
AddDeletionTasks() noexcept¶ Adds deletion tasks for intermediate tensors.
Each tensor that participates in a contraction will be paired with a deletion task which deallocates the tensor once it is no longer needed.
- Returns
Number of created deletion tasks.
-
inline std::future<void>
Contract()¶ Executes the tasks in this
TaskBasedContractor.- Returns
Future that becomes available once all the tasks have finished.