qrunch.tools.mpi.contraction_calculators

Re-exports of MPI contraction calculators.

class MpiCutensornetTensorNetworkContractionCalculator

Bases: GraphTensorNetworkContractionCalculator

Contracts tensor networks using NVIDIA cuTensorNet library.

GPU-accelerated tensor network contraction using cuTensorNet with support for automatic optimization and autotuning.

Every rank keeps the prepared network of the last contraction, so contracting a network with the same structure again, e.g. when estimating with new parameters, only uploads and broadcasts the new tensor values before contracting. All networks share one cuTensorNet handle.

Requirements:
  • Qrunch install requirements: qrunch[cuda] (or qrunch[all]).

  • A working cuda (cupy) installation.

__init__(root: int | None = None, comm: MPI.Comm | None = None, contraction_path_finder: GraphTensorNetworkContractionPathFinder | None = None, options: MpiCutensornetTensorNetworkContractionCalculatorOptions | None = None) → None

Create CutensornetTensorNetworkContractionCalculator.

Parameters:
  • root (int | None) – mpi root id

  • comm (MPI.Comm | None) – mpi comm handle

  • contraction_path_finder (GraphTensorNetworkContractionPathFinder | None) – Optional path finder for determining contraction order. Defaults to greedy Boltzmann bisection with the beast-braket preset unless optimizer options are provided. Every rank runs the path finder and the path with the lowest FLOP count is used, skipping ranks where it fails. Leave the seed unset so ranks search differently, unless identical paths are wanted, e.g. for scaling comparisons. The path finder may use all CPU cores, so if several ranks share a node, limit its threads on each rank, e.g. with RAYON_NUM_THREADS for the Rust path finders or OMP_NUM_THREADS for OpenMP based ones.

  • options (MpiCutensornetTensorNetworkContractionCalculatorOptions | None) – Configuration options for the calculator.

Return type:

None

property calculator_data: ContractionCalculatorData

Running resource-usage statistics accumulated across contractions performed so far.

property compute_data_type: Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'tfloat32', '3x_tfloat32', 'bfloat16']

Data type used for contracting tensors.

contract(tensor_network: GraphTensorNetworkData) → ContractionResult

Contract the tensor network to compute the final result.

Parameters:

tensor_network (GraphTensorNetworkData) – Tensors, connectivity and batch data of the graph tensor network to contract.

Return type:

ContractionResult

reset_calculator_data() → None

Reset the accumulated resource-usage statistics.

Return type:

None

serve_forever() → None

Start the worker event loop on a non-root rank, analogous to a network server.

Call this once on every non-root rank after creating the calculator. It blocks indefinitely, handling commands broadcast by the root rank (e.g. contract()) until the root calls shutdown(). The typical pattern is:

if rank == root:
    try:
        run_calculation(calculator, ...)  # Calls calculator.contract as many times as needed
    finally:
        calculator.shutdown()
else:
    calculator.serve_forever()  # Blocks until shutdown
Return type:

None

shutdown() → None

Signal all worker ranks to exit their serve_forever loop, and free the kept network on all ranks.

Return type:

None

property storage_data_type: Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'tfloat32', '3x_tfloat32', 'bfloat16']

Data type used for storing tensors.

with_data_types(storage_data_type: Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'tfloat32', '3x_tfloat32', 'bfloat16'], compute_data_type: Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'tfloat32', '3x_tfloat32', 'bfloat16']) → MpiCutensornetTensorNetworkContractionCalculator

Create a copy of the calculator instance using the specified data types.

Parameters:
  • storage_data_type (Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'tfloat32', '3x_tfloat32', 'bfloat16']) – Data type name for storing tensors (e.g., ‘float32’).

  • compute_data_type (Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'tfloat32', '3x_tfloat32', 'bfloat16']) – Data type name for tensor computations (e.g., ‘tfloat32’).

Return type:

MpiCutensornetTensorNetworkContractionCalculator

class MpiCutensornetTensorNetworkContractionCalculatorOptions

Bases: DataclassPublicAPI

Configuration options for cuTensorNet contraction calculator.

Note that the network and optimizer options are only meant for expert users, and to have a better understanding of what is possible, you might want to read cuquantum’s own documentation.

Parameters:
  • network_options – Optional cuTensorNet network configuration. The handle and device id are given by the MPI rank, so they must not be set. (default=None)

  • optimizer_options – Optional cuTensorNet optimizer configuration. (default=None)

  • storage_data_type – Data type for storing tensors on the GPU. (default=’float32’)

  • compute_data_type – Data type for arithmetic during contraction. (default=’float32’)

  • autotune_iterations – Number of autotuning iterations, where 0 disables autotuning. Autotuning rarely speeds up the contraction by more than a few percent, so it is disabled by default. (default=0)

  • autotune_flops_threshold – Only networks estimated to need at least this many floating point operations on each rank in a contraction call, i.e. for the slices of the rank and all batches, are autotuned, since autotuning runs the contraction several times and only pays off for expensive networks. (default=1e15)

  • seed – Optional random seed for the cuTensorNet optimizer. Each rank derives a unique seed from this. Only used when cuTensorNet finds the contraction path itself, i.e. when no contraction path finder is given, which requires optimizer options to be given. A contraction path finder has its own seed. (default=None)

  • fix_seed – Use the same seed on all ranks instead of one seed for each rank. Like seed, only used when no contraction path finder is given. (default=False)

Requirements:
  • Qrunch install requirements: qrunch[cuda] (or qrunch[all]).

  • A working cuda (cupy) installation.

__init__(*, network_options: NetworkOptions | None = None, optimizer_options: OptimizerOptions | None = None, storage_data_type: Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'tfloat32', '3x_tfloat32', 'bfloat16'] = 'float32', compute_data_type: Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'tfloat32', '3x_tfloat32', 'bfloat16'] = 'float32', autotune_iterations: int = 0, autotune_flops_threshold: float = 1000000000000000.0, seed: int | None = None, fix_seed: bool = False) → None
Parameters:
  • network_options (NetworkOptions | None)

  • optimizer_options (OptimizerOptions | None)

  • storage_data_type (Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'tfloat32', '3x_tfloat32', 'bfloat16'])

  • compute_data_type (Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'tfloat32', '3x_tfloat32', 'bfloat16'])

  • autotune_iterations (int)

  • autotune_flops_threshold (float)

  • seed (int | None)

  • fix_seed (bool)

Return type:

None

autotune_flops_threshold: float = 1000000000000000.0
autotune_iterations: int = 0
compute_data_type: Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'tfloat32', '3x_tfloat32', 'bfloat16'] = 'float32'
fix_seed: bool = False
network_options: NetworkOptions | None = None
optimizer_options: OptimizerOptions | None = None
seed: int | None = None
storage_data_type: Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'tfloat32', '3x_tfloat32', 'bfloat16'] = 'float32'