Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize spinner progress #4745

Merged
merged 10 commits into from
Sep 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export interface OptimizeCiemssOperationState extends BaseState {
optimizedInterventionPolicyId: string;
optimizeErrorMessage: { name: string; value: string; traceback: string };
simulateErrorMessage: { name: string; value: string; traceback: string };
// Intermediate:
currentProgress: number; // optimization run's 2 digit %
}

// This is used as a map between dropdown labels and the inner values used by pyciemss-service.
Expand Down Expand Up @@ -150,7 +152,8 @@ export const OptimizeCiemssOperation: Operation = {
optimizationRunId: '',
optimizedInterventionPolicyId: '',
optimizeErrorMessage: { name: '', value: '', traceback: '' },
simulateErrorMessage: { name: '', value: '', traceback: '' }
simulateErrorMessage: { name: '', value: '', traceback: '' },
currentProgress: 0
};
return init;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@
<template #preview>
<tera-drilldown-section
class="ml-3 mr-3"
:is-loading="showSpinner"
:class="{ 'failed-run': optimizationResult.success === 'False' ?? 'successful-run' }"
>
<template #header-controls-left v-if="optimizedInterventionPolicy?.name">
Expand All @@ -254,10 +253,16 @@
@click="showSaveInterventionPolicy = true"
/>
</template>

<section v-if="showSpinner" class="spinner-message">
<tera-progress-spinner :font-size="2" is-centered style="height: 12rem" />
<p>{{ node.state.currentProgress }}% of maximum iterations complete</p>
</section>
Tom-Szendrey marked this conversation as resolved.
Show resolved Hide resolved
<tera-operator-output-summary v-if="node.state.summaryId && !showSpinner" :summary-id="node.state.summaryId" />
<!-- Optimize result.json display: -->
<div v-if="optimizationResult && displayOptimizationResultMessage" class="result-message-grid mt-2 mb-2">
<div
v-if="optimizationResult && displayOptimizationResultMessage && !showSpinner"
class="result-message-grid mt-2 mb-2"
>
<span class="flex flex-row">
<p class="mt-2">For debugging</p>
<Button
Expand All @@ -275,6 +280,7 @@
</div>
</div>
<SelectButton
v-if="!showSpinner"
:model-value="outputViewSelection"
@change="if ($event.value) outputViewSelection = $event.value;"
:options="outputViewOptions"
Expand All @@ -288,7 +294,7 @@
</SelectButton>
<tera-notebook-error v-bind="node.state.optimizeErrorMessage" />
<tera-notebook-error v-bind="node.state.simulateErrorMessage" />
<template v-if="runResults[knobs.postForecastRunId] && runResults[knobs.preForecastRunId]">
<template v-if="runResults[knobs.postForecastRunId] && runResults[knobs.preForecastRunId] && !showSpinner">
<section v-if="outputViewSelection === OutputView.Charts" ref="outputPanel">
<Accordion multiple :active-index="[0, 1, 2]">
<AccordionTab header="Success criteria">
Expand Down Expand Up @@ -379,6 +385,7 @@ import TeraDrilldownSection from '@/components/drilldown/tera-drilldown-section.
import TeraSaveDatasetFromSimulation from '@/components/dataset/tera-save-dataset-from-simulation.vue';
import TeraPyciemssCancelButton from '@/components/pyciemss/tera-pyciemss-cancel-button.vue';
import TeraOperatorOutputSummary from '@/components/operator/tera-operator-output-summary.vue';
import TeraProgressSpinner from '@/components/widgets/tera-progress-spinner.vue';
import { getUnitsFromModelParts, getModelByModelConfigurationId } from '@/services/model';
import { createModelConfiguration, getModelConfigurationById } from '@/services/model-configurations';
import {
Expand Down Expand Up @@ -1119,6 +1126,17 @@ watch(
padding: var(--gap-1) var(--gap);
gap: var(--gap-2);
}

.spinner-message {
align-items: center;
align-self: center;
display: flex;
flex-direction: column;
gap: var(--gap-2);
margin-top: 15rem;
text-align: center;
}

.info-circle {
color: var(--text-color-secondary);
font-size: var(--font-caption);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
<template v-if="!node.inputs[0].value"> Attach a model configuration </template>
</tera-operator-placeholder>
<template v-if="node.inputs[0].value">
<tera-progress-spinner v-if="showSpinner" :font-size="2" is-centered style="height: 100%" />
<div v-if="showSpinner">
<p>{{ node.state.currentProgress }}% of maximum iterations complete</p>
<tera-progress-spinner :font-size="2" is-centered style="height: 100%" />
</div>
Tom-Szendrey marked this conversation as resolved.
Show resolved Hide resolved

<div v-if="!showSpinner && runResults">
<template v-for="(_, index) of node.state.selectedSimulationVariables" :key="index">
<vega-chart :visualization-spec="preparedCharts[index]" :are-embed-actions-visible="false" />
Expand Down Expand Up @@ -33,7 +37,7 @@ import {
parsePyCiemssMap
} from '@/services/models/simulation-service';
import { nodeMetadata, nodeOutputLabel } from '@/components/workflow/util';
import { SimulationRequest, InterventionPolicy } from '@/types/Types';
import { SimulationRequest, InterventionPolicy, Simulation } from '@/types/Types';
import { createLLMSummary } from '@/services/summary-service';
import VegaChart from '@/components/widgets/VegaChart.vue';
import { createForecastChart } from '@/services/charts';
Expand Down Expand Up @@ -74,7 +78,19 @@ const pollResult = async (runId: string) => {
poller
.setInterval(5000)
.setThreshold(100)
.setPollAction(async () => pollAction(runId));
.setPollAction(async () => pollAction(runId))
.setProgressAction((data: Simulation) => {
if (runId === props.node.state.inProgressOptimizeId && data.updates.length > 0) {
const checkpoint = _.first(data.updates);
if (checkpoint) {
const state = _.cloneDeep(props.node.state);
state.currentProgress = +((100 * checkpoint.data.progress) / checkpoint.data.totalPossibleIterations).toFixed(
2
);
emit('update-state', state);
}
}
Tom-Szendrey marked this conversation as resolved.
Show resolved Hide resolved
});

const pollerResults = await poller.start();

Expand Down Expand Up @@ -234,6 +250,7 @@ Provide a consis summary in 100 words or less.
state.preForecastRunId = preSimId;
state.inProgressPostForecastId = '';
state.postForecastRunId = postSimId;
state.currentProgress = 0;
emit('update-state', state);

const datasetName = `Forecast run ${state.postForecastRunId}`;
Expand Down Expand Up @@ -281,6 +298,7 @@ Provide a consis summary in 100 words or less.
state.inProgressOptimizeId = '';
state.inProgressPreForecastId = '';
state.inProgressPostForecastId = '';
state.currentProgress = 0;
emit('update-state', state);
}
},
Expand Down
6 changes: 4 additions & 2 deletions packages/client/hmi-client/src/types/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,11 @@ export interface CalibrationRequestCiemss {
}

export interface CiemssStatusUpdate {
loss: number;
progress: number;
jobId: string;
progress: number;
loss?: number;
currentResults?: number[];
totalPossibleIterations?: number;
Tom-Szendrey marked this conversation as resolved.
Show resolved Hide resolved
}

export interface EnsembleCalibrationCiemssRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,30 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import lombok.Data;
import software.uncharted.terarium.hmiserver.annotations.TSModel;
import software.uncharted.terarium.hmiserver.annotations.TSOptional;

@Data
@TSModel
public class CiemssStatusUpdate {

private Number loss;
@JsonAlias("job_id")
private String jobId;

private Number progress;

@JsonAlias("job_id")
private String jobId;
@TSOptional
private Number loss;

@TSOptional
@JsonAlias("current_results")
private List<Number> currentResults;

@TSOptional
@JsonAlias("total_possible_iterations")
private Number totalPossibleIterations;

@JsonIgnore
public JsonNode getDataToPersist() {
Expand Down
Loading