## `eigenkit.qml.qrc`

Quantum reservoir computing (QRC) estimators, compatible with scikit-learn.

A reservoir is a circuit with fixed random weights, which are never trained. These estimators sample the weights once (with the seed `random_state`), run the circuit over the input sequences with reservoir.run_reservoir(), extract classical features, and train only a linear readout. This split into a fixed reservoir and a linear readout is the standard form of QRC. So these estimators belong with the scikit-learn estimators (next to `QSVC` and `QSVR`), and not in the PyTorch package.

They are thin wrappers around the functions of the `reservoir` package. For full control (custom processing of the features, custom readouts), call `run_reservoir` and the feature extractors directly.

Data shapes: `X` has shape `(n_sequences, n_timesteps, n_features)`, and `y` has shape `(n_sequences, n_timesteps)`, with one target per timestep (sequence to sequence). `washout` drops the first timesteps from the fit of the readout, so that the reservoir can forget its initial state. Predictions are still made for every timestep.

### `QuantumReservoirClassifier`

Bases: `_ReservoirMixin`, `BaseQuantumClassifier`

Quantum reservoir classifier: a fixed random reservoir and a logistic readout.

It uses the same reservoir as QuantumReservoirRegressor. The readout is a scikit-learn `LogisticRegression` on the features of each timestep. `y` holds integer or label targets, of shape `(n_sequences, n_timesteps)`.

Parameters:

| Name           | Type           | Description                                                                                                                                                                                                                                                   | Default                                                                                                                    |
| -------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| `blocks`       | `list`         | The architecture of the reservoir circuit, a list of blocks that is assembled once. Its n_inputs must match the policy: F for the policies that carry the state, and window * F for state_policy="stateless", where F is the number of features per timestep. | *required*                                                                                                                 |
| `state_policy` | `str`          | "carry" (the unitary of the circuit carries the state from one step to the next), "stateless" (each step starts from                                                                                                                                          | 0…0⟩ and encodes a sliding window of inputs), or "leaky" (the carried state is mixed with a reset state and renormalised). |
| `window`       | `int`          | The length of the sliding window, for state_policy="stateless".                                                                                                                                                                                               | `1`                                                                                                                        |
| `leak`         | `float`        | The mixing coefficient alpha, for state_policy="leaky".                                                                                                                                                                                                       | `1.0`                                                                                                                      |
| `features`     | `FeaturesSpec` | The features read from the reservoir. It is "z" (the value of ⟨Z⟩ on each qubit, the default), "probabilities", "amplitudes", a Pauli or Hamiltonian string (for example "0.5 Z0 X1 - 0.3 Y0"), or a list of such strings, to read out any observables.       | `'z'`                                                                                                                      |
| `C`            | `float`        | The inverse regularisation strength of the logistic readout, passed to scikit-learn. Smaller values regularise more. This is the only argument that the regressor does not have: there, the readout is a ridge regression controlled by ridge.                | `1.0`                                                                                                                      |
| `washout`      | `int`          | The number of timesteps dropped from the fit of the readout. They are not dropped from the predictions.                                                                                                                                                       | `0`                                                                                                                        |
| `weight_scale` | `float`        | The standard deviation of the sampled reservoir weights.                                                                                                                                                                                                      | `1.0`                                                                                                                      |
| `provider`     | `ProviderSpec` | The backend, which must give access to the statevector. Default: "numpy".                                                                                                                                                                                     | `'numpy'`                                                                                                                  |
| `random_state` | \`int          | None\`                                                                                                                                                                                                                                                        | The seed of the fixed reservoir weights.                                                                                   |

#### `__sklearn_is_fitted__()`

Return True when the readout has been fitted.

#### `fit(X, y)`

Fit the estimator on `X` and `y`.

Parameters:

| Name | Type      | Description                                                                              | Default    |
| ---- | --------- | ---------------------------------------------------------------------------------------- | ---------- |
| `X`  | `ndarray` | The sequences, of shape (n_sequences, n_timesteps, n_features). A 2-D array is rejected. | *required* |
| `y`  | `ndarray` | One target for each timestep, of shape (n_sequences, n_timesteps).                       | *required* |

Returns:

| Type                           | Description                                   |
| ------------------------------ | --------------------------------------------- |
| `'QuantumReservoirClassifier'` | This estimator, so that calls can be chained. |

#### `predict(X)`

Predict a label for every timestep of every sequence in `X`.

Parameters:

| Name | Type      | Description                                                                              | Default    |
| ---- | --------- | ---------------------------------------------------------------------------------------- | ---------- |
| `X`  | `ndarray` | The sequences, of shape (n_sequences, n_timesteps, n_features). A 2-D array is rejected. | *required* |

Returns:

| Type      | Description                                                |
| --------- | ---------------------------------------------------------- |
| `ndarray` | The predicted labels, of shape (n_sequences, n_timesteps). |

#### `predict_proba(X)`

Predict the class probabilities for every timestep of every sequence in `X`.

Parameters:

| Name | Type      | Description                                                                              | Default    |
| ---- | --------- | ---------------------------------------------------------------------------------------- | ---------- |
| `X`  | `ndarray` | The sequences, of shape (n_sequences, n_timesteps, n_features). A 2-D array is rejected. | *required* |

Returns:

| Type      | Description                                                                                                      |
| --------- | ---------------------------------------------------------------------------------------------------------------- |
| `ndarray` | The probabilities, of shape (n_sequences, n_timesteps, n_classes), with the last axis in the order of classes\_. |

#### `score(X, y)`

Score the estimator on `X` against `y`.

Parameters:

| Name | Type      | Description                                                                              | Default    |
| ---- | --------- | ---------------------------------------------------------------------------------------- | ---------- |
| `X`  | `ndarray` | The sequences, of shape (n_sequences, n_timesteps, n_features). A 2-D array is rejected. | *required* |
| `y`  | `ndarray` | One target for each timestep, of shape (n_sequences, n_timesteps).                       | *required* |

Returns:

| Type    | Description                                                             |
| ------- | ----------------------------------------------------------------------- |
| `float` | The accuracy of the predictions, over every timestep of every sequence. |

### `QuantumReservoirRegressor`

Bases: `_ReservoirMixin`, `BaseQuantumRegressor`

Quantum reservoir regressor: a fixed random reservoir and a ridge readout.

Parameters:

| Name           | Type           | Description                                                                                                                                                                                                                                                   | Default                                                                                                                    |
| -------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| `blocks`       | `list`         | The architecture of the reservoir circuit, a list of blocks that is assembled once. Its n_inputs must match the policy: F for the policies that carry the state, and window * F for state_policy="stateless", where F is the number of features per timestep. | *required*                                                                                                                 |
| `state_policy` | `str`          | "carry" (the unitary of the circuit carries the state from one step to the next), "stateless" (each step starts from                                                                                                                                          | 0…0⟩ and encodes a sliding window of inputs), or "leaky" (the carried state is mixed with a reset state and renormalised). |
| `window`       | `int`          | The length of the sliding window, for state_policy="stateless".                                                                                                                                                                                               | `1`                                                                                                                        |
| `leak`         | `float`        | The mixing coefficient alpha, for state_policy="leaky".                                                                                                                                                                                                       | `1.0`                                                                                                                      |
| `features`     | `FeaturesSpec` | The features read from the reservoir. It is "z" (the value of ⟨Z⟩ on each qubit, the default), "probabilities", "amplitudes", a Pauli or Hamiltonian string (for example "0.5 Z0 X1 - 0.3 Y0"), or a list of such strings, to read out any observables.       | `'z'`                                                                                                                      |
| `ridge`        | `float`        | The strength of the L2 penalty of the linear readout, which is solved in closed form.                                                                                                                                                                         | `1e-06`                                                                                                                    |
| `washout`      | `int`          | The number of timesteps dropped from the fit of the readout. They are not dropped from the predictions.                                                                                                                                                       | `0`                                                                                                                        |
| `weight_scale` | `float`        | The standard deviation of the sampled reservoir weights.                                                                                                                                                                                                      | `1.0`                                                                                                                      |
| `provider`     | `ProviderSpec` | The backend, which must give access to the statevector. Default: "numpy".                                                                                                                                                                                     | `'numpy'`                                                                                                                  |
| `random_state` | \`int          | None\`                                                                                                                                                                                                                                                        | The seed of the fixed reservoir weights.                                                                                   |

#### `__sklearn_is_fitted__()`

Return True when the readout has been fitted.

#### `fit(X, y)`

Fit the estimator on `X` and `y`.

Parameters:

| Name | Type      | Description                                                                                                                      | Default    |
| ---- | --------- | -------------------------------------------------------------------------------------------------------------------------------- | ---------- |
| `X`  | `ndarray` | The sequences, of shape (n_sequences, n_timesteps, n_features). A 2-D array is rejected.                                         | *required* |
| `y`  | `ndarray` | One target for each timestep, of shape (n_sequences, n_timesteps), or (n_sequences, n_timesteps, n_outputs) for several outputs. | *required* |

Returns:

| Type                          | Description                                   |
| ----------------------------- | --------------------------------------------- |
| `'QuantumReservoirRegressor'` | This estimator, so that calls can be chained. |

#### `predict(X)`

Predict a value for every timestep of every sequence in `X`.

Parameters:

| Name | Type      | Description                                                                              | Default    |
| ---- | --------- | ---------------------------------------------------------------------------------------- | ---------- |
| `X`  | `ndarray` | The sequences, of shape (n_sequences, n_timesteps, n_features). A 2-D array is rejected. | *required* |

Returns:

| Type      | Description                                                                                                                          |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `ndarray` | The predictions, of shape (n_sequences, n_timesteps), or (n_sequences, n_timesteps, n_outputs) when the targets had several outputs. |

#### `score(X, y)`

Score the estimator on `X` against `y`.

Parameters:

| Name | Type      | Description                                                                              | Default    |
| ---- | --------- | ---------------------------------------------------------------------------------------- | ---------- |
| `X`  | `ndarray` | The sequences, of shape (n_sequences, n_timesteps, n_features). A 2-D array is rejected. | *required* |
| `y`  | `ndarray` | One target for each timestep, of shape (n_sequences, n_timesteps).                       | *required* |

Returns:

| Type    | Description                                                                                    |
| ------- | ---------------------------------------------------------------------------------------------- |
| `float` | The coefficient of determination R² of the predictions, over every timestep of every sequence. |
