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 constraint - adding observables #4564

Merged
merged 7 commits into from
Sep 3, 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
Expand Up @@ -41,7 +41,7 @@ export interface InterventionPolicyGroupForm {

export interface Criterion {
name: string; // Title of the group
targetVariable: string;
targetVariable: string; // qoi context which will contain _state or _observable accordingly
qoiMethod: ContextMethods;
riskTolerance: number;
threshold: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,12 @@ const model = ref<Model | null>(null);
const modelParameterOptions = computed<string[]>(() =>
(model.value?.semantics?.ode?.parameters ?? []).map((p) => p.id)
);
const modelStateAndObsOptions = ref<string[]>([]);
const modelStateAndObsOptions = ref<{ label: string; value: string }[]>([]);

const simulationChartOptions = computed(() => [...modelParameterOptions.value, ...modelStateAndObsOptions.value]);
const simulationChartOptions = computed(() => [
...modelParameterOptions.value,
...modelStateAndObsOptions.value.map((ele) => ele.label)
]);
const modelConfiguration = ref<ModelConfiguration>();

const showAdditionalOptions = ref(true);
Expand Down Expand Up @@ -655,14 +658,22 @@ const initialize = async () => {
if (optimizedPolicyId) {
optimizedInterventionPolicy.value = await getInterventionPolicyById(optimizedPolicyId);
}

modelStateAndObsOptions.value = model.value?.model.states.map((state: any) => state.id);

/** Until supported by pyciemss-service, do not show observables.
if (model?.semantics?.ode.observables) {
modelStateAndObsOptions.value.push(...model.semantics.ode.observables.map((observable: any) => observable.id));
const modelStates = model.value?.model.states;
modelStateAndObsOptions.value = modelStates.map((state: any) => ({
label: state.id,
value: `${state.id}_state`
}));

// Add obs:
const modelObs = model.value?.semantics?.ode.observables;
if (modelObs) {
modelStateAndObsOptions.value.push(
...modelObs.map((observable: any) => ({
label: observable.id,
value: `${observable.id}_observable`
}))
mwdchang marked this conversation as resolved.
Show resolved Hide resolved
);
}
*/
};

const setInterventionPolicyGroups = (interventionPolicy: InterventionPolicy) => {
Expand Down Expand Up @@ -776,7 +787,7 @@ const runOptimize = async () => {

// InferredParameters is to link a calibration run to this optimize call.
optimizePayload.extra.inferredParameters = modelConfiguration.value.simulationId;

console.log(optimizePayload);
const optResult = await makeOptimizeJobCiemss(optimizePayload, nodeMetadata(props.node));
const state = _.cloneDeep(props.node.state);
state.inProgressOptimizeId = optResult.simulationId;
Expand All @@ -799,7 +810,13 @@ const setOutputSettingDefaults = () => {
if (!knobs.value.selectedSimulationVariables.length) {
props.node.state.constraintGroups.forEach((constraint) => {
if (constraint.targetVariable) {
selectedSimulationVariables.push(constraint.targetVariable);
// Use modelStateAndObsOptions to map from value -> label as simulation selection uses S not S_State
const userSelection = modelStateAndObsOptions.value.find(
(ele) => ele.value === constraint.targetVariable
)?.label;
if (userSelection) {
selectedSimulationVariables.push(userSelection);
}
}
});
if (selectedSimulationVariables.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<Dropdown
class="p-inputtext-sm"
:options="modelStateAndObsOptions"
option-label="label"
option-value="value"
v-model="config.targetVariable"
placeholder="Select"
@update:model-value="emit('update-self', config)"
Expand Down Expand Up @@ -77,7 +79,7 @@ import { Criterion, ContextMethods } from './optimize-ciemss-operation';

const props = defineProps<{
criterion: Criterion;
modelStateAndObsOptions: string[];
modelStateAndObsOptions: { label: string; value: string }[];
}>();

const emit = defineEmits(['update-self', 'delete-self']);
Expand Down
5 changes: 2 additions & 3 deletions packages/client/hmi-client/src/services/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,8 @@ export function createSuccessCriteriaChart(
alpha: number,
options: BaseChartOptions
): any {
const targetState = `${targetVariable}_state`;
const data = riskResults[targetState]?.qoi || [];
const risk = riskResults[targetState]?.risk?.[0] || 0;
const data = riskResults[targetVariable]?.qoi || [];
const risk = riskResults[targetVariable]?.risk?.[0] || 0;
const binCount = Math.floor(Math.sqrt(data.length)) ?? 1;
const alphaPercentile = percentile(data, alpha);

Expand Down
Loading