Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
3ec5e3c
CIP-0003: add umbrella CIP for renovating PyDeepGP
lawrennd Nov 27, 2026
6e56798
Merge remote-tracking branch 'origin/main'
lawrennd Nov 27, 2026
fc31803
CIP-0003: accept; correct evidence against origin/main; add Phase 2/3…
lawrennd Nov 27, 2026
282d1c8
CIP-0003: Remove MPI and rename SparseGP_MPI to SparseGPLayer
lawrennd Nov 27, 2026
c7f73de
CIP-0003: VarDTC subclasses GPy's; keep only uncertain-outputs, chunk…
lawrennd Nov 27, 2026
65dba79
CIP-0003: add deepgp.functional (collapsed_bound, route_gradients); l…
lawrennd Nov 27, 2026
c05059f
CIP-0003: extract q(X) functions; MRD checkgrad tests; record back-co…
lawrennd Nov 27, 2026
6469649
CIP-0003: fix back-constrained MRD gradients (idempotent MLP.update_g…
lawrennd Nov 27, 2026
b5a73a1
CIP-0003 Phase 3: ARD scales, prune/restore, validated initialiser names
lawrennd Nov 27, 2026
b8b6892
CIP-0003 Phase 4: whitened marginals core with backward pass (slice 1)
lawrennd Nov 27, 2026
59a78db
CIP-0003 Phase 4: doubly stochastic bound over a layer stack (slice 2)
lawrennd Nov 27, 2026
50d82fb
CIP-0003 Phase 4: DoublyStochasticDeepGP shell, seeded minibatching, …
lawrennd Nov 27, 2026
4b87555
CIP-0003: cross-check doubly stochastic bound against GPc CIP-0035 re…
lawrennd Nov 27, 2026
5ca0491
CIP-0003: natural-gradient step for the top layer of the doubly stoch…
lawrennd Nov 27, 2026
3775a39
CIP-0003: unsupervised doubly stochastic deep GP with latent q(X)
lawrennd Nov 27, 2026
cfa6139
CIP-0003: V8 composite task and oil/CMU comparison scripts with recor…
lawrennd Nov 27, 2026
1d288bf
CIP-0003: keep VarDTC const_jitter=1e-6 against GPy main's per-instan…
lawrennd Nov 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# Coverage config for PyDeepGP
#
# Measured surface is the maintained serial DeepGP path, including MRD
# (CIP-0002). Remaining omits are MPI / prediction-only SVI helpers (CIP-0001).
# (CIP-0002). Remaining omits are prediction-only SVI helpers (CIP-0001).
[run]
branch = True
source = deepgp
omit =
*/deepgp/testing/*
*/deepgp/inference/vardtc_parallel.py
*/deepgp/inference/inferenceX.py
*/deepgp/inference/svi_ratio.py
*/deepgp/util/parallel.py

[report]
exclude_lines =
Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,3 @@ jobs:
name: ubuntu-3.12
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}

# CIP-0001 R11: optional MPI parity while mpi4py support still exists.
mpi:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install MPI and Python deps
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends libopenmpi-dev openmpi-bin
python -m pip install --upgrade pip setuptools wheel
python -m pip install "numpy>=1.7" "scipy>=0.12" matplotlib h5py tables mpi4py
python -m pip install "git+https://github.com/SheffieldML/GPy.git@main"
python -m pip install -e . --no-deps

- name: MPI parity (2 ranks vs serial)
env:
OMPI_MCA_btl_vader_single_copy_mechanism: none
OMPI_MCA_rmaps_base_oversubscribe: 'true'
run: mpiexec -n 2 python -m deepgp.testing.mpi_parity
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include AUTHORS.txt
include LICENSE
include README.md
recursive-include deepgp/testing *.txt *.h5
recursive-include deepgp/testing *.txt *.h5 *.json
40 changes: 28 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ tox
```

Coverage is gated on the maintained serial DeepGP path, including the NumPy
encoder and MRD (see `.coveragerc`). MPI parallel inference and prediction-only
SVI helpers remain omitted until those paths are removed or revived
(CIP-0001 Phases 2–4).
encoder and MRD (see `.coveragerc`). Prediction-only SVI helpers remain
omitted until those paths are removed or revived (CIP-0001 Phases 2–4).

Pre-commit (notebooks)
----------------------
Expand Down Expand Up @@ -83,15 +82,32 @@ hidden widths (e.g. ``[[[4], [4]], [3]]``); higher indices feed the usual
``EncoderLayer`` stack for layers above the MRD leaf. See
``examples/example_mrd.py``.

MPI (deprecated)
----------------

Passing ``mpi_comm`` to ``DeepGP`` emits a ``FutureWarning`` (CIP-0001). Use
serial models for now; chunked psi-statistics (Phase 3) will replace the
single-machine role of MPI. ``mpi_comm`` with ``back_constraint=False`` raises
``ValueError`` (that configuration produced silently wrong results).

An optional GitHub Actions job runs a 2-rank parity check while MPI remains.
MPI (removed)
-------------

MPI parallel inference has been removed (CIP-0001, CIP-0003). Passing a
non-``None`` ``mpi_comm`` to ``DeepGP``, a layer or an inference method raises
``TypeError``; ``mpi_comm=None`` is still accepted. Use chunked psi-statistics
(``psi_chunk_size``, ``psi_threads``) for single-machine scaling. The old
``SparseGP_MPI`` class name is now an alias of ``SparseGPLayer`` and emits a
``FutureWarning``.

Doubly stochastic inference (new)
---------------------------------

``DeepGP(nDims, Y, X, inference_method='doubly_stochastic', ...)`` returns a
``DoublyStochasticDeepGP`` (Salimbeni and Deisenroth, 2017): a whitened ``q(u)``
per layer, reparameterised samples through hidden layers, and a minibatch
trainer. The likelihood is Gaussian, and the default collapsed ``DeepGP`` is
unchanged. Pass ``X=None`` for the unsupervised model, with a Gaussian ``q(X)``
(``m.X_mean``, ``m.X_var``) initialised by PCA of ``Y``. Training can give the top
layer natural-gradient steps (``fit_minibatch(..., natgrad_gamma=0.1)``)::

m = deepgp.DeepGP([1, 2, 1], Y, X, num_inducing=20,
inference_method='doubly_stochastic', seed=0)
m.optimize(max_iters=200) # fixed samples: deterministic
m.fit_minibatch(steps=500, batch_size=50) # fresh batch and samples each step
mean, var = m.predict(Xnew)

Psi chunking (optional)
-----------------------
Expand Down
55 changes: 55 additions & 0 deletions backlog/bugs/2026-11-27_mrd-back-constraint-gradients.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
id: "2026-11-27_mrd-back-constraint-gradients"
title: "Back-constrained MRD layer fails checkgrad (encoder and X_var gradients)"
status: "Completed"
priority: "High"
created: "2026-11-27"
last_updated: "2026-11-27"
category: "bugs"
related_cips: ["0003", "0002"]
owner: "Neil Lawrence"
dependencies: []
tags:
- backlog
- bug
- mrd
---

# Bug: Back-constrained MRD layer fails checkgrad

## Description

Found while adding MRD `checkgrad` tests for CIP-0003 Phase 2. For `DeepGP([[3, 3], 2], [Y1, Y2], kernels=[[k1, k2]], num_inducing=4, back_constraint=True)`, `checkgrad` fails. It fails identically at commit 65dba79, before the q(X) extraction, so the extraction did not cause it. Non-back-constrained MRD (single layer and with a hidden layer) passes.

Observed with `m.checkgrad(verbose=True)`:

- Kernel, inducing-input and noise gradients are correct.
- Encoder (`view_i.mlp.*`) gradients: numerical is exactly 0.2 times analytical, for every weight (so the analytical gradient is 5x too large; 5 does not equal the number of views).
- `view_i.X_var` (shared variance): analytical is about 1e-6, numerical is large (about -272); the gradient is lost.
- `latent_space.mean/variance` are derived from the encoders in this mode and are overwritten on every update; their analytical gradients are non-zero but should be excluded (fixed) or ignored.

## Acceptance Criteria

- [ ] `MRDCheckgradTest.test_mrd_back_constrained_checkgrad` passes without `expectedFailure`
- [ ] Root cause recorded (candidates: `MRDView.scale` handling in `update_gradients`, `update_encoder_gradients` ordering against `X_var_common`, and `latent_space` being a free parameter)

## Related

- CIP: 0003 (Phase 3: MRD), 0002
- Test: `deepgp/testing/test_functional.py`

## Progress Updates

### 2026-11-27

Found; test marked `expectedFailure` so CI records it without blocking the maintained path.

## Progress Updates

### 2026-11-27
Fixed. Two independent causes:

1. `MLP.update_gradient` accumulated into the layer gradient buffers, which were only reset by `predict`. Each repeated `parameters_changed` between two `predict` calls added another copy of the encoder gradient, so the analytic gradient was an integer multiple of the true one (5x in the repro). `update_gradient` now resets the buffers first and is idempotent.
2. In back-constrained mode the aggregate q(X) (`latent_space`) is derived from the view encoders on every update but was a free parameter, so `checkgrad` (and any optimiser) saw nonzero analytic gradients against zero numerical ones. It is now fixed.

The `X_var` gradients were correct throughout. `test_mrd_back_constrained_checkgrad` is no longer an expected failure; full suite 75 passed.
47 changes: 47 additions & 0 deletions backlog/features/2026-11-27_ard-scales-and-init.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
id: "2026-11-27_ard-scales-and-init"
title: "ARD scale inspection, pruning, and initialisation options"
status: "Completed"
priority: "Medium"
created: "2026-11-27"
last_updated: "2026-11-27"
category: "features"
related_cips: ["0003", "0002"]
owner: "Neil Lawrence"
dependencies: []
tags:
- backlog
- matlab-parity
---

# Task: ARD scale inspection, pruning, and initialisation options

## Description

Phase 3 of CIP-0003. Recover the workflow of Matlab `hsvargplvmShowScales`, `PruneModel` / `RestorePrunedModel` and `InitXOptions` as small tested features: per-layer ARD relevance report, pruning of near-zero dimensions with restore, and named initialisers for `X` (PCA, per-view concatenation, random). We reproduce the capability, not the Matlab interface.

## Acceptance Criteria

- [x] Per-layer ARD scale report and plot helper
- [x] Prune and restore round-trip leaves the objective unchanged to tolerance
- [x] Initialiser selectable by name; default unchanged
- [x] Tests run in CI; the toy example from Damianou 2013 shows the relevant scales

## Related

- CIP: 0003 (Phase 3), 0002

## Progress Updates

### 2026-11-27

Task created from CIP-0003 (Accepted).

### 2026-11-27

Implemented in `deepgp/diagnostics.py` (`ard_scales`, `show_scales`, `prune_model`, `restore_model`) and `validate_init` / `INITIALISERS` in `deepgp/util/util.py`, with tests in `deepgp/testing/test_diagnostics.py` (85 passed overall).

Scope decisions:
- Pruning masks dimensions (kernel parameter set to its off value and fixed) rather than removing columns, so there is no speed-up. Restore is exact. Structural removal is not implemented.
- Unknown initialiser names used to fall through silently to random; they now raise `ValueError`. `random` is a new synonym for `rand`. The default (`PCA`) is unchanged.
- The toy example is a one-layer model on a 1-D curve, not the Damianou 2013 data; it shows one of three offered dimensions switched off (scales 1.00, 0.48, 0.01). Reproducing the paper's own figure belongs to Phase 5.
52 changes: 52 additions & 0 deletions backlog/features/2026-11-27_pure-layer-functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
id: "2026-11-27_pure-layer-functions"
title: "Extract pure layer functions and define the layer interface"
status: "In Progress"
priority: "Medium"
created: "2026-11-27"
last_updated: "2026-11-27"
category: "features"
related_cips: ["0003"]
owner: "Neil Lawrence"
dependencies: ["2026-11-27_remove-mpi"]
tags:
- backlog
- refactor
---

# Task: Extract pure layer functions and define the layer interface

## Description

Phase 2 of CIP-0003. Move the layer bound, psi-statistic propagation and gradients into array-in / array-out functions (public but provisional; name `deepgp/functional/` provisional), following GPy CIP-000F Stage 2. `Layer` classes become a thin shell holding parameters. Define the per-layer interface that both inference families will implement: forward marginals at supplied inputs, accept upstream gradients, expose parameters.

## Acceptance Criteria

- [x] Functions take and return arrays only: no `Param`, observers or communicators
- [x] Layer classes call the functions; public class names and constructors unchanged
- [x] Objective and gradient identical to current values on the reference models (tolerance recorded)
- [x] `checkgrad` passes for every layer type
- [x] Interface documented in the module docstrings

## Related

- CIP: 0003 (Phase 2)
- GPy CIP-000F

## Progress Updates

### 2026-11-27

Task created from CIP-0003 (Accepted). Blocked on MPI removal.

### 2026-11-27 (first slice)

Added `deepgp/functional/`: `collapsed_bound` (statistics in, bound, posterior arrays and gradients w.r.t. statistics and outputs out; certain or uncertain outputs) and `route_gradients` (gradients w.r.t. statistics to kernel and inducing-input gradients). `VarDTC._inference_uncertain_outputs` and `SparseGPLayer._inference_vardtc` now call them; dead `psicov` branches removed. Reference tests unchanged (63 pass before, 70 now), so objective and gradients are identical to within the stored-value tolerances. `checkgrad` passes for unsupervised, supervised and back-constrained stacks; finite-difference tests cover the bound.

Honest limits: `route_gradients` still takes a GPy kernel object (GPy kernels are not pure until GPy CIP-000F Stage 2) and the shell assigns the returned arrays. The q(X) gradient routing in `Layer.update_qX_gradients`, MRD layers and the encoder layers are not yet extracted; the SVI path keeps its in-class code. Left open, so the task stays In Progress.

### 2026-11-27 (second slice)

Added `deepgp/functional/qx.py`: `qx_gradients` (used by `Layer` and `MRDView`), `aggregate_qx` and `disaggregate_qx_gradients` (MRD product-of-experts q(X) and its gradient back-propagation, previously inline in `MRDLayer`). Tested against finite differences. MRD `checkgrad` added: single MRD layer and MRD with a hidden layer pass. Back-constrained MRD fails `checkgrad`; this predates the extraction (see `backlog/bugs/2026-11-27_mrd-back-constraint-gradients.md`) and is recorded as an expected failure.

Remaining: encoder layers (`EncoderLayer`) and the SVI path still hold their own gradient code; both move behind the same functions when those families are touched (encoders in Phase 3 with the MRD bug, SVI in Phase 4). The collapsed-family extraction that this task targets is done.
47 changes: 47 additions & 0 deletions backlog/features/2026-11-27_remove-mpi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
id: "2026-11-27_remove-mpi"
title: "Remove MPI and SparseGP_MPI (CIP-0001 Phase 4, CIP-0002 Phase D)"
status: "In Progress"
priority: "High"
created: "2026-11-27"
last_updated: "2026-11-27"
category: "features"
related_cips: ["0003", "0001", "0002"]
owner: "Neil Lawrence"
dependencies: []
tags:
- backlog
- refactor
- mpi
---

# Task: Remove MPI and SparseGP_MPI

## Description

Phase 2, step 1 of CIP-0003. Execute CIP-0001 R17–R24 and CIP-0002 Phase D: delete `inference/vardtc_parallel.py` and `util/parallel.py`; rename `SparseGP_MPI` to `SparseGPLayer` (keep a deprecated alias); strip root-only branches and reductions from layers, `enclayer.py`, `mrd.py`, `model.py` and the inference modules. Keep accepting `mpi_comm=None` and `mpi_root=0`; raise `TypeError` if `mpi_comm` is not `None`. Single-machine scale comes from `psi_chunk_size` / `psi_threads`.

## Acceptance Criteria

- [x] No `mpi4py` import or `mpi_comm` branch remains in `deepgp/`
- [x] `DeepGP(..., mpi_comm=comm)` with non-`None` raises `TypeError` naming the chunked-psi alternative
- [x] `SparseGP_MPI` still importable, with a `FutureWarning`, pointing at `SparseGPLayer`
- [x] Reference-value tests (`dgp_*.h5`, `dgp_bc_*.h5`) unchanged and passing
- [x] MPI parity and policy tests replaced by a test of the new error
- [x] `.coveragerc` and README no longer mention MPI as supported

## Implementation Notes

Removal follows CIP-0001's deprecation text (the `FutureWarning` has been on `main` since the Phase 2 merge). No multi-machine users were identified in the Discussion; if one appears, CIP-0001 allows reducing MPI to a reducer hook instead.

## Related

- CIP: 0003 (Phase 2), 0001, 0002

## Progress Updates

### 2026-11-27

Task created and started on branch `cip0003-remove-mpi`.

Implementation complete on `cip0003-remove-mpi`: 56 tests pass (53 before, plus the new removal tests); reference tests unchanged. Awaiting review before status moves to Completed.
54 changes: 54 additions & 0 deletions backlog/features/2026-11-27_share-vardtc-with-gpy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
id: "2026-11-27_share-vardtc-with-gpy"
title: "Replace local VarDTC with GPy's, including CIP-0013 sparse linalg modes"
status: "In Progress"
priority: "Medium"
created: "2026-11-27"
last_updated: "2026-11-27"
category: "features"
related_cips: ["0003"]
owner: "Neil Lawrence"
dependencies: ["2026-11-27_remove-mpi"]
tags:
- backlog
- refactor
---

# Task: Replace local VarDTC with GPy's

## Description

Phase 2 of CIP-0003. After MPI is removed, `deepgp/inference/vardtc.py` differs from GPy's `VarDTC` mainly by the uncertain-input handling and chunking. Work out the real delta, upstream what belongs in GPy (or subclass thinly), and delete the rest. Pick up GPy CIP-0013's `stable` / `lq` linear algebra modes where the layer bound uses them.

## Acceptance Criteria

- [x] A written comparison of `deepgp.inference.vardtc.VarDTC` against `GPy...VarDTC` (what differs, and why)
- [x] Local code reduced to the documented delta
- [x] Reference-value tests unchanged
- [x] Choice of linalg mode exposed per layer, defaulting to current behaviour (`sparse_linalg=` on `SparseGPLayer`; settable later via `layer.inference_method.sparse_linalg`)

## Related

- CIP: 0003 (Phase 2)
- GPy CIP-0013

## Progress Updates

### 2026-11-27

Task created from CIP-0003 (Accepted). Blocked on MPI removal.

### 2026-11-27 (comparison and result)

Compared on identical inputs (certain and uncertain X, Gaussian noise 0.1): log marginal, all gradients and the woodbury posterior agree with GPy's `VarDTC` to about 1e-11 once `const_jitter` is matched. The algebra was never the difference. The real delta:

| Feature | GPy `VarDTC` | PyDeepGP (before) | Now |
|---|---|---|---|
| Uncertain outputs (`Y` is q(X) of layer below) | not supported | supported | local code, `_inference_uncertain_outputs` (the only retained algebra) |
| Chunked psi-statistics | no (psi arguments can be passed in) | yes | `psi_statistics`, passed to GPy via `psi0/psi1/psi2` |
| `Kuu_sigma` (hidden layers) | no (`Lm` can be passed in) | yes | factor built locally, passed as `Lm` |
| Jitter / noise floor | 1e-8 | 1e-6 | `const_jitter = 1e-6`, floor 1e-6 (reference tests depend on it) |
| Heteroscedastic noise, mean function, caching, `to_dict`, `sparse_linalg` | yes | no | inherited |
| `inferentia` option | n/a | imported a non-existent class | raises `NotImplementedError` |

`vardtc.py` still carries the uncertain-outputs derivation. Moving it into GPy as an `uncertain_outputs` capability is the upstreaming candidate; it is left for a GPy CIP rather than done here. The linalg mode is exposed on `SparseGPLayer`; `DeepGP`-level pass-through is not yet wired. Tests: `deepgp/testing/test_vardtc_gpy.py` (63 pass overall, reference tests unchanged).
Loading
Loading