Hands-on lab · 1 step
Train the ridge readout of a quantum reservoir
The -qubit quantum reservoir of the lesson is fixed: its Ising Hamiltonian, the input injection on qubit and the virtual nodes per input are never trained. Only the linear readout is learned. Your TypeScript function receives the feature matrix of the training window (the expectation values plus a bias column) and the targets of a short-term memory task, and returns the ridge-regression weights . The grader recomputes the reservoir and scores your weights on unseen time steps: recalling the input of one step ago must reach , recalling the input of two steps ago .
Step 1: Implement trainReadout
Complete the TypeScript function
trainReadout(features: number[][], targets: number[], lambda: number): number[]
The reservoir (fixed). Four qubits (qubit is the most significant bit) evolve under with , , , , , and , starting in . At time step the input replaces qubit : with . The state then evolves for in sub-steps , and after each sub-step the four values are recorded. The inputs are mulberry32(42)() for .
The arguments. features is the matrix with one row per time step (the first steps are the washout, which removes the dependence on the initial state). Each row has entries: the expectation values, ordered sub-step by sub-step, followed by a bias entry that is always . Do not add another bias column. targets is the vector with , the input steps in the past, for the same rows in the same order. lambda is the ridge parameter .
What to compute. The weights Setting the gradient to zero gives the normal equations The matrix is symmetric positive definite, so the solution is unique. Solve the system with a Cholesky factorisation followed by forward substitution and back substitution , or with Gaussian elimination. The regulariser applies to every weight, the bias included. Return as an array of finite numbers.
Grading. Your function runs twice, with the delay- targets (code test weights-d1) and with the delay- targets (weights-d2); you are not told which delay a call belongs to. The check shape verifies that each call returns finite numbers. The checks delay-1 and delay-2 recompute the reservoir on the server, predict on the test steps , which your function never sees, and compute . They require for delay and for delay . The exact ridge solution reaches and .
About the shortcut. The module 'quantumcore/qml' exports a ridgeRegression function, which the lesson uses. Calling it would pass this lab without doing the exercise. The grader only sees the returned weights, so this rule is not enforced; the point of the lab is to write the normal equations and the solver yourself.