qrunch.quantum.sub_creators.contraction_path_finder_creators

Sub-creator for configuring contraction path finders via the fluent builder chain.

Functions

path_finder_with_fallback(primary, fallback)

Compose the configured primary and optional fallback.

Classes

ContractionPathFinderSubCreator

Sub-creator for configuring contraction path finders.

class ContractionPathFinderSubCreator

Bases: Generic[T]

Sub-creator for configuring contraction path finders.

This sub-creator allows choosing a contraction path finder via the fluent builder chain, eliminating the need for deep internal imports.

__init__(parent: T, field_name: str, *, fallback_field_name: str | None = None, threshold: PathFinderThresholdOptions | None = None) → None

Initialize the sub-creator.

Parameters:
  • parent (T) – The parent object to which the path finder will be added.

  • field_name (str) – The name of the field in the parent object to which the path finder will be assigned.

  • fallback_field_name (str | None) – Field storing the optional fallback finder and primary threshold.

  • threshold (PathFinderThresholdOptions | None) – Primary acceptance threshold when choosing a fallback instead of a primary.

Return type:

None

greedy_boltzmann_bisection(options: GreedyBoltzmannBisectionContractionPathFinderOptions | None = None) → T

Use adaptive greedy, Boltzmann sampling and bisection search.

Combines integer-space greedy, log-space Boltzmann exploration and multi-level bisection, with optional index slicing to fit a memory budget.

Parameters:

options (GreedyBoltzmannBisectionContractionPathFinderOptions | None) – Configuration for the path finder. If None, the beast_braket option defaults are used. Pass GreedyBoltzmannBisectionContractionPathFinderOptions.beast_vectorized() for the vectorized tensor network builder.

Return type:

T

multi_strategy(*, max_memory_fraction: float = 0.8) → T

Use the multi-strategy contraction pathfinder.

Runs multiple strategies (random-greedy-128, auto-hq, cuTensorNet with various configurations including slicing) and returns the best path (lowest FLOPs) that fits within the memory budget. Falls back to slicing/memory-limited strategies if no path fits.

Note: Does not include a fast greedy heuristic. Choose a primary finder first, then use choose_fallback_contraction_path_finder(threshold=...).multi_strategy() to run this search only when the primary path exceeds resource limits.

Parameters:

max_memory_fraction (float) – Maximum fraction of system memory a path is allowed to use.

Return type:

T

none() → T

Clear the selected contraction path finder.

When choosing a primary, clear both primary and fallback and defer to the contraction calculator. When choosing a fallback, remove only the fallback.

Return type:

T

random_greedy_128() → T

Use the opt_einsum contraction pathfinder with random-greedy-128.

Return type:

T

path_finder_with_fallback(primary: GraphTensorNetworkContractionPathFinder | None, fallback: tuple[GraphTensorNetworkContractionPathFinder, PathFinderThresholdOptions] | None) → GraphTensorNetworkContractionPathFinder | None

Compose the configured primary and optional fallback.

Parameters:
  • primary (GraphTensorNetworkContractionPathFinder | None) – Primary finder, or None for the calculator’s default.

  • fallback (tuple[GraphTensorNetworkContractionPathFinder, PathFinderThresholdOptions] | None) – Fallback finder and the resource threshold for accepting the primary.

Return type:

GraphTensorNetworkContractionPathFinder | None