wikillm

Paper · 2021-04-27 · cs.LG, cond-mat.dis-nn, cs.ET, physics.optics

Deep physical neural networks enabled by a backpropagation algorithm for arbitrary physical systems

Physics-aware training (PAT) trains a chain of real physical systems with backpropagation. The forward pass runs on the hardware, and gradients come from a differentiable digital model. Shown on optical, mechanical and analog-circuit networks. Author-reported: 93% vowel accuracy with PAT versus about 40% for in silico training.

Hardware-aware trainingSurrogate modelingDifferentiable simulationphysical-neural-networksanalog-hardwareopticstraining-algorithm

arXivPDFCodeMarkdown9 min read

AI-compiled by claude-haiku-5-5 on 2026-10-19, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.

In plain words

Deep learning usually runs on digital chips that simulate every step of a neural network. Physical systems can do some of the same work directly: a beam of light, a vibrating metal plate or an electronic circuit transforms its input as it evolves, and that transformation can be fast and cheap. The problem is that real physical systems cannot be trained the usual way, because the computer cannot ask a physical system how its output would change if one knob moved a little.

The paper's answer is to let the real system compute the forward pass and to use a computer model of the system only for the backward pass, where the gradients are worked out. Stacking several such systems gives a deep network made of physical stages. The authors built three of these networks, from an optical crystal, a mechanical plate and an analog circuit, and trained them on small image and speech classification tasks.

TL;DR

  • Physics-aware training (PAT) runs the forward pass on the real hardware and estimates gradients with a differentiable digital model §Results app. S1.
  • Its main claim is that training a hardware-in-the-loop chain works where training purely in simulation does not fig. 3 §Results.
  • Results are author-reported on vowel and MNIST classification with three physical systems fig. 2 fig. 4.
  • The public repository is a simulation demo, not the experimental code, so the paper's hardware settings cannot be reproduced from it README.md.

Problem

Backpropagation needs the derivatives of every layer. A physical system's input-output map has no analytic derivative, and estimating it by finite differences costs one physical call per input and parameter, which is too slow for networks with many parameters app. S1. Training in simulation avoids that cost, but a digital model is never exact, and the errors compound through the layers, so the trained parameters fail on the real device §Results app. S1. The paper treats both failure modes as the problem to solve.

Method

Physics-aware training (PAT). Each physical stage is wrapped as an autodiff function with two behaviours. The forward pass uses the measured output of the physical system. The backward pass uses the derivatives of a differentiable digital model evaluated at the inputs that were actually measured app. S1. The error vector at the output is therefore exact, and the Jacobians are taken at the true intermediate signals instead of simulated ones app. S1. The paper describes the forward and backward equations for a single stage and for a feed-forward chain of stages app. S1. The chain form is the one the paper's multi-stage experiments use.

Digital model. The differentiable model is a fitted neural network. Its training data are input-output pairs measured on the physical system, usually about 10⁴ samples drawn uniformly, split into training and validation sets. The architecture is chosen by a neural architecture search with the Optuna package app. S2. The digital models also include a noise model fitted to repeated measurements app. S2.

Algorithm (feed-forward PNN, one update). The paper gives the loop as forward pass, error vector, backward pass and parameter update app. S1. The pseudocode below follows that loop. The paper's experiments used Adadelta rather than plain gradient descent app. S2.

Pseudocode
# Physics-aware training, one parameter update  [app. S1]
# Input:  batch of (x, y); N stages with physical map f_ph and
#         differentiable digital model f_mo; learning rate eta
# Output: updated parameters thetas[1..N]

def pat_update(batch_inputs, batch_targets, thetas):
    # Forward pass on the physical stages; keep each stage's input  [app. S1]
    stage_inputs = []
    activation = batch_inputs
    for stage in range(N):
        stage_inputs.append(activation)
        activation = f_ph(activation, thetas[stage])
    outputs = activation

    # Exact error vector at the output, from the measured output  [app. S1]
    grad_output = loss_gradient(outputs, batch_targets)

    # Backward pass: digital-model Jacobians at the measured inputs  [app. S1]
    grad_thetas = [None] * N
    for stage in reversed(range(N)):
        x = stage_inputs[stage]
        grad_thetas[stage] = vjp_theta(f_mo, x, thetas[stage], grad_output)
        grad_output = vjp_input(f_mo, x, thetas[stage], grad_output)

    # Gradient step, averaged over the batch  [app. S1]
    for stage in range(N):
        thetas[stage] = thetas[stage] - eta * grad_thetas[stage]
    return thetas

Autodiff wrapper. The paper's Listing 1 builds the wrapper for any forward and backward function pair app. S1. The public repository has the same construction, written for any number of arguments pat.py.

Pseudocode
# Autodiff wrapper for one physical stage  [code: pat.py#L22-L33]
# Forward: physical (or simulated) output; backward: digital-model VJP

class PhysicalStage(autodiff_function):
    def forward(ctx, *args):
        # Save the inputs for the backward pass  [code: pat.py#L24-L26]
        ctx.save(args)
        return f_forward(*args)

    def backward(ctx, grad_output):
        # Vector-Jacobian product of f_backward at the saved inputs
        # [code: pat.py#L27-L32]
        args = ctx.saved
        return vjp(f_backward, args, grad_output)[1]

Vowel classification with five SHG stages fig. 2. The formant vector is rescaled by trainable scalars, repeated four times to make 48 values, and concatenated with 52 trainable physical parameters to form the first 100-value control. Each SHG output (50 values) is renormalised by its maximum, given a trainable scale and offset, and concatenated with 50 new parameters for the next stage. The last stage's output is cropped to 21 values and summed in groups of three to give seven class scores app. S2. The loss is cross-entropy plus two bound penalties on the controls and inputs app. S2. The main text describes the same chain at a higher level fig. 1 fig. 2.

Mechanical PNN, MNIST fig. 4A-D. A 784-pixel image is fed as a time series to a metal plate driven by a speaker, three times in sequence, with a trainable element-wise rescaling before each pass §Results. The output is read from a short window of the microphone signal, split into ten bins, and the strongest bin gives the digit app. S2. The digital model for this system is linear, with no hidden layers app. S2.

Electronic PNN, MNIST fig. 4E-H. A transistor in an RLC oscillator is driven by a time-varying voltage. Seven three-stage sub-networks, each with trainable skip connections, are combined by a trainable weighted sum. The input is 196 pixels pooled to 14 values and repeated five times app. S2. The digital model is a four-hidden-layer network with swish activations app. S2.

Hybrid SHG PNN, MNIST fig. 4I-L. A trainable linear layer maps 196 pixels to 50 values and back to 196. Four independent channels each pass their input through two SHG stages, with skip connections, and each channel gives 70 values. The 280 values are summed in bins of 28 to give ten class scores, and a trainable softmax temperature is used during training app. S2.

Hyperparameters

NameValueWhereNotes
OptimizerAdadeltaapp. S2Chosen as the best of those tried; the paper hypothesises momentum may inhibit PAT.
Vowel PNN learning rate1.0, halved every 700 epochsapp. S2The total epoch count for this run is not stated.
Vowel PNN loss weightsλθ = 0.5, λx = 2, vmin = 0, vmax = 1app. S2Bound penalties on controls and inputs.
Vowel data12-D min-max scaled; 259 vowels; N_data = 257app. S2See Pitfalls. Split sizes not stated.
SHG digital model layers[100, 500, 1000, 300, 50]app. S2Adam; learning rate not stated for this model.
Architecture search space1 to 5 layers; widths 20 to 1500; initial learning rate 1e-5 to 1e-2app. S2Optuna search; swish activation.
Digital model training datausually about 10⁴ uniform samplesapp. S2Split into training and validation sets.
Numerical example model3 hidden layers of 1000, 500, 300 units; 2000 instancesapp. S1Simulated autocorrelation stage, not hardware.
Numerical example loss weightλ = 0.02, vmin = 0, vmax = 1app. S1Constraint on controls.
Electronic PNN learning rate0.75; 0.375 after 30 epochs; 0.28 after 45app. S2Adadelta.
Electronic digital model retrainingevery 2 epochs, on random 70-D inputs plus local dataapp. S2Compensates for drift of the circuit.
Electronic digital model[70, 217, 427, 167, 197, 70]; Adam, learning rate 4.56e-4app. S2Validation loss 0.09 on data scaled to [-1, 1].
Electronic PNN sub-networks7 sub-networks, 3 physical stages eachapp. S2Stages are 70-D.
Mechanical PNN digital modellinear (no hidden layers)app. S2Optimizer learning rate not stated.
SHG MNIST input layers196→50 and 50→196, linear, 4 channelsapp. S2Output bins of 28 values.
SHG operating rate200 Hz sustainedapp. S2Training needs millions of executions.
Training epochs and batch sizenot statedFor the three MNIST PNNs and the vowel PNN.

Results

Author-reported. Setup: each experiment is a physical system trained by PAT and evaluated on test data. Baselines are as listed. Dataset split sizes are not stated for the vowel task app. S2.

SettingMetricBaselineThis paperSource
SHG vowel PNN, five stagestest accuracyin silico training: about 40% at best (training curve)93%fig. 2C-D fig. 3B-C
Mechanical PNN, MNIST, three passestest accuracyidentity-replaced physics: about 10%87%fig. 4D §Results
Electronic PNN, MNISTtest accuracydigital-only baseline not stated93%fig. 4H §Results
Hybrid SHG PNN, MNISTtest accuracydigital operations alone: about 90%97%fig. 4L §Results
Numerical vowel example (simulated)test accuracyideal backpropagation: close to 96%about 96%app. S1

The paper's own comparison uses an identity baseline for the physics part. For the mechanical PNN, the paper describes its accuracy as close to that of a linear classifier §Results.

Paper vs code

  • The repository is a simulation demo. Its docstring says the forward pass uses "a simulation for convenience" pat.py. Its README says the paper "demonstrated the methodology on real experiments" README.md. The experimental code is not in this repository.
  • The paper's data and code statement points to a Zenodo record (10.5281/zenodo.4719150) §Data and code availability. It was not checked for this card.
  • The paper's Listing 1 was written for Python 3.7 and PyTorch 1.6 app. S1. The repository pins torch==1.7.1 requirements.txt.
  • The paper's listing takes two arguments, x and theta app. S1. The repository's version takes any number of arguments pat.py. The backward pass returns the gradient tuple in both app. S1 [code: pat.py#L32].
  • The repository's README cites a later journal version with a different title README.md. This card covers only the arXiv v1 text.
  • The repository's precomputed MNIST log reaches validation accuracy 0.98 in its simulated demo. That number is not a result from the paper [code: training_logs/precomputed_results/MNIST/epoch=17-val_accu=0.98.ckpt].

Pitfalls

  • Learning-rate schedules are only partly given. The vowel and electronic PNNs have explicit schedules. The mechanical and hybrid PNNs say only that Adadelta and "learning rate scheduling" were used app. S2.
  • Epochs and batch size are not stated for any of the experiments app. S2. The vowel and electronic schedules are given in epochs, but the total run length is not.
  • Vowel data counts disagree. The text says 259 vowels, then gives N_data = 257 app. S2.
  • Electronic readout: average or weighted sum? The main text says the seven sub-networks are averaged §Results. The supplement says a weighted sum with trainable weights and offsets app. S2.
  • SHG parameter count. Layer 1 has 52 parameters and later layers 50, which gives about 252 physical parameters app. S2. The Figure 2 caption says "~250 physical parameters and 10 digital parameters" fig. 2.
  • Figure 3 caption and text on in silico training. The caption says in silico training is "barely distinguishable from random guessing" for final accuracy at every depth fig. 3C. The text says it reaches about 40% at its best §Results. Read these as different measures.
  • Typo in the stage equation. The later-stage normalisation divides by the maximum of the stage's own output, but the formula writes s^[1] in the numerator app. S2. The first-stage form uses s^[1] throughout. Implement with the stage's own output.
  • The in silico baseline includes a noise model. The paper says all simulation-trained results, including fig. 3, used a fitted model of the physical noise app. S2. A simulation baseline without that model is not the paper's comparison.
  • Cost of physical data. At the stated 200 Hz, one million physical executions take about 5,000 seconds of machine time app. S2. Each PAT step also needs a digital-model Jacobian, and the electronic PNN retrains its model every two epochs app. S2.
  • The digital model's accuracy matters for gradient direction, not for loss. The paper argues that a poor digital model degrades the gradient estimates, while the loss itself is computed from measured outputs app. S1.
  • Bound penalties are required. The paper says the constraint terms were needed in all cases so that physical inputs and parameters stayed in range app. S2.
  • Finite-difference cost. A physical system's own gradients would cost one physical call per input and parameter for each backward pass app. S1.

Lineage

  • Builds on: backpropagation with autodiff for digital networks app. S1. PAT is compared to quantization-aware training and feedback alignment as analogous ideas §Results.
  • Compared against: in silico training (the same chain trained entirely in simulation) and ideal backpropagation with finite differences app. S1 fig. 3.
  • Superseded by: the repository's README cites a 2022 journal version of this work with a different title README.md. This card does not cover it.

Source and license

Adapted from “Deep physical neural networks enabled by a backpropagation algorithm for arbitrary physical systems” by Logan G. Wright, Tatsuhiro Onodera, Martin M. Stein, Tianyu Wang, Darren T. Schachter, Zoey Hu, Peter L. McMahon (arXiv:2104.13386), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/mcmahon-lab/Physics-Aware-Training at commit e28af4ffa7ad (CC-BY-4.0). Any quoted code is shown under that license.