API Reference
API Overview
This section is auto-generated from the Python docstrings using
mkdocstrings. It always reflects the latest installed version of
quantumuq.
Core modules
DeepEnsemble
dataclass
Bases: UncertaintyMethod
Deep ensemble over a list of already trained predictors.
Source code in quantumuq/core/methods.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
NoiseProfile
dataclass
Probe prediction stability as a function of shots.
For each value in sweep_shots, the predictor is evaluated n_repeats
times and stability statistics are computed.
Source code in quantumuq/core/methods.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
ShotBootstrap
dataclass
Bases: UncertaintyMethod
Repeated forward passes with (optionally) varying shots.
This method is fully model-agnostic and works for both PennyLane and Qiskit
predictors, as long as they implement the :class:Predictor protocol.
Source code in quantumuq/core/methods.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
brier(y_true, p_pred)
Multiclass Brier score.
Source code in quantumuq/core/metrics.py
17 18 19 20 21 22 23 24 25 | |
ece(y_true, p_pred, n_bins=15)
Expected calibration error with equal-width bins.
Source code in quantumuq/core/metrics.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
gaussian_nll(y_true, mean, std, eps=1e-08)
Gaussian negative log-likelihood for regression.
Source code in quantumuq/core/metrics.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
nll(y_true, p_pred, eps=1e-12)
Multiclass negative log-likelihood.
Source code in quantumuq/core/metrics.py
6 7 8 9 10 11 12 13 14 | |
predictive_entropy(p_pred, eps=1e-12)
Predictive entropy from class probabilities.
Source code in quantumuq/core/metrics.py
50 51 52 53 54 55 56 | |
rmse(y_true, y_pred)
Root mean squared error.
Source code in quantumuq/core/metrics.py
59 60 61 62 63 64 | |
PredictiveDistribution
dataclass
Container for predictive samples and summary statistics.
Attributes:
| Name | Type | Description |
|---|---|---|
samples |
ndarray
|
Array of samples with shape |
mean |
ndarray
|
Mean over the sample dimension, shape |
std |
ndarray
|
Standard deviation over the sample dimension, same shape as |
Source code in quantumuq/core/predictors.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
entropy()
Predictive entropy for classification tasks.
Uses the mean class probabilities over samples and returns entropy
per data point with shape (N,).
Source code in quantumuq/core/predictors.py
68 69 70 71 72 73 74 75 76 77 78 79 80 | |
interval(alpha)
Return central prediction interval for given alpha.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Confidence level in (0, 1). E.g. |
required |
Source code in quantumuq/core/predictors.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
Predictor
Bases: Protocol
Protocol for quantum predictors used by UQ methods.
Implementations must expose:
task: either"classification"or"regression".predict(X, shots=None): point predictions.predict_proba(X, shots=None): class probabilities for classification.
Source code in quantumuq/core/predictors.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
UQModel
Wrap a base predictor with an uncertainty method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_predictor
|
Predictor
|
Object implementing the :class: |
required |
method
|
'UncertaintyMethod'
|
Callable that given |
required |
Source code in quantumuq/core/predictors.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
UncertaintyMethod
Bases: Protocol
Protocol for uncertainty methods compatible with :class:UQModel.
Source code in quantumuq/core/predictors.py
115 116 117 118 119 120 121 | |
stack_ensemble_samples(samples)
Utility to convert a sequence of per-model predictions into a distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples
|
Sequence[ndarray]
|
Sequence of arrays of identical shape |
required |
Source code in quantumuq/core/predictors.py
124 125 126 127 128 129 130 131 132 133 134 135 136 | |
Adapters
wrap_qnode(qnode, task, n_classes=None, params=None, postprocess=None, batched=False)
Wrap a PennyLane QNode as a QuantumUQ predictor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qnode
|
Any
|
PennyLane QNode. For classification it should return probabilities, logits, or expectations convertible to probabilities. |
required |
task
|
Literal['classification', 'regression']
|
Either |
required |
n_classes
|
Optional[int]
|
Number of classes for classification tasks. |
None
|
params
|
Optional[Any]
|
Optional trainable parameters; the QNode is expected to have signature
|
None
|
postprocess
|
Optional[PostprocessFn]
|
Optional function mapping raw outputs to probabilities (classification) or predictions (regression). If not provided for classification, a defensive normalization is applied, or softmax when outputs look like logits. |
None
|
batched
|
bool
|
If |
False
|
Source code in quantumuq/adapters/pennylane_adapter.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 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 | |
wrap_qiskit_estimator(estimator, circuit, observables, task, n_classes=None, params=None, feature_map=None, postprocess=None)
Wrap a Qiskit Estimator primitive as a predictor.
For classification, use one observable per class to obtain logits, and apply a softmax by default. For regression, use a single observable per data point and return expectations directly.
Source code in quantumuq/adapters/qiskit_adapter.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
wrap_qiskit_sampler(sampler, circuit, task='classification', n_classes=2, params=None, feature_map=None, bitstring_to_class=None)
Wrap a Qiskit Sampler primitive as a classification predictor.
Source code in quantumuq/adapters/qiskit_adapter.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |