From 90dd950e2d8c1495f2be34bbf1629b2fd82b93ae Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Mon, 6 Jul 2026 10:09:18 +0100 Subject: [PATCH] Refactors NS and Dream to exist quicker when stopped --- minimisers/DREAM/functions/DREAM.m | 2 +- minimisers/DREAM/runDREAM.m | 6 ++++++ minimisers/NS/nestedSampler.m | 3 ++- minimisers/NS/runNestedSampler.m | 5 +++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/minimisers/DREAM/functions/DREAM.m b/minimisers/DREAM/functions/DREAM.m index e6481e570..df486d910 100644 --- a/minimisers/DREAM/functions/DREAM.m +++ b/minimisers/DREAM/functions/DREAM.m @@ -222,7 +222,7 @@ if ~strcmpi(controls.display, coderEnums.displayOptions.Off) triggerEvent(coderEnums.eventTypes.Message, sprintf('Optimisation terminated by user\n')); end - break; + return; end end diff --git a/minimisers/DREAM/runDREAM.m b/minimisers/DREAM/runDREAM.m index 73e98ea05..c2845dd6a 100644 --- a/minimisers/DREAM/runDREAM.m +++ b/minimisers/DREAM/runDREAM.m @@ -87,6 +87,12 @@ % Run the sampler.... [chain,dreamOutput,~] = DREAM(DREAMPar,ParInfo,ratInputs); +if isRATStopped(controls.IPCFilePath) + result = makeEmptyResultStruct(problemStruct.numberOfContrasts, length(problemStruct.fitParams), domains); + outProblemStruct = problemStruct; + return +end + % Combine all chains.... nChains = DREAMPar.nChains; nParams = DREAMPar.nParams; diff --git a/minimisers/NS/nestedSampler.m b/minimisers/NS/nestedSampler.m index e7a4f98b4..f7ce16ea7 100644 --- a/minimisers/NS/nestedSampler.m +++ b/minimisers/NS/nestedSampler.m @@ -263,7 +263,8 @@ if ~strcmpi(controls.display, coderEnums.displayOptions.Off) triggerEvent(coderEnums.eventTypes.Message, sprintf('Optimisation terminated by user\n')); end - break; + post_samples = []; + return; end % update counter j = j+1; diff --git a/minimisers/NS/runNestedSampler.m b/minimisers/NS/runNestedSampler.m index 0a8310e72..1ab17893c 100644 --- a/minimisers/NS/runNestedSampler.m +++ b/minimisers/NS/runNestedSampler.m @@ -49,6 +49,11 @@ [logZ, nestSamples, postSamples, H] = nestedSampler(data, nLive, nMCMC,... tolerance, likelihood, model, priorList, fitNames); +if isRATStopped(controls.IPCFilePath) + result = makeEmptyResultStruct(problemStruct.numberOfContrasts, length(problemStruct.fitParams), domains); + return +end + % Process the results... nParams = length(fitNames); % chain = nest_samples(:,1:end-1);