cosmiq.library.reservoir#
cosmiq.library.reservoir: a windowed reservoir with a ridge readout, after Fujii & Nakajima
2017 and Bravo et al. 2022, and the NARMA2 task (Atiya & Parlos 2000).
A sample is a window of the last window inputs. Each input sets the global detuning for one
segment of segment µs, under a constant \(\Omega\), so a window is one program of window
\(\times\) segment µs (the device’s 5 µs at most). Its features are the exact
\(\langle n_i \rangle\) and \(\langle n_i n_j \rangle\) (\(i < j\)) at the end, or
their estimates from shots. A ridge regression reads them out. No quantum benefit is claimed:
its tests report polynomial baselines beside it.
The reservoir on |
|
Ridge regression in closed form, float64: \(\min \lVert Xw + b - y \rVert^2 + \alpha \lVert w \rVert^2\), the intercept \(b\) unpenalised (fitted on centred data). |
|
NARMA2: inputs \(u(t)\) uniform in \([0, 0.5)\) (numpy's default_rng(seed)), and \(y(t+1) = 0.4\, y(t) + 0.4\, y(t)\, y(t-1) + 0.6\, u(t)^3 + 0.1\) from \(y(0) = y(1) = 0\). |
|
The normalised mean squared error: \(\mathrm{mean}((\mathrm{prediction}-\mathrm{target})^2)/\mathrm{var}(\mathrm{target})\). |
|
Every monomial of each window's values of total degree 1 to |
|
The sliding windows of a [T] series, [T - window + 1, window] float64; row t is series[t : t + window]. |
Classes
- class cosmiq.library.reservoir.Reservoir(register: Register, device: str | DeviceSpec = 'cosmiq-ref-1', *, window: int, segment: float, omega: float = 2 * math.pi * 1.5, detuning: tuple[float, float] = (-2 * math.pi * 0.5, 2 * math.pi * 0.5), input_range: tuple[float, float] = (0.0, 1.0), ramp: float = 0.1)#
Bases:
objectThe reservoir on
register, targeted atdevice.window: inputs per sample;segment: µs per input, on the device’s clock.omega: the constant \(\Omega\), rad/µs (\(2\pi \cdot 1.5\,\mathrm{MHz}\) by default), ramped up and down overrampµs at the window’s ends. It’s the program’s one parameter (“params.omega”).detuning: the (low, high) \(\Delta\), rad/µs, that the ends ofinput_rangemap onto, linearly (\(\pm 2\pi \cdot 0.5\,\mathrm{MHz}\) by default: a wider range wraps the phase, as an early test showed). Between segments \(\Delta\) moves linearly overrampµs.
Noise off, on the full-space emulator.
- windows(inputs: object) Tensor#
inputsas [B, window] float64: a [T] series gives its T - window + 1 sliding windows (row t ends at input t + window - 1); a [B, window] array is taken as is.
- features(inputs: object, *, shots: int | None = None, seed: int | None = None) Tensor#
\([B, N + N(N-1)/2]\) float64: \(\langle n_i \rangle\) for each atom, then \(\langle n_i n_j \rangle\) for \(i < j\) (row by row), at the end of each window. Exact, or with
shots=the means over that many shots per window (seeded byseed).
- class cosmiq.library.reservoir.Ridge(alpha: float = 1e-6)#
Bases:
objectRidge regression in closed form, float64: \(\min \lVert Xw + b - y \rVert^2 + \alpha \lVert w \rVert^2\), the intercept \(b\) unpenalised (fitted on centred data).
Functions
- cosmiq.library.reservoir.narma2(length: int, *, seed: int) tuple[Tensor, Tensor]#
NARMA2: inputs \(u(t)\) uniform in \([0, 0.5)\) (numpy’s default_rng(seed)), and \(y(t+1) = 0.4\, y(t) + 0.4\, y(t)\, y(t-1) + 0.6\, u(t)^3 + 0.1\) from \(y(0) = y(1) = 0\). Both [length] float64.
- cosmiq.library.reservoir.nmse(prediction: object, target: object) float#
The normalised mean squared error: \(\mathrm{mean}((\mathrm{prediction}-\mathrm{target})^2)/\mathrm{var}(\mathrm{target})\).