Docs

PennyLane & photonics

PennyLane exposes a cost function and tunable parameters, so the runtime drops in exactly at the optimizer.

The swap

Instead of calling a PennyLane optimizer’s step(cost, params), evaluate the QNode to get the measured cost, hand (params, cost) to the runtime, and apply the configuration it returns.

copyimport pennylane as qml
from swc import SWCOptimizer

dev = qml.device("default.qubit", wires=N)
@qml.qnode(dev)
def cost(theta):
    # your ansatz + measurement
    return qml.expval(H)

opt = SWCOptimizer(key, n=N)
theta = opt.start(theta0)
for _ in range(rounds):
    c = cost(theta)               # one circuit evaluation
    theta = opt.step([c], score=-float(c))
opt.end()

Substrate-agnostic

The runtime only sees parameters in and a measured objective out, so it does not care whether the QNode runs on a simulator, real hardware, or a photonic / continuous-variable backend (PennyLane’s Strawberry Fields plugin, pennylane-sf). Integrating the path is the same swap.

Important scope — read before you wire this to a Hamiltonian: this swap works when your cost is a diagonal / combinatorial objective (QUBO, Ising cost, max-cut) read off the measured output. It does not work for variational energy minimization (VQE / QAOA expectation values). We tested that carefully and the runtime cannot descend it — the objective lives in correlations the marginal-feedback law cannot see. For diagonal cost, follow QUBO & diagonal optimization (and pass the scored configuration as the measured statistic). For VQE-style energy, keep your classical optimizer — SWC is not the right tool.