Meta Reference
module meta
function to_ssa_path
Convert a linear contraction path to the Single Static Assignment (SSA) form.
Args:
linear_path
(list): A list of tuples representing the linear contraction path.
Returns:
list
: A list of tuples representing the SSA form of the contraction path.
Raises:
RuntimeError
: If the path contains negative indices.RuntimeError
: If the path cannot be converted to SSA form.RuntimeError
: If the path contains repeating indices within a contraction pair.
function find_path
Optimize a path for evaluating an einsum expression.
Args:
format_string
(str): The Einstein summation notation expression.*tensors
: The input tensors.minimize
(Literal[“flops”, “size”]): The objective to minimize, either “flops” or “size”.n_trials
(int, optional): The number of trials for the optimization process. Defaults to 128.n_jobs
(int, optional): The number of parallel jobs to run. Defaults to 10.show_progress_bar
(bool, optional): Whether to show a progress bar during optimization. Defaults to True.timeout
(int, optional): The maximum time in seconds for the optimization process. Defaults to None.
Returns:
str
: An ssa path for evaluating the einsum expression.
function compute_meta_info_of_einsum_instance
Compute meta information for an einsum instance.
Args:
format_string
(str): The einsum format string.tensors
(list): A list of input tensors.
Returns:
Meta_Info_Instance
: An instance of the Meta_Info_Instance class containing the computed meta information. It has the following Attributes- tensors (int): The number of tensors involved in the computation.
- different_indices (int): The number of different indices in the computation.
- hadamard_products (int): The number of Hadamard products in the computation.
- edges (int): The number of contraction edges in the computation.
- hyperedges (int): The number of contraction hyperedges in the computation.
- tensors_in_largest_hyperedge (int): The number of tensors in the largest hyperedge in the computation.
- tensors_with_traces_or_diagonals (int): The number of tensors with traces or diagonals in the computation.
- independent_components (int): The number of independent components in the computation.
- tensors_in_largest_component (int): The number of tensors in the largest component in the computation.
- smallest_dimension_size (int): The size of the smallest dimension in the computation.
- largest_dimension_size (int): The size of the largest dimension in the computation.
- log2_output_size (float): The logarithm base 2 of the output size of the computation.
function get_ops_and_max_size
Calculates the total number of operations and the maximum size of intermediate tensors.
Calculates the total number of operations and the maximum size of intermediate tensors for a given format string, annotated SSA path, and input tensors.
Args:
format_string
(str): The format string specifying the input and output tensors.annotated_ssa_path
(list): A list of tuples representing the annotated SSA path.tensors
(tuple): Input tensors.size_dict
(dict, optional): A dictionary mapping characters in the format string to their sizes.
Returns:
tuple
: A tuple containing the logarithm base 10 of the total number of operations and the logarithm base 2 of the maximum size of intermediate tensors.
function to_annotated_ssa_path
Annote an SSA path with their pairwise einsum format string.
Args:
format_string
(str): The format string representing the einsum expression.ssa_path
(list): A list of tuples representing the SSA path indices.is_ascii
(bool, optional): Flag indicating whether to convert the annotated SSA path to ASCII characters. Defaults to False.
Returns:
list
: Annotated SSA path, where each element is a tuple containing the indices and pairwise format_string for each step in the SSA path.
function jensum
Perform a series of tensor contractions based on the annotated_ssa_path.
Args:
annotated_ssa_path
(list): A list of tuples representing the annotated SSA path.Each tuple contains three elements
: the indices of the tensors to contract, and the contraction expression.*arguments
: Variable number of tensor arguments.debug
(bool, optional): If True, print debug information during the contractions.
Returns: The final tensor resulting from the series of contractions.
Raises:
AssertionError
: If the number of contractions is less than 1.AssertionError
: If the number of tensors in arguments is less than 2.RuntimeError
: If the number of tensors in arguments contradicts the number of entries in annotated_ssa_path.
function jensum_meta
Compute the meta information and perform tensor contractions using the jensum algorithm.
Args:
annotated_ssa_path
(list): A list of tuples representing the annotated SSA path for each contraction.Each tuple contains three elements
: the indices of the tensors to contract, and the contraction expression.arguments
(tuple): The input tensors to be contracted.debug
(bool, optional): If True, debug information will be printed. Defaults to False.
Returns:
tuple
: A tuple containing the final contracted tensor and a list of meta information for each contraction. The list of meta information contains for each step, where A and B are input tensors and C is the output tensor:- The number of operations (flops).
- The sizes of the input tensors (size_A, size_B, size_C).
- The densities of the input and output tensors (density_A, density_B, density_C).
Raises:
AssertionError
: If the number of contractions is less than 1 or the number of tensors in arguments is less than 2.RuntimeError
: If the number of tensors in arguments contradicts the number of entries in annotated_ssa_path.RuntimeError
: If the density of a tensor cannot be computed due to missing size or numel() attribute.
function linear_path_runtime_meta
Compute the runtime metadata for a linear path.
This functions returns all metadata as given in the metadata.csv
Args:
format_string
(str): The format string specifying the einsum operation.linear_path
(str): The linear path representing the einsum operation.*arguments
: Variable length arguments for the einsum operation.debug
(bool, optional): Whether to enable debug mode. Defaults to False.
Returns:
tuple
: A tuple containing the result of the einsum expression, the execution time, the minimum density, and the average density.