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

Update ensemble simulate output #4429

Merged
merged 16 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CalibrateEnsembleCiemssOperation as operation } from './calibrate-ensemble-ciemss-operation';
import node from './tera-calibrate-ensemble-node-ciemss.vue';
import drilldown from './tera-calibrate-ensemble-ciemss.vue';
import drilldown from './tera-calibrate-ensemble-ciemss-drilldown.vue';

const name = operation.name;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SimulateEnsembleCiemssOperation as operation } from './simulate-ensemble-ciemss-operation';
import node from './tera-simulate-ensemble-node-ciemss.vue';
import drilldown from './tera-simulate-ensemble-ciemss.vue';
import drilldown from './tera-simulate-ensemble-ciemss-drilldown.vue';

const name = operation.name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export interface SimulateEnsembleCiemssOperationState extends BaseState {
mapping: EnsembleModelConfigs[];
timeSpan: TimeSpan;
numSamples: number;
inProgressSimulationId: string;
inProgressForecastId: string;
forecastId: string; // Completed run's Id
errorMessage: { name: string; value: string; traceback: string };
}

Expand All @@ -20,7 +21,7 @@ export const SimulateEnsembleCiemssOperation: Operation = {
documentationUrl: DOCUMENTATION_URL,
imageUrl: simulateEnsembleCiemss,
inputs: [{ type: 'modelConfigId', label: 'Model configuration', acceptMultiple: false }],
outputs: [{ type: 'simulationId' }],
outputs: [{ type: 'datasetId' }],
isRunnable: true,

// TODO: Figure out mapping
Expand All @@ -35,7 +36,8 @@ export const SimulateEnsembleCiemssOperation: Operation = {
mapping: [],
timeSpan: { start: 0, end: 40 },
numSamples: 40,
inProgressSimulationId: '',
inProgressForecastId: '',
forecastId: '',
errorMessage: { name: '', value: '', traceback: '' }
};
return init;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ const numSamples = ref<number>(props.node.state.numSamples);

const newSolutionMappingKey = ref<string>('');
const runResults = ref<RunResults>({});
const cancelRunId = computed(() => props.node.state.inProgressSimulationId);
const cancelRunId = computed(() => props.node.state.inProgressForecastId);
// Preview selection
const outputs = computed(() => {
if (!_.isEmpty(props.node.outputs)) {
Expand Down Expand Up @@ -302,7 +302,7 @@ const runEnsemble = async () => {
const response = await makeEnsembleCiemssSimulation(params, nodeMetadata(props.node));

const state = _.cloneDeep(props.node.state);
state.inProgressSimulationId = response.simulationId;
state.inProgressForecastId = response.simulationId;
emit('update-state', state);
};

Expand Down Expand Up @@ -344,7 +344,7 @@ onMounted(async () => {
});

watch(
() => props.node.state.inProgressSimulationId,
() => props.node.state.inProgressForecastId,
(id) => {
if (id === '') showSpinner.value = false;
else showSpinner.value = true;
Expand All @@ -359,8 +359,10 @@ watch(

selectedOutputId.value = output.id;
selectedRunId.value = output.value[0];
const forecastId = props.node.state.forecastId;
if (!forecastId) return;

const response = await getRunResultCiemss(output.value[0], 'result.csv');
const response = await getRunResultCiemss(forecastId, 'result.csv');
runResults.value = response.runResults;
},
{ immediate: true }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<section v-if="!inProgressSimulationId && runResults[selectedRunId]">
<section v-if="!inProgressForecastId && runResults[selectedRunId]">
<tera-simulate-chart
v-for="(cfg, index) of node.state.chartConfigs"
:key="index"
Expand All @@ -13,7 +13,7 @@

<Button v-if="node.inputs[0].value" label="Edit" @click="emit('open-drilldown')" severity="secondary" outlined />
<tera-operator-placeholder v-else :node="node">Connect a model configuration</tera-operator-placeholder>
<tera-progress-spinner v-if="inProgressSimulationId" :font-size="2" is-centered style="height: 100%" />
<tera-progress-spinner v-if="inProgressForecastId" :font-size="2" is-centered style="height: 100%" />
</template>

<script setup lang="ts">
Expand All @@ -29,6 +29,8 @@ import TeraOperatorPlaceholder from '@/components/operator/tera-operator-placeho
import TeraProgressSpinner from '@/components/widgets/tera-progress-spinner.vue';
import { logger } from '@/utils/logger';
import { chartActionsProxy, nodeOutputLabel } from '@/components/workflow/util';
import { useProjects } from '@/composables/project';
import { createDatasetFromSimulationResult } from '@/services/dataset';
import {
SimulateEnsembleCiemssOperation,
SimulateEnsembleCiemssOperationState
Expand All @@ -41,7 +43,7 @@ const emit = defineEmits(['append-output', 'update-state', 'open-drilldown', 'ap

// const runResults = ref<RunResults>({});
const runResults = ref<{ [runId: string]: RunResults }>({});
const inProgressSimulationId = computed(() => props.node.state.inProgressSimulationId);
const inProgressForecastId = computed(() => props.node.state.inProgressForecastId);
const selectedRunId = ref<string>('');

const chartProxy = chartActionsProxy(props.node, (state: SimulateEnsembleCiemssOperationState) => {
Expand All @@ -60,7 +62,7 @@ const getStatus = async (simulationId: string) => {
state.errorMessage = { name: '', value: '', traceback: '' };

if (pollerResults.state === PollerState.Cancelled) {
state.inProgressSimulationId = '';
state.inProgressForecastId = '';
poller.stop();
} else if (pollerResults.state !== PollerState.Done || !pollerResults.data) {
logger.error(`Simulation: ${simulationId} has failed`, {
Expand All @@ -69,7 +71,7 @@ const getStatus = async (simulationId: string) => {
const simulation = await getSimulation(simulationId);
if (simulation?.status && simulation?.statusMessage) {
state = _.cloneDeep(props.node.state);
state.inProgressSimulationId = '';
state.inProgressForecastId = '';
state.errorMessage = {
name: simulationId,
value: simulation.status,
Expand All @@ -91,14 +93,22 @@ const processResult = async (simulationId: string) => {
chartProxy.addChart();
}

const datasetName = `Forecast run ${simulationId}`;
const projectId = useProjects().activeProjectId.value;
const datasetResult = await createDatasetFromSimulationResult(projectId, simulationId, datasetName, false);
if (!datasetResult) {
return;
}

emit('append-output', {
type: SimulateEnsembleCiemssOperation.outputs[0].type,
label: nodeOutputLabel(props.node, `${portLabel} Result`),
value: [simulationId],
value: [datasetResult.id],
state: {
mapping: state.mapping,
timeSpan: state.timeSpan,
numSamples: state.numSamples
numSamples: state.numSamples,
forecastId: simulationId
},
isSelected: false
});
Expand All @@ -115,7 +125,7 @@ watch(
);

watch(
() => props.node.state.inProgressSimulationId,
() => props.node.state.inProgressForecastId,
async (id) => {
if (!id || id === '') return;

Expand All @@ -124,7 +134,8 @@ watch(
processResult(id);
}
const state = _.cloneDeep(props.node.state);
state.inProgressSimulationId = '';
state.inProgressForecastId = '';
state.forecastId = id;
emit('update-state', state);
},
{ immediate: true }
Expand All @@ -138,8 +149,10 @@ watch(

selectedRunId.value = props.node.outputs.find((o) => o.id === active)?.value?.[0];
if (!selectedRunId.value) return;
const forecastId = props.node.state.forecastId;
if (!forecastId) return;

const output = await getRunResultCiemss(selectedRunId.value, 'result.csv');
const output = await getRunResultCiemss(forecastId, 'result.csv');
runResults.value[selectedRunId.value] = output.runResults;
},
{ immediate: true }
Expand Down
15 changes: 10 additions & 5 deletions packages/client/hmi-client/src/page/WorkflowNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
<tera-dataset-drilldown v-else-if="isNodeType(OperationType.DATASET)" :node="node" />
<tera-regridding-drilldown v-else-if="isNodeType(OperationType.REGRIDDING)" :node="node" />
<tera-calibrate-ciemss v-else-if="isNodeType(OperationType.CALIBRATION_CIEMSS)" :node="node" />
<tera-calibrate-ensemble-ciemss v-else-if="isNodeType(OperationType.CALIBRATE_ENSEMBLE_CIEMSS)" :node="node" />
<tera-calibrate-ensemble-ciemss-drilldown
v-else-if="isNodeType(OperationType.CALIBRATE_ENSEMBLE_CIEMSS)"
:node="node"
/>
<tera-simulate-ciemss-drilldown v-else-if="isNodeType(OperationType.SIMULATE_CIEMSS)" :node="node" />
<tera-simulate-ensemble-ciemss v-else-if="isNodeType(OperationType.SIMULATE_ENSEMBLE_CIEMSS)" :node="node" />
<tera-simulate-ensemble-ciemss-drilldown
v-else-if="isNodeType(OperationType.SIMULATE_ENSEMBLE_CIEMSS)"
:node="node"
/>
<tera-funman v-else-if="isNodeType(OperationType.FUNMAN)" :node="node" />
<tera-code-asset-wrapper v-else-if="isNodeType(OperationType.CODE)" :node="node" />
</template>
Expand All @@ -19,15 +25,14 @@
import { watch, ref } from 'vue';
import { WorkflowNode, WorkflowOperationTypes as OperationType } from '@/types/workflow';
import * as workflowService from '@/services/workflow';

import TeraModelWorkflowWrapper from '@/components/workflow/ops/model/tera-model-drilldown.vue';
import TeraDatasetDrilldown from '@/components/workflow/ops/dataset/tera-dataset-drilldown.vue';
import TeraRegriddingDrilldown from '@/components/workflow/ops/regridding/tera-regridding.vue';
import TeraDatasetTransformer from '@/components/workflow/ops/dataset-transformer/tera-dataset-transformer.vue';
import TeraCalibrateCiemss from '@/components/workflow/ops/calibrate-ciemss/tera-calibrate-ciemss-drilldown.vue';
import TeraCalibrateEnsembleCiemss from '@/components/workflow/ops/calibrate-ensemble-ciemss/tera-calibrate-ensemble-ciemss.vue';
import TeraCalibrateEnsembleCiemssDrilldown from '@/components/workflow/ops/calibrate-ensemble-ciemss/tera-calibrate-ensemble-ciemss-drilldown.vue';
import TeraSimulateCiemssDrilldown from '@/components/workflow/ops/simulate-ciemss/tera-simulate-ciemss-drilldown.vue';
import TeraSimulateEnsembleCiemss from '@/components/workflow/ops/simulate-ensemble-ciemss/tera-simulate-ensemble-ciemss.vue';
import TeraSimulateEnsembleCiemssDrilldown from '@/components/workflow/ops/simulate-ensemble-ciemss/tera-simulate-ensemble-ciemss-drilldown.vue';
import TeraFunman from '@/components/workflow/ops/funman/tera-funman.vue';
import TeraStratifyMira from '@/components/workflow/ops/stratify-mira/tera-stratify-mira.vue';
import TeraCodeAssetWrapper from '@/components/workflow/ops/code-asset/tera-code-asset-wrapper.vue';
Expand Down
Loading