PennyLane exposes a cost function and tunable parameters, so the runtime drops in exactly at the optimizer.
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()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.