From d59b905d5f7542a78ff6e962c835157f6ad14e1a Mon Sep 17 00:00:00 2001 From: voj Date: Wed, 18 Dec 2024 12:00:00 +1300 Subject: [PATCH] [360] fix inversion completion termination (#361) --- doc/inversion-cookbook.md | 6 +++--- .../NZSHM22_AbstractInversionRunner.java | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/inversion-cookbook.md b/doc/inversion-cookbook.md index 27721d9a..c4aa686e 100644 --- a/doc/inversion-cookbook.md +++ b/doc/inversion-cookbook.md @@ -38,14 +38,14 @@ repeat until completion criteria { ### Completion Criteria These criteria determine the overall length of the inversion. All three criteria can be set up, and the inversion will end when one of them is satisfied at the beginning of a round. -- `setInversionMinutes()` or `setInversionSeconds()` sets a minimum duration. +- `setInversionMinutes()` or `setInversionSeconds()` sets a minimum duration, default 60 seconds. - `setIterationCompletionCriteria()` sets a minimum number of iterations. - `setEnergyChangeCompletionCriteria()` sets an energy change condition. ### Selection Completion Criteria -The length of each `round` is controlled by selection completion criteria. Both can be set up, and each thread will end when one of them is satisfied at the beginning of an iteration step. -- `setSelectionInterval()` minimum round duration in seconds. +The length of each `round` is controlled by selection completion criteria. Only one selection criteria can be set up, and each thread will end when the criteria is satisfied at the beginning of an iteration step. If selection iterations are set up, the selection interval will be ignored. +- `setSelectionInterval()` minimum round duration in seconds, default 10 seconds. - `setSelectionIterations()` the minimum number of iterations. ### Parallelism diff --git a/src/main/java/nz/cri/gns/NZSHM22/opensha/inversion/NZSHM22_AbstractInversionRunner.java b/src/main/java/nz/cri/gns/NZSHM22/opensha/inversion/NZSHM22_AbstractInversionRunner.java index f2a38df1..9a4670dc 100644 --- a/src/main/java/nz/cri/gns/NZSHM22/opensha/inversion/NZSHM22_AbstractInversionRunner.java +++ b/src/main/java/nz/cri/gns/NZSHM22/opensha/inversion/NZSHM22_AbstractInversionRunner.java @@ -763,16 +763,16 @@ public FaultSystemSolution runInversion() throws IOException, DocumentException // .... ProgressTrackingCompletionCriteria progress = new ProgressTrackingCompletionCriteria(completionCriteria); - List subCompletionCriteriaList = new ArrayList<>(); - if (selectionIterations != null) { - subCompletionCriteriaList.add(new IterationCompletionCriteria(selectionIterations)); - } - if (!repeatable){ - subCompletionCriteriaList.add(TimeCompletionCriteria.getInSeconds(selectionInterval)); - } // this is the "sub completion criteria" - the amount of time and/or iterations // between solution selection/synchronization - CompletionCriteria subCompletionCriteria = new CompoundCompletionCriteria(subCompletionCriteriaList); + // Note: since OpenSHA breaks if the subcompletionCriteria is a compound completion criteria, we only allow + // one criteria here. See https://github.com/GNS-Science/nzshm-opensha/issues/360 + CompletionCriteria subCompletionCriteria; + if (selectionIterations != null) { + subCompletionCriteria = new IterationCompletionCriteria(selectionIterations); + } else { + subCompletionCriteria = TimeCompletionCriteria.getInSeconds(selectionInterval); + } initialState = inversionInputGenerator.getInitialSolution();