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.

Reservoir

The reservoir on register, targeted at device.

Ridge

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

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\).

nmse

The normalised mean squared error: \(\mathrm{mean}((\mathrm{prediction}-\mathrm{target})^2)/\mathrm{var}(\mathrm{target})\).

poly_features

Every monomial of each window's values of total degree 1 to degree, [B, C] float64 (no constant: Ridge fits its own intercept), for window of shape [B, window]: the polynomial baselines.

windows

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: object

The reservoir on register, targeted at device.

  • 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 over ramp µ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 of input_range map 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 over ramp µs.

Noise off, on the full-space emulator.

property duration: float#

A window’s length, µs.

windows(inputs: object) → Tensor#

inputs as [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 by seed).

class cosmiq.library.reservoir.Ridge(alpha: float = 1e-6)#

Bases: object

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).

fit(features: object, targets: object) → Ridge#

Fits on [M, F] features and [M] or [M, T] targets; returns self.

predict(features: object) → Tensor#

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})\).

cosmiq.library.reservoir.poly_features(window: object, degree: int) → Tensor#

Every monomial of each window’s values of total degree 1 to degree, [B, C] float64 (no constant: Ridge fits its own intercept), for window of shape [B, window]: the polynomial baselines.

cosmiq.library.reservoir.windows(series: object, window: int) → Tensor#

The sliding windows of a [T] series, [T - window + 1, window] float64; row t is series[t : t + window].