qrunch.quantum.sub_creators.estimator_algorithm_creators
Creator functions for tensor network estimator algorithms.
Module Attributes
Type alias for a factory that creates a TensorNetworkEstimatorAlgorithm given an optional path finder. |
Functions
Create the default tensor network estimator algorithm. |
|
|
Create the default tensor network estimator algorithm with an optional contraction path finder. |
Classes
Sub-creator for choosing tensor network estimator algorithm. |
- EstimatorAlgorithmFactory
Type alias for a factory that creates a TensorNetworkEstimatorAlgorithm given an optional path finder.
The factory also returns a sampler algorithm sharing the contraction calculator of the estimator algorithm, or None if the contraction calculator is not known.
alias of
Callable[[GraphTensorNetworkContractionPathFinder|None],tuple[TensorNetworkEstimatorAlgorithm,TensorNetworkSamplerAlgorithm|None]]
- class TensorNetworkEstimatorAlgorithmSubCreator
Bases:
Generic[T]Sub-creator for choosing tensor network estimator algorithm.
- __init__(parent: T, field_name: str) None
Initialize the sub-creator.
- Parameters:
parent (T) – The parent object to which the estimator algorithm factory will be stored.
field_name (str) – The name of the field in the parent object to which the factory will be assigned.
- Return type:
None
- custom(estimator_algorithm: TensorNetworkEstimatorAlgorithm) T
Use a custom estimator algorithm.
The sampler algorithm, used for estimation with shots and for exact basis state probabilities, can not be derived from a custom estimator algorithm. Choose it with choose_sampler_algorithm(), or the default CPU sampler algorithm is used.
- Parameters:
estimator_algorithm (TensorNetworkEstimatorAlgorithm) – The custom estimator algorithm to use.
- Return type:
T
- custom_contraction_calculator(contraction_calculator: GraphTensorNetworkContractionCalculator) T
Use a custom contraction calculator with the default estimator algorithm.
The calculator keeps its own path finder, including when it is shared with the sampler. Primary and fallback path finders selected on the builder do not override it.
- Parameters:
contraction_calculator (GraphTensorNetworkContractionCalculator) – The custom contraction calculator to use.
- Return type:
T
- exact_cpu(precision: Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'bfloat16', 'mixed'] = 'float64') T
Use the default exact CPU estimator.
The CPU estimator uses the CachingEstimatorAlgorithm with the GraphEstimatorAlgorithm as backing estimator algorithm.
If precision is “mixed”, uses MixedPrecisionEstimatorAlgorithm with default CPU precision tiers. The sampler shares the high-precision tier’s contraction calculator.
- Parameters:
precision (Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'bfloat16', 'mixed']) – Data type for tensor computations, or
"mixed"for mixed precision estimation.- Return type:
T
- exact_gpu(precision: Literal['float64', 'float32', '3x_tfloat32', 'tfloat32', 'float16', 'bfloat16', 'mixed'] = 'float32') T
Use the default exact GPU estimator.
The GPU estimator uses the CachingEstimatorAlgorithm with the GraphEstimatorAlgorithm as backing estimator algorithm.
If precision is “mixed”, uses MixedPrecisionEstimatorAlgorithm with GPU-appropriate precision tiers. The sampler shares the high-precision tier’s contraction calculator.
- Parameters:
precision (Literal['float64', 'float32', '3x_tfloat32', 'tfloat32', 'float16', 'bfloat16', 'mixed']) – Data type for tensor computations, or
"mixed"for mixed precision estimation.- Return type:
T
- Requirements:
Qrunch install requirements: qrunch[cuda] (or qrunch[all]).
A working cuda (cupy) installation.
- default_estimator_algorithm() TensorNetworkEstimatorAlgorithm
Create the default tensor network estimator algorithm.
Uses a caching estimator algorithm with the graph-based estimator, bra-ket builder, and opt_einsum contraction calculator.
- Return type:
TensorNetworkEstimatorAlgorithm
- default_estimator_algorithm_factory(path_finder: GraphTensorNetworkContractionPathFinder | None) tuple[TensorNetworkEstimatorAlgorithm, TensorNetworkSamplerAlgorithm]
Create the default tensor network estimator algorithm with an optional contraction path finder.
Uses a caching estimator algorithm with the graph-based estimator, bra-ket builder, and opt_einsum contraction calculator. Also returns a gate-by-gate sampler algorithm sharing the contraction calculator.
- Parameters:
path_finder (GraphTensorNetworkContractionPathFinder | None) – Optional contraction path finder for determining contraction order.
- Return type:
tuple[TensorNetworkEstimatorAlgorithm, TensorNetworkSamplerAlgorithm]