qten.precision
Module reference for qten.precision.
precision
Global numeric precision configuration for QTen.
This module stores the default floating and complex dtypes used by QTen helper functions when constructing NumPy arrays and PyTorch tensors. The configuration keeps NumPy and PyTorch precision choices paired so real and complex values use consistent 32-bit or 64-bit families throughout geometry, tensor, and physics workflows.
The default precision is 64-bit: torch.float64, torch.complex128,
np.float64, and np.complex128.
PrecisionInput
module-attribute
PrecisionInput = Union[
Literal["32", "64"], int, dtype, dtype
]
PrecisionInfo
module-attribute
PrecisionInfo = namedtuple(
"PrecisionInfo",
[
"torch_float",
"torch_complex",
"np_float",
"np_complex",
],
)
Container describing the active real and complex dtype family.
Attributes:
| Name | Type | Description |
|---|---|---|
torch_float |
dtype
|
PyTorch real floating dtype. |
torch_complex |
dtype
|
PyTorch complex dtype paired with |
np_float |
dtype
|
NumPy real floating dtype. |
np_complex |
dtype
|
NumPy complex dtype paired with |
set_precision
set_precision(
precision: PrecisionInput,
set_torch_default: bool = True,
) -> None
Set QTen's global real and complex dtype family.
The selected precision updates the dtype values returned by
get_precision_config(). When
set_torch_default=True, it also calls torch.set_default_dtype() with the
selected real PyTorch dtype.
Supported values
"32"or32: usetorch.float32,torch.complex64,np.float32, andnp.complex64."64"or64: usetorch.float64,torch.complex128,np.float64, andnp.complex128.- A supported real or complex
torch.dtypeselects its matching dtype family. - A supported real or complex
np.dtypeor NumPy scalar dtype selects its matching dtype family.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
precision
|
PrecisionInput
|
Precision selector describing the desired 32-bit or 64-bit dtype family. |
required |
set_torch_default
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
None
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/qten/precision.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
get_precision_config
get_precision_config() -> PrecisionInfo
Return QTen's current global precision configuration.
Returns:
| Type | Description |
|---|---|
PrecisionInfo
|
Named tuple with fields |
See Also
set_precision(precision, set_torch_default)
Update the stored precision configuration.
Source code in src/qten/precision.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |