tn_noise_learning.trainer#
Stochastic gradient descent on the Kraus tensors of an LPDO with optax and JAX.
Trainer #
Trainer(config: TrainingConfig | None = None)
Fit an LPDO to a NoiseDataset.
Source code in src/tn_noise_learning/trainer.py
143 144 | |
fit #
fit(
model: LPDO,
train: NoiseDataset,
test: NoiseDataset | None = None,
ideal_channel: LPDO | None = None,
) -> History
Train model in place and return the training history.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
initial LPDO; on return it holds the parameters of the best epoch.
TYPE:
|
train
|
training shots; its circuit is applied inside the loss.
TYPE:
|
test
|
held-out shots; split off
TYPE:
|
ideal_channel
|
ground truth to report
TYPE:
|
Source code in src/tn_noise_learning/trainer.py
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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
TrainingConfig
dataclass
#
TrainingConfig(
epochs: int = 50,
batch_size: int = 256,
learning_rate: ScalarOrSchedule = (
lambda: optax.exponential_decay(
0.01, 200, 0.8, end_value=0.0001
)
)(),
optimizer: Callable[
[ScalarOrSchedule], GradientTransformation
] = optax.adam,
tp_weight: Schedule = 100.0,
tp_warmstart_steps: int = 500,
tp_project_every: int | None = None,
tp_project_steps: int = 50,
extra_loss_terms: dict[
str, tuple[LossTerm, Schedule]
] = dict(),
metrics: dict[str, Metric] = dict(),
monitor: str = "test_loss",
patience: int = 10,
tolerance: float = 0.0001,
test_fraction: float = 0.1,
seed: int = 0,
snapshot_params: bool = False,
log_every: int = 1,
contract_optimize: str = "auto-hq",
)
Hyper-parameters of Trainer.
| PARAMETER | DESCRIPTION |
|---|---|
epochs
|
maximum number of passes over the training set.
TYPE:
|
batch_size
|
shots per gradient step; every batch has exactly this size.
TYPE:
|
learning_rate
|
constant, optax schedule, or callable of the step index; defaults to an exponential decay
from
TYPE:
|
optimizer
|
factory turning the learning rate into an optax optimizer.
TYPE:
|
tp_weight
|
weight of the trace-preservation penalty, constant or callable of the step index. The trained
trace exceeds
TYPE:
|
tp_warmstart_steps
|
L-BFGS-B steps moving the initial model onto the trace-preserving manifold (0 disables).
TYPE:
|
tp_project_every
|
re-run the L-BFGS-B projection every this many steps (
TYPE:
|
tp_project_steps
|
L-BFGS-B steps per projection.
TYPE:
|
extra_loss_terms
|
|
metrics
|
|
monitor
|
metric used for early stopping and model selection.
TYPE:
|
patience
|
epochs without improvement of
TYPE:
|
tolerance
|
minimum decrease of
TYPE:
|
test_fraction
|
held-out fraction used when
TYPE:
|
seed
|
seed for the train/test split and batch shuffling.
TYPE:
|
snapshot_params
|
record the Kraus tensors after every epoch in the history.
TYPE:
|
log_every
|
log one line every this many epochs.
TYPE:
|
contract_optimize
|
cotengra path optimizer for the loss contraction.
TYPE:
|
evaluate_schedule #
evaluate_schedule(schedule: Schedule, step: int) -> float
Value of a constant or step-dependent schedule.
Source code in src/tn_noise_learning/trainer.py
44 45 46 47 48 | |
project_trace_preserving #
project_trace_preserving(model: LPDO, steps: int) -> LPDO
Minimise the trace-preservation penalty alone with L-BFGS-B, starting from model.
Source code in src/tn_noise_learning/trainer.py
100 101 102 103 104 105 106 107 108 109 110 111 | |