The loop is identical across substrates — only measure() and the score change. Three common shapes:
Tune phase shifters / heaters to maximize transmission or minimize loss; the measurement is an optical power reading per setting.
copyx = opt.step(read_power(x), score=read_power(x)) # maximize transmitted powerTune bias points or a matching network to minimize reflection (maximize return loss); the measurement is an S-parameter or detector reading.
copyx = opt.step(read_s11(x), score=-abs(read_s11(x))) # minimize reflectionTune array parameters (delays, gains, focus) to maximize usable signal per scan, when each scan is expensive.
copyx = opt.step(scan_features(x), score=snr(x)) # maximize SNR per scanIn every case: a writable configuration in, an expensive measurement out, a scalar score that rewards the outcome you want.