Skip to content

Commit

Permalink
Regridding operator (#3120)
Browse files Browse the repository at this point in the history
Co-authored-by: Yohann Paris <github@yohannparis.com>
  • Loading branch information
bigglesandginger and YohannParis authored Mar 22, 2024
1 parent d6e2186 commit be739c7
Show file tree
Hide file tree
Showing 11 changed files with 722 additions and 2 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const operatorGraphics = {
[WorkflowOperationTypes.MODEL_FROM_EQUATIONS]: createModelFromEquations,
[WorkflowOperationTypes.OPTIMIZE_CIEMSS]: optimizeModel,
[WorkflowOperationTypes.MODEL_TRANSFORMER]: transformModel,
[WorkflowOperationTypes.REGRIDDING]: transformDataset,
[WorkflowOperationTypes.SIMULATE_CIEMSS]: simulateProbabilistic,
[WorkflowOperationTypes.SIMULATE_ENSEMBLE_CIEMSS]: simulateEnsembleCiemss,
[WorkflowOperationTypes.SIMULATE_JULIA]: simulateJulia,
Expand Down
2 changes: 2 additions & 0 deletions packages/client/hmi-client/src/page/WorkflowNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
:node="node"
/>
<tera-dataset-drilldown v-else-if="isNodeType(OperationType.DATASET)" :node="node" />
<tera-regridding-drilldown v-else-if="isNodeType(OperationType.REGRIDDING)" :node="node" />
<tera-calibrate-julia v-else-if="isNodeType(OperationType.CALIBRATION_JULIA)" :node="node" />
<tera-simulate-julia v-else-if="isNodeType(OperationType.SIMULATE_JULIA)" :node="node" />
<tera-calibrate-ciemss v-else-if="isNodeType(OperationType.CALIBRATION_CIEMSS)" :node="node" />
Expand All @@ -32,6 +33,7 @@ import * as workflowService from '@/services/workflow';
import TeraModelWorkflowWrapper from '@/workflow/ops/model/tera-model-workflow-wrapper.vue';
import TeraDatasetDrilldown from '@/workflow/ops/dataset/tera-dataset-drilldown.vue';
import TeraRegriddingDrilldown from '@/workflow/ops/regridding/tera-regridding.vue';
import TeraDatasetTransformer from '@/workflow/ops/dataset-transformer/tera-dataset-transformer.vue';
import TeraCalibrateJulia from '@/workflow/ops/calibrate-julia/tera-calibrate-julia.vue';
import TeraSimulateJulia from '@/workflow/ops/simulate-julia/tera-simulate-julia.vue';
Expand Down
1 change: 1 addition & 0 deletions packages/client/hmi-client/src/types/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,7 @@ export enum WorkflowOperationTypes {
OptimizeCiemss = "OPTIMIZE_CIEMSS",
ModelCoupling = "MODEL_COUPLING",
ModelEdit = "MODEL_EDIT",
Regridding = "REGRIDDING",
Document = "DOCUMENT",
}

Expand Down
3 changes: 2 additions & 1 deletion packages/client/hmi-client/src/types/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export enum WorkflowOperationTypes {
MODEL_EDIT = 'ModelEdit',
DOCUMENT = 'Document',
MODEL_FROM_EQUATIONS = 'ModelFromEquations',
DECAPODES = 'Decapodes'
DECAPODES = 'Decapodes',
REGRIDDING = 'Regridding'
}

export enum OperatorStatus {
Expand Down
7 changes: 7 additions & 0 deletions packages/client/hmi-client/src/workflow/ops/regridding/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { RegriddingOperation as operation } from './regridding-operation';
import node from './tera-regridding-node.vue';
import drilldown from './tera-regridding.vue';

const name = operation.name;

export { name, operation, node, drilldown };
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Operation, WorkflowOperationTypes } from '@/types/workflow';

export interface RegriddingState {
datasetId: string | null;
notebookSessionId?: string;
}

export const RegriddingOperation: Operation = {
name: WorkflowOperationTypes.REGRIDDING,
description: 'Select a dataset',
displayName: 'Transform gridded dataset',
isRunnable: true,
inputs: [{ type: 'datasetId', label: 'Dataset' }],
outputs: [],
action: () => {},

initState: () => {
const init: RegriddingState = {
datasetId: null
};
return init;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<template>
<section>
<tera-operator-placeholder v-if="!node.inputs[0].value" :operation-type="node.operationType">
Attach one or more resources
</tera-operator-placeholder>
<Button v-else label="Edit" @click="emit('open-drilldown')" severity="secondary" outlined />
</section>
</template>

<script setup lang="ts">
import { watch } from 'vue';
import { WorkflowNode, WorkflowPortStatus } from '@/types/workflow';
import Button from 'primevue/button';
import TeraOperatorPlaceholder from '@/components/operator/tera-operator-placeholder.vue';
import { RegriddingState } from './regridding-operation';
const emit = defineEmits(['append-input-port', 'open-drilldown']);
const props = defineProps<{
node: WorkflowNode<RegriddingState>;
}>();
watch(
// add another input port when all inputs are connected, we want to add as many datasets as we can
() => props.node.inputs,
() => {
const inputs = props.node.inputs;
if (inputs.every((input) => input.status === WorkflowPortStatus.CONNECTED)) {
emit('append-input-port', { type: 'datasetId', labe: 'Dataset' });
}
},
{ deep: true }
);
</script>

<style scoped></style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<template>
<tera-drilldown :title="node.displayName" @on-close-clicked="emit('close')">
<template #header-actions>
<tera-operator-annotation
:state="node.state"
@update-state="(state: any) => emit('update-state', state)"
/>
</template>
<div class="background">
<Suspense>
<tera-dataset-jupyter-regridding-panel
:assets="assets"
:show-kernels="showKernels"
:show-chat-thoughts="showChatThoughts"
@new-dataset-saved="addOutputPort"
:notebook-session="notebookSession"
/>
</Suspense>
</div>
</tera-drilldown>
</template>

<script setup lang="ts">
// Proxy to use tera-dataset via a workflow context
import { WorkflowNode, WorkflowPortStatus } from '@/types/workflow';
import TeraDatasetJupyterRegriddingPanel from '@/components/dataset/tera-dataset-jupyter-regridding-panel.vue';
import { computed, onMounted, ref } from 'vue';
import { createNotebookSession, getNotebookSessionById } from '@/services/notebook-session';
import type { NotebookSession } from '@/types/Types';
import { cloneDeep } from 'lodash';
import { v4 as uuidv4 } from 'uuid';
import TeraDrilldown from '@/components/drilldown/tera-drilldown.vue';
import TeraOperatorAnnotation from '@/components/operator/tera-operator-annotation.vue';
import { RegriddingState } from './regridding-operation';
const props = defineProps<{
node: WorkflowNode<RegriddingState>;
}>();
const emit = defineEmits(['append-output', 'update-state', 'close']);
const showKernels = ref(<boolean>false);
const showChatThoughts = ref(<boolean>false);
const assets = computed(() =>
props.node.inputs
.filter((inputNode) => inputNode.status === WorkflowPortStatus.CONNECTED && inputNode.value)
.map((inputNode) => ({
type: inputNode.type,
id: inputNode.value![0]
}))
);
const notebookSession = ref(<NotebookSession | undefined>undefined);
onMounted(async () => {
const state = cloneDeep(props.node.state);
let notebookSessionId = props.node.state?.notebookSessionId;
if (!notebookSessionId) {
// create a new notebook session log if it does not exist
const response = await createNotebookSession({
id: uuidv4(),
name: props.node.id,
description: '',
data: { history: [] }
});
notebookSessionId = response?.id;
if (notebookSessionId) {
// update the node state with the notebook session id
state.notebookSessionId = notebookSessionId;
emit('update-state', state);
}
}
notebookSession.value = await getNotebookSessionById(notebookSessionId!);
});
const addOutputPort = (data: any) => {
emit('append-output', {
id: data.id,
label: data.name,
type: 'datasetId',
value: data.id
});
};
</script>

<style scoped>
.background {
background: white;
height: 100%;
overflow-y: auto;
}
</style>
7 changes: 6 additions & 1 deletion packages/client/hmi-client/src/workflow/tera-workflow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ import * as DocumentOp from './ops/document/mod';
import * as ModelFromDocumentOp from './ops/model-from-equations/mod';
import * as ModelComparisonOp from './ops/model-comparison/mod';
import * as DecapodesOp from './ops/decapodes/mod';
import * as RegriddingOp from './ops/regridding/mod';
const WORKFLOW_SAVE_INTERVAL = 8000;
Expand Down Expand Up @@ -277,6 +278,7 @@ registry.registerOp(DocumentOp);
registry.registerOp(ModelFromDocumentOp);
registry.registerOp(ModelComparisonOp);
registry.registerOp(DecapodesOp);
registry.registerOp(RegriddingOp);
// Will probably be used later to save the workflow in the project
const props = defineProps<{
Expand Down Expand Up @@ -550,7 +552,10 @@ const contextMenuItems: MenuItem[] = [
label: SubsetDataOp.operation.displayName,
command: addOperatorToWorkflow(SubsetDataOp)
},
{ label: 'Transform gridded dataset', disabled: true }
{
label: RegriddingOp.operation.displayName,
command: addOperatorToWorkflow(RegriddingOp)
}
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum WorkflowOperationTypes {
MODEL_COUPLING = 'ModelCoupling',
MODEL_EDIT = 'ModelEdit',
DOCUMENT = 'Document'
REGRIDDING = 'Regridding'
*/

ADD("add"),
Expand All @@ -48,6 +49,7 @@ public enum WorkflowOperationTypes {
OPTIMIZE_CIEMSS("OptimizeCiemss"),
MODEL_COUPLING("ModelCoupling"),
MODEL_EDIT("ModelEdit"),
REGRIDDING("Regridding"),
DOCUMENT("Document");

private final String value;
Expand Down

0 comments on commit be739c7

Please sign in to comment.