Skip to content

Commit f8ecbfb

Browse files
authored
Avoid PPEC crash during dithering ops (#1263)
* Cleanup of MultiStar processing and UI if subframes enabled * Force rebuild of MultiStar list when subframes are disabled * Add try/catch protection in gp regularize_dataset for dithering only * PR changes. Restore star.cpp to resolve Clang issues * PR-requested changes, logging, 'const' * PR request, exception pass by reference
1 parent a471ca7 commit f8ecbfb

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

contributions/MPI_IS_gaussian_process/src/gaussian_process_guider.cpp

+23-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,19 @@ double GaussianProcessGuider::result(double input, double SNR, double time_step,
274274
{
275275
dithering_active_ = false;
276276
}
277-
deduceResult(time_step); // just pretend we would do dark guiding...
277+
try
278+
{
279+
deduceResult(time_step); // just pretend we would do dark guiding...
280+
}
281+
catch (const std::runtime_error& err)
282+
{
283+
reset();
284+
std::ostringstream message;
285+
message << "PPEC: Model reset after exception: " << err.what();
286+
GPDebug->Write(message.str().c_str());
287+
288+
return parameters.control_gain_ * input;
289+
}
278290

279291
GPDebug->Log("PPEC rslt(dithering): input = %.2f, final = %.2f", input, parameters.control_gain_ * input);
280292

@@ -670,6 +682,7 @@ void GaussianProcessGuider::UpdatePeriodLength(double period_length)
670682
SetGPHyperparameters(hypers); // the setter function is needed to convert parameters
671683
}
672684

685+
// NOTE: Callers must be prepared to handle a thrown exception
673686
Eigen::MatrixXd GaussianProcessGuider::regularize_dataset(const Eigen::VectorXd& timestamps, const Eigen::VectorXd& gear_error,
674687
const Eigen::VectorXd& variances)
675688
{
@@ -689,6 +702,7 @@ Eigen::MatrixXd GaussianProcessGuider::regularize_dataset(const Eigen::VectorXd&
689702
int j = 0;
690703
for (size_t i = 0; i < N - 1; ++i)
691704
{
705+
692706
if (timestamps(i) < last_cell_end + grid_interval)
693707
{
694708
gear_error_sum += (timestamps(i) - last_timestamp) * 0.5 * (last_gear_error + gear_error(i));
@@ -699,6 +713,14 @@ Eigen::MatrixXd GaussianProcessGuider::regularize_dataset(const Eigen::VectorXd&
699713
{
700714
while (timestamps(i) >= last_cell_end + grid_interval)
701715
{
716+
if (dithering_active_) // generalizing this will require recovery in any function that calls UpdateGP
717+
{
718+
if (j >= reg_timestamps.size())
719+
{
720+
GPDebug->Log("PPDbg: Index-over-run in regularize_dataset, j = %d", j);
721+
throw std::runtime_error("Index over-run in regularize_dataset");
722+
}
723+
}
702724
double inter_timestamp = last_cell_end + grid_interval;
703725

704726
double proportion = (inter_timestamp - last_timestamp) / (timestamps(i) - last_timestamp);

0 commit comments

Comments
 (0)