qrunch.quantum.sub_creators.sampler_algorithm_creators
Creator functions for tensor network sampler algorithms.
Module Attributes
Type alias for a factory that creates a TensorNetworkSamplerAlgorithm given an optional path finder. |
Functions
Create the default tensor network sampler algorithm using gate-by-gate with opt_einsum. |
|
|
Create the default tensor network sampler algorithm with an optional contraction path finder. |
|
Create a gate-by-gate sampler algorithm with an opt_einsum contraction calculator. |
|
Create a gate-by-gate sampler algorithm with a cuTensorNet contraction calculator. |
Create a gate-by-gate sampler algorithm, using real tensors unless the calculator stores complex tensors. |
Classes
Sub-creator for choosing tensor network sampler algorithm. |
- SamplerAlgorithmFactory
Type alias for a factory that creates a TensorNetworkSamplerAlgorithm given an optional path finder.
alias of
Callable[[GraphTensorNetworkContractionPathFinder|None],TensorNetworkSamplerAlgorithm]
- class TensorNetworkSamplerAlgorithmSubCreator
Bases:
Generic[T]Sub-creator for choosing tensor network sampler algorithm.
- __init__(parent: T, field_name: str) None
Initialize the sub-creator.
- Parameters:
parent (T) – The parent object to which the sampler 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(sampler_algorithm: TensorNetworkSamplerAlgorithm) T
Use a custom sampler algorithm.
- Parameters:
sampler_algorithm (TensorNetworkSamplerAlgorithm) – Custom tensor network sampler algorithm to use.
- Return type:
T
- custom_contraction_calculator(contraction_calculator: GraphTensorNetworkContractionCalculator) T
Use a custom contraction calculator with the default sampler algorithm.
The sampler uses the path finder already configured on the calculator. Primary and fallback path finders selected on the builder do not override it. When configuring an estimator’s sampler, this does not change the path finder used by the estimator algorithm itself.
- Parameters:
contraction_calculator (GraphTensorNetworkContractionCalculator) – The custom contraction calculator to use.
- Return type:
T
- exact_cpu(precision: Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'bfloat16'] = 'float64') T
Use the default exact CPU sampler.
Real precisions use real tensors, which require a real circuit and can not measure in the Y basis. Use
precision="complex128"orprecision="complex64"for circuits with complex relative phases, such as qDRIFT circuits.- Parameters:
precision (Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'bfloat16']) – Data type for tensor computations.
- Return type:
T
- exact_gpu(precision: Literal['float64', 'float32', '3x_tfloat32', 'tfloat32', 'float16', 'bfloat16'] = 'float32') T
Use the default exact GPU sampler.
The GPU sampler uses real tensors, which require a real circuit and can not measure in the Y basis. For circuits with complex relative phases, use
exact_cpu(precision="complex128")instead.- Parameters:
precision (Literal['float64', 'float32', '3x_tfloat32', 'tfloat32', 'float16', 'bfloat16']) – Data type for tensor computations.
- Return type:
T
- Requirements:
Qrunch install requirements: qrunch[cuda] (or qrunch[all]).
A working cuda (cupy) installation.
- default_sampler_algorithm() TensorNetworkSamplerAlgorithm
Create the default tensor network sampler algorithm using gate-by-gate with opt_einsum.
- Return type:
TensorNetworkSamplerAlgorithm
- default_sampler_algorithm_factory(path_finder: GraphTensorNetworkContractionPathFinder | None) TensorNetworkSamplerAlgorithm
Create the default tensor network sampler algorithm with an optional contraction path finder.
Uses a gate-by-gate sampler algorithm with opt_einsum contraction calculator.
- Parameters:
path_finder (GraphTensorNetworkContractionPathFinder | None) – Optional contraction path finder for determining contraction order.
- Return type:
TensorNetworkSamplerAlgorithm
- exact_cpu_sampler_algorithm(path_finder: GraphTensorNetworkContractionPathFinder | None, precision: Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'bfloat16']) TensorNetworkSamplerAlgorithm
Create a gate-by-gate sampler algorithm with an opt_einsum contraction calculator.
- Parameters:
path_finder (GraphTensorNetworkContractionPathFinder | None) – Optional contraction path finder for determining contraction order.
precision (Literal['complex128', 'complex64', 'float64', 'float32', 'float16', 'bfloat16']) – Data type for tensor computations.
- Return type:
TensorNetworkSamplerAlgorithm
- exact_gpu_sampler_algorithm(path_finder: GraphTensorNetworkContractionPathFinder | None, precision: Literal['float64', 'float32', '3x_tfloat32', 'tfloat32', 'float16', 'bfloat16']) TensorNetworkSamplerAlgorithm
Create a gate-by-gate sampler algorithm with a cuTensorNet contraction calculator.
Tensors are stored as float64 for float64 precision, and as float32 otherwise.
- Parameters:
path_finder (GraphTensorNetworkContractionPathFinder | None) – Optional contraction path finder for determining contraction order.
precision (Literal['float64', 'float32', '3x_tfloat32', 'tfloat32', 'float16', 'bfloat16']) – Data type for tensor computations.
- Return type:
TensorNetworkSamplerAlgorithm
- sampler_algorithm_with_contraction_calculator(contraction_calculator: GraphTensorNetworkContractionCalculator) TensorNetworkSamplerAlgorithm
Create a gate-by-gate sampler algorithm, using real tensors unless the calculator stores complex tensors.
- Parameters:
contraction_calculator (GraphTensorNetworkContractionCalculator) – The contraction calculator to use.
- Return type:
TensorNetworkSamplerAlgorithm