Skip to content

Diagnostics#10

Open
vtommasini wants to merge 1 commit into
sxs-collaboration:mainfrom
vtommasini:diagnostics
Open

Diagnostics#10
vtommasini wants to merge 1 commit into
sxs-collaboration:mainfrom
vtommasini:diagnostics

Conversation

@vtommasini

Copy link
Copy Markdown

Functions to carry out leave-one-out cross validation for GPR model

Copilot AI review requested due to automatic review settings May 27, 2026 01:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Introduces a GPR diagnostics/checkpointing API and replaces the previous single GPR unit test with broader tests covering diagnostics, core training/prediction behavior, and checkpoint save/load.

Changes:

  • Added diagnostics utilities (LOO predictions/cross-validation + residual plotting) and corresponding unit tests.
  • Added checkpoint save/load functions for trained GPR models (including normalization stats and training data) with unit tests.
  • Reorganized exports via a new SimulationSupport.gpr package interface and removed the old test_gpr.py.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tests/test_gpr.py Removed legacy GPR unit test file in favor of more granular coverage.
tests/test_diagnostics.py Adds unit tests for new diagnostics helpers (LOO + residuals).
tests/test_core.py Adds unit tests for core GPR behavior and checkpoint save/load round-trips.
src/SimulationSupport/gpr/diagnostics.py New diagnostics module implementing LOO prediction/CV and residual plotting.
src/SimulationSupport/gpr/init.py New package export surface for core + diagnostics.
src/SimulationSupport/gpr.py Updates documentation/formatting and adds checkpoint save/load functions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread tests/test_diagnostics.py Outdated
Comment on lines +473 to +516
def setUp(self):
self.df = make_df()

def tearDown(self):
plt.close("all")

def test_returns_four_outputs(self):
# Test that the function returns (X, Y, predictions_LOO, uncertainties_LOO)
result = loo_predictions(
self.df,
inputVar="initial_separation",
outputVar="initial_orbital_frequency",
)
self.assertEqual(len(result), 4)

def test_output_types_are_arrays(self):
# Test that all four outputs are numpy arrays (and not lists or tensors)
X, Y, preds, uncertainties = loo_predictions(
self.df,
inputVar="initial_separation",
outputVar="initial_orbital_frequency",
)
for arr in (X, Y, preds, uncertainties):
self.assertIsInstance(arr, np.ndarray)

def test_output_shapes_match_input(self):
# Test that each returned array has one entry per row in the DataFrame
X, Y, preds, uncertainties = loo_predictions(
self.df,
inputVar="initial_separation",
outputVar="initial_orbital_frequency",
)
n = len(self.df)
for arr in (X, Y, preds, uncertainties):
self.assertEqual(arr.shape, (n,))

def test_X_matches_input_column(self):
# Returned X should be exactly the values of the inputVar column
X, _, _, _ = loo_predictions(
self.df,
inputVar="initial_separation",
outputVar="initial_orbital_frequency",
)
np.testing.assert_array_equal(X, self.df["initial_separation"].values)
Comment thread tests/test_core.py
Comment on lines +617 to +647
def setUp(self):
"""
Train a model and save a checkpoint once for all tests in this class.
Individual tests inspect different aspects of the saved file.
"""
# Temporary directory
self.tmp_dir = tempfile.TemporaryDirectory()
self.ckpt_path = str(Path(self.tmp_dir.name) / "test_model.pt")

self.model, self.likelihood, self.features, self.X, self.Y = (
_train_test_model()
)
self.run_col = "initial_orbital_frequency"
self.pn_col = "spec_pn_guess_omega"

# Save once - all tests below read this file
save_gpr_checkpoint(
self.model,
self.likelihood,
self.features,
"omega",
self.run_col,
self.pn_col,
self.X,
self.Y,
self.ckpt_path,
)

def tearDown(self):
# Temporary directory
self.tmp_dir.cleanup()
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread tests/test_core.py Outdated
self.assertFalse(model.training)

def test_likelihood_in_eval_mode(self):
# Test lihelihood.training is False
@vtommasini vtommasini force-pushed the diagnostics branch 3 times, most recently from 795ff5e to 99a78b8 Compare May 27, 2026 01:27

@nilsvu nilsvu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase on the merged #8 .

Also look at the Copilot review and decide which comments to address.

Comment thread src/SimulationSupport/gpr/__init__.py Outdated
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread tests/test_diagnostics.py Outdated
@vtommasini vtommasini force-pushed the diagnostics branch 2 times, most recently from bf62555 to 5d719fd Compare June 24, 2026 07:21
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread tests/test_diagnostics.py Outdated
Comment thread tests/test_diagnostics.py Outdated
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread src/SimulationSupport/gpr/diagnostics.py Outdated
Comment thread tests/test_data.csv
Comment thread tests/test_diagnostics.py Outdated
@vtommasini vtommasini force-pushed the diagnostics branch 2 times, most recently from 04268d8 to f4ff5a5 Compare July 1, 2026 19:50
Simplified parallelization and tests, and decreased number of test_data points to make tests run faster
Rebased, shortened tests
@nilsvu

nilsvu commented Jul 2, 2026

Copy link
Copy Markdown
Member

@vtommasini for some reason the CI tests take forever and time out at 6 hours. Any idea what's happening? Doe the tests run quick on your machine?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants