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

Ts/1871 task stratify a model workflow #2118

Merged
merged 27 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
22f8c92
new stratify mira
Tom-Szendrey Oct 5, 2023
4e57cfd
renaming operation to follow naming convs
Tom-Szendrey Oct 5, 2023
7e1778f
meant for last commit
Tom-Szendrey Oct 5, 2023
a2ef178
add strata-group-form component
Tom-Szendrey Oct 5, 2023
b31c6a8
reading model states/obs for group form
Tom-Szendrey Oct 5, 2023
0c91f34
first step in providing colour to group form
Tom-Szendrey Oct 5, 2023
50c879e
first iteration of state + colouring not working
Tom-Szendrey Oct 6, 2023
b0b2995
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Oct 11, 2023
891290d
no safeguarding colouring
Tom-Szendrey Oct 11, 2023
24190a9
deleteing, not sure if i need to use uuid > index
Tom-Szendrey Oct 11, 2023
73a19fc
removing uuid
Tom-Szendrey Oct 11, 2023
9b8f26f
adding cart product
Tom-Szendrey Oct 11, 2023
fa7b611
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Oct 18, 2023
b269784
var naming clarity
Tom-Szendrey Oct 18, 2023
9d84857
fixing font by using h4
Tom-Szendrey Oct 18, 2023
887fcde
stop warnings
Tom-Szendrey Oct 18, 2023
690db35
correcting enum
Tom-Szendrey Oct 19, 2023
feaadb7
minor fix
Tom-Szendrey Oct 19, 2023
d6e14d9
rename group form + very very start of mira ntebk
Tom-Szendrey Oct 23, 2023
ec0cb38
correcting new session args
Tom-Szendrey Oct 24, 2023
6f530ca
do not use ref for session
Tom-Szendrey Oct 24, 2023
7bcc251
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Oct 30, 2023
dd68c49
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Oct 30, 2023
ec6a551
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Oct 31, 2023
5ab01ea
changing tab enum var name
Tom-Szendrey Oct 31, 2023
f460807
good catch Shawn
Tom-Szendrey Oct 31, 2023
117b56c
Merge branch 'main' into TS/1871-task-stratify-a-model-workflow
mwdchang Oct 31, 2023
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
@@ -0,0 +1,50 @@
<template>
<h4>Code Editor</h4>
<Textarea class="codeBox" v-model="codeAsText" />
<Button label="Run" @click="hitMira" />
</template>

<script setup lang="ts">
import { ref, onUnmounted } from 'vue';
import Textarea from 'primevue/textarea';
import Button from 'primevue/button';
import { SessionContext } from '@jupyterlab/apputils/lib/sessioncontext';
import { newSession, JupyterMessage } from '@/services/jupyter';
import { createMessage } from '@jupyterlab/services/lib/kernel/messages';

const INITIAL_CODE =
"from mira.metamodel import ControlledConversion, NaturalConversion, Concept, Template \n infected = Concept(name='infected population', identifiers={'ido': '0000511'}) \n susceptible = Concept(name='susceptible population', identifiers={'ido': '0000514'}) \n immune = Concept(name='immune population', identifiers={'ido': '0000592'}) \n \n t1 = ControlledConversion(controller=infected, subject=susceptible, outcome=infected,) \n t2 = NaturalConversion(subject=infected, outcome=immune) \n t1.dict() \n ";

const codeAsText = ref(INITIAL_CODE);
const jupyterSession: SessionContext = await newSession('beaker', 'Beaker');

async function hitMira() {
if (!jupyterSession) return;

console.log('Trying to hit mira');
console.log(codeAsText);
const messageBody = {
session: jupyterSession.session?.name || '',
channel: 'shell',
content: codeAsText as any,
msgType: 'context_setup_request',
msgId: 'tgpt-context_setup_request'
};
const message: JupyterMessage = createMessage(messageBody);
console.log(jupyterSession.session);
jupyterSession.session?.kernel?.sendJupyterMessage(message);
console.log(jupyterSession.session);
}

onUnmounted(() => {
if (!jupyterSession) return;
jupyterSession.shutdown();
});
</script>

<style>
.codeBox {
width: 100%;
height: 50%;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<template>
<div class="strata-group" :style="`border-left: 9px solid ${props.config.borderColour}`">
<div class="sub-header">
<label for="strata-name">Cartesian product</label>
<InputSwitch v-model="cartesianProduct" />
<i class="trash-button pi pi-trash" @click="emit('delete-self', { index: props.index })" />
</div>
<div class="first-row">
<div class="age-group">
<label for="strata-name">Name of strata</label>
<InputText
id="strata-name"
v-model="strataName"
placeholder="Age group"
@focusout="emit('update-self', { index: props.index, updatedConfig: updatedConfig })"
/>
</div>
<div class="select-variables">
<label for="variables-select">Select variables and parameters to stratify</label>
<MultiSelect
id="variables-select"
v-model="selectedVariables"
:options="props.modelNodeOptions"
placeholder="Model states"
display="chip"
@update:model-value="
emit('update-self', { index: props.index, updatedConfig: updatedConfig })
"
></MultiSelect>
</div>
</div>
<div class="flex flex-column">
<label for="group-labels"
>Enter a comma separated list of labels for each group.
<span class="subdued-text">(Max 100)</span></label
>
<InputText
id="group-labels"
v-model="labels"
placeholder="Young, Old"
@focusout="emit('update-self', { index: props.index, updatedConfig: updatedConfig })"
/>
</div>
</div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue';
import InputText from 'primevue/inputtext';
import MultiSelect from 'primevue/multiselect';
import InputSwitch from 'primevue/inputswitch';
import { StratifyGroup } from '@/workflow/ops/stratify-mira/stratify-mira-operation';

const props = defineProps<{
modelNodeOptions: string[];
config: StratifyGroup;
index: number;
}>();

const emit = defineEmits(['delete-self', 'update-self']);

const strataName = ref(props.config.name);
const selectedVariables = ref<string[]>(props.config.selectedVariables);
const labels = ref(props.config.groupLabels);
const cartesianProduct = ref<boolean>(props.config.cartesianProduct);

const updatedConfig = computed<StratifyGroup>(() => ({
borderColour: props.config.borderColour,
name: strataName.value,
selectedVariables: selectedVariables.value,
groupLabels: labels.value,
cartesianProduct: cartesianProduct.value
}));
</script>

<style>
.strata-group {
margin: 1rem;
display: flex;
padding: 1rem 1rem 1rem 1.5rem;
flex-direction: column;
justify-content: center;
align-items: flex-start;
border-radius: 0.375rem;
background: #fff;
/* Shadow/medium */
box-shadow: 0px 2px 4px -1px rgba(0, 0, 0, 0.06), 0px 4px 6px -1px rgba(0, 0, 0, 0.08);
}

.sub-header {
display: flex;
padding-bottom: 0px;
justify-content: flex-end;
align-items: center;
gap: 1rem;
align-self: stretch;
}

.first-row {
display: flex;
}
.age-group {
display: flex;
flex-direction: column;
padding-right: 2rem;
padding-bottom: 1rem;
}

.select-variables {
display: flex;
flex-direction: column;
}

.subdued-text {
color: var(--text-color-subdued);
}

.trash-button {
cursor: pointer;
}
</style>
4 changes: 3 additions & 1 deletion packages/client/hmi-client/src/page/WorkflowNode.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<template>
<template v-if="node">
<tera-model-workflow-wrapper v-if="isNodeType(OperationType.MODEL)" :node="node" />
<tera-stratify-julia v-else-if="isNodeType(OperationType.STRATIFY)" :node="node" />
<tera-stratify-julia v-else-if="isNodeType(OperationType.STRATIFY_JULIA)" :node="node" />
<tera-stratify-mira v-else-if="isNodeType(OperationType.STRATIFY_MIRA)" :node="node" />
<tera-dataset-transformer
v-else-if="isNodeType(OperationType.DATASET_TRANSFORMER)"
:node="node"
Expand Down Expand Up @@ -38,6 +39,7 @@ import TeraCalibrateEnsembleCiemss from '@/workflow/ops/calibrate-ensemble-ciems
import TeraSimulateCiemss from '@/workflow/ops/simulate-ciemss/tera-simulate-ciemss.vue';
import TeraSimulateEnsembleCiemss from '@/workflow/ops/simulate-ensemble-ciemss/tera-simulate-ensemble-ciemss.vue';
import TeraStratifyJulia from '@/workflow/ops/stratify-julia/tera-stratify.vue';
import teraStratifyMira from '@/workflow/ops/stratify-mira/tera-stratify-mira.vue';

const props = defineProps<{ nodeId: string; workflowId: string }>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@
"
:node="workflowNode"
/>
<tera-stratify-mira
v-if="workflowNode && workflowNode.operationType === WorkflowOperationTypes.STRATIFY_MIRA"
:node="workflowNode"
/>
<tera-stratify
v-if="workflowNode && workflowNode.operationType === WorkflowOperationTypes.STRATIFY"
v-if="
workflowNode && workflowNode.operationType === WorkflowOperationTypes.STRATIFY_JULIA
"
:node="workflowNode"
:key="workflowNode.id"
@open-asset="openAsset"
Expand Down Expand Up @@ -123,6 +129,7 @@ import TeraDatasetWorkflowWrapper from '@//workflow/ops/dataset/tera-dataset-wor
import TeraCalibrateJulia from '@/workflow/ops/calibrate-julia/tera-calibrate-julia.vue';
import TeraCalibrateCiemss from '@/workflow/ops/calibrate-ciemss/tera-calibrate-ciemss.vue';
import TeraSimulateJulia from '@/workflow/ops/simulate-julia/tera-simulate-julia.vue';
import TeraStratifyMira from '@/workflow/ops/stratify-mira/tera-stratify-mira.vue';
import TeraStratify from '@/workflow/ops/stratify-julia/tera-stratify.vue';
import TeraSimulateCiemss from '@/workflow/ops/simulate-ciemss/tera-simulate-ciemss.vue';
import teraSimulateEnsembleCiemss from '@/workflow/ops/simulate-ensemble-ciemss/tera-simulate-ensemble-ciemss.vue';
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 @@ -7,7 +7,8 @@ export enum WorkflowOperationTypes {
MODEL = 'ModelOperation',
SIMULATE_JULIA = 'SimulateJuliaOperation',
SIMULATE_CIEMSS = 'SimulateCiemssOperation',
STRATIFY = 'Stratify',
STRATIFY_JULIA = 'StratifyJulia',
STRATIFY_MIRA = 'StratifyMira',
SIMULATE_ENSEMBLE_CIEMSS = 'SimulateEnsembleCiemms',
CALIBRATE_ENSEMBLE_CIEMSS = 'CalibrateEnsembleCiemms',
DATASET_TRANSFORMER = 'DatasetTransformer',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Operation, WorkflowOperationTypes } from '@/types/workflow';

export const StratifyOperation: Operation = {
name: WorkflowOperationTypes.STRATIFY,
name: WorkflowOperationTypes.STRATIFY_JULIA,
displayName: 'Stratify',
description: 'Stratify a model',
inputs: [{ type: 'modelConfigId', label: 'Model configuration', acceptMultiple: false }],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './stratify-mira-operation';
export { default as TeraStratifyMira } from './tera-stratify-mira.vue';
export { default as TeraStratifyNodeMira } from './tera-stratify-node-mira.vue';
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Operation, WorkflowOperationTypes } from '@/types/workflow';

export interface StratifyGroup {
borderColour: string;
name: string;
selectedVariables: string[];
groupLabels: string;
cartesianProduct: boolean;
}

export interface StratifyOperationStateMira {
strataGroups: StratifyGroup[];
}

export const StratifyMiraOperation: Operation = {
name: WorkflowOperationTypes.STRATIFY_MIRA,
displayName: 'Stratify MIRA',
description: 'Stratify a model',
inputs: [{ type: 'modelConfigId', label: 'Model configuration', acceptMultiple: false }],
mwdchang marked this conversation as resolved.
Show resolved Hide resolved
outputs: [{ type: 'model' }],
isRunnable: false,
action: () => {},
initState: () => {
const init: StratifyOperationStateMira = {
strataGroups: [
{
borderColour: '#c300a6',
name: '',
selectedVariables: [],
groupLabels: '',
cartesianProduct: true
}
]
};
return init;
}
};
Loading