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 new plumbing #4112

Merged
merged 47 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
639b07e
remove intervention policy group form.
Tom-Szendrey Jul 9, 2024
919b17b
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Jul 9, 2024
71ef5cc
undoing file rename for PR clarity
Tom-Szendrey Jul 9, 2024
06b5333
more clarity on isEditingName
Tom-Szendrey Jul 9, 2024
318a976
Thanks Dan, Cole
Tom-Szendrey Jul 9, 2024
0745b3b
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Jul 9, 2024
010d1ba
Merge branch 'TS/4079-task-optimize-cleanup' of https://github.com/DA…
Tom-Szendrey Jul 9, 2024
27f4126
TEMP CHANGES
Tom-Szendrey Jul 9, 2024
4f72a72
assigning optimizationType properly
Tom-Szendrey Jul 9, 2024
7670438
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Jul 9, 2024
7807ce2
updaing static default.
Tom-Szendrey Jul 9, 2024
b764e1f
update default
Tom-Szendrey Jul 9, 2024
0d6b4cc
Name is intervention name not editable.
Tom-Szendrey Jul 9, 2024
75f9e5f
interention is not optional.
Tom-Szendrey Jul 9, 2024
0cd06b8
we should not store disabled here as its temporary
Tom-Szendrey Jul 9, 2024
1497ec9
renaming group to group form
Tom-Szendrey Jul 9, 2024
728983c
reset policy groups only when required.
Tom-Szendrey Jul 9, 2024
bd851fe
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Jul 9, 2024
e2e2342
adding clarifying todo
Tom-Szendrey Jul 9, 2024
655c3e4
why provide what we are already providing?
Tom-Szendrey Jul 9, 2024
047b777
cannot optimize on grouped up static interventions
Tom-Szendrey Jul 9, 2024
836230a
fix emits first pass.
Tom-Szendrey Jul 9, 2024
a4b55d5
correcting emit call for tera input
Tom-Szendrey Jul 9, 2024
013f909
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Jul 9, 2024
1f7e05e
no longer 100 - our shit to get alpha
Tom-Szendrey Jul 9, 2024
44736d2
do not allow for both options at the moment
Tom-Szendrey Jul 9, 2024
6c466f2
remove for loop and update some naming
Tom-Szendrey Jul 9, 2024
63529fc
remove defaults. add enum. rename obj fun
Tom-Szendrey Jul 9, 2024
267f3ca
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Jul 9, 2024
360a521
shared const with enums
Tom-Szendrey Jul 9, 2024
63c7892
minor correction
Tom-Szendrey Jul 9, 2024
3cad774
on-focus-out was not working.
Tom-Szendrey Jul 9, 2024
ccd0268
previous naming was better - whoops
Tom-Szendrey Jul 10, 2024
2575654
correct sentence structure
Tom-Szendrey Jul 10, 2024
1a59882
will need to add css later to make this prettier
Tom-Szendrey Jul 10, 2024
0fcc33e
reformat for space between parameter and appliedto
Tom-Szendrey Jul 10, 2024
82f4632
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Jul 10, 2024
200160e
updating optimize request type and call
Tom-Szendrey Jul 11, 2024
55c60a8
updating typing and naming
Tom-Szendrey Jul 11, 2024
c050f63
chore: lint and format server codebase
github-actions[bot] Jul 12, 2024
a404958
minor updates to activePolicyGroups
Tom-Szendrey Jul 12, 2024
51745e6
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Jul 12, 2024
2524133
Update packages/client/hmi-client/src/components/workflow/ops/optimiz…
Tom-Szendrey Jul 12, 2024
db4f984
Update packages/client/hmi-client/src/components/workflow/ops/optimiz…
Tom-Szendrey Jul 12, 2024
ef8c5ff
Update packages/client/hmi-client/src/components/workflow/ops/optimiz…
Tom-Szendrey Jul 12, 2024
1d0abbe
inActivePolicyGroups -> inactivePolicyGroups
Tom-Szendrey Jul 12, 2024
2b76859
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Jul 15, 2024
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 @@ -130,8 +130,7 @@ export const OptimizeCiemssOperation: Operation = {
{
type: 'policyInterventionId',
label: 'Interventions',
acceptMultiple: false,
isOptional: true
acceptMultiple: false
}
],
outputs: [{ type: 'simulationId' }],
Expand Down Expand Up @@ -168,11 +167,11 @@ export async function getOptimizedInterventions(optimizeRunId: string) {
const simulation = await getSimulation(optimizeRunId);
const simulationIntervetions =
simulation?.executionPayload.fixed_static_parameter_interventions ?? [];
const policyInterventions = simulation?.executionPayload?.policy_interventions;
const interventionType = policyInterventions.selection ?? '';
const paramNames: string[] = policyInterventions.param_names ?? [];
const paramValue: number[] = policyInterventions.param_values ?? [];
const startTime: number[] = policyInterventions.start_time ?? [];
const optimizeInterventions = simulation?.executionPayload?.optimize_interventions;
const interventionType = optimizeInterventions.intervention_type ?? '';
const paramNames: string[] = optimizeInterventions.param_names ?? [];
const paramValue: number[] = optimizeInterventions.param_values ?? [];
const startTime: number[] = optimizeInterventions.start_time ?? [];

const policyResult = await getRunResult(optimizeRunId, 'policy.json');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,10 @@ import {
ModelParameter,
OptimizeRequestCiemss,
CsvAsset,
PolicyInterventions,
OptimizeInterventions,
OptimizeQoi,
InterventionPolicy
InterventionPolicy,
Intervention
} from '@/types/Types';
import { logger } from '@/utils/logger';
import { chartActionsProxy, drilldownChartSize, nodeMetadata } from '@/components/workflow/util';
Expand Down Expand Up @@ -404,6 +405,14 @@ const isSaveDisabled = computed<boolean>(() =>
isSaveDatasetDisabled(props.node.state.postForecastRunId, useProjects().activeProject.value?.id)
);
const activePolicyGroups = computed(() =>
props.node.state.interventionPolicyGroups.filter((ele) => ele.isActive === true)
);
const inactivePolicyGroups = computed(() =>
props.node.state.interventionPolicyGroups.filter((ele) => ele.isActive === false)
);
const menuItems = computed(() => [
{
label: 'Save as a new model configuration',
Expand Down Expand Up @@ -450,11 +459,13 @@ const outputs = computed(() => {
const isRunDisabled = computed(() => {
if (
!props.node.state.constraintGroups?.at(0)?.targetVariable ||
props.node.state.interventionPolicyGroups.length === 0
props.node.state.interventionPolicyGroups.length === 0 ||
activePolicyGroups.value.length <= 0
)
return true;
return false;
});
const selectedOutputId = ref<string>();
const outputViewSelection = ref(OutputView.Charts);
Expand Down Expand Up @@ -573,23 +584,36 @@ const runOptimize = async () => {
const startTime: number[] = [];
const listInitialGuessInterventions: number[] = [];
const listBoundsInterventions: number[][] = [];
props.node.state.interventionPolicyGroups.forEach((ele) => {
const initialGuess: number[] = [];
const objectiveFunctionOption: string[] = [];
activePolicyGroups.value.forEach((ele) => {
paramNames.push(ele.intervention.appliedTo);
paramValues.push(ele.intervention.staticInterventions[0].value);
startTime.push(ele.startTime);
initialGuess.push(ele.initialGuessValue);
objectiveFunctionOption.push(ele.objectiveFunctionOption);
listInitialGuessInterventions.push(ele.initialGuessValue);
listBoundsInterventions.push([ele.lowerBoundValue]);
listBoundsInterventions.push([ele.upperBoundValue]);
});
const interventionType = props.node.state.interventionPolicyGroups[0].optimizationType;
const optimizeInterventions: PolicyInterventions = {
// These are interventions to be optimized over.
const optimizeInterventions: OptimizeInterventions = {
interventionType,
paramNames,
startTime,
paramValues
paramValues,
initialGuess,
objectiveFunctionOption
};
// These are interventions to be considered but not optimized over.
const fixedStaticParameterInterventions: Intervention[] = _.cloneDeep(
inactivePolicyGroups.value.map((ele) => ele.intervention)
);
// TODO: https://github.com/DARPA-ASKEM/terarium/issues/3909
// The method should be a list but pyciemss + pyciemss service is not yet ready for this.
const qoi: OptimizeQoi = {
Expand All @@ -605,7 +629,8 @@ const runOptimize = async () => {
start: 0,
end: knobs.value.endTime
},
policyInterventions: optimizeInterventions,
optimizeInterventions,
fixedStaticParameterInterventions,
qoi,
riskBound: props.node.state.constraintGroups[0].threshold, // TODO: https://github.com/DARPA-ASKEM/terarium/issues/3909
initialGuessInterventions: listInitialGuessInterventions,
Expand All @@ -620,9 +645,11 @@ const runOptimize = async () => {
}
};
// InferredParameters is to link a calibration run to this optimize call.
if (inferredParameters.value) {
optimizePayload.extra.inferredParameters = inferredParameters.value[0];
}
const optResult = await makeOptimizeJobCiemss(optimizePayload, nodeMetadata(props.node));
const state = _.cloneDeep(props.node.state);
state.inProgressOptimizeId = optResult.simulationId;
Expand Down
18 changes: 10 additions & 8 deletions packages/client/hmi-client/src/types/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@ export interface EnsembleSimulationCiemssRequest {
export interface OptimizeRequestCiemss {
modelConfigId: string;
timespan: TimeSpan;
policyInterventions?: PolicyInterventions;
fixedStaticParameterInterventions?: string;
optimizeInterventions?: OptimizeInterventions;
fixedStaticParameterInterventions?: Intervention[];
stepSize?: number;
qoi: OptimizeQoi;
riskBound: number;
Expand Down Expand Up @@ -803,16 +803,18 @@ export interface OptimizeExtra {
solverMethod?: string;
}

export interface OptimizeQoi {
contexts: string[];
method: string;
}

export interface PolicyInterventions {
export interface OptimizeInterventions {
interventionType: string;
paramNames: string[];
paramValues?: number[];
startTime?: number[];
objectiveFunctionOption?: string[];
initialGuess?: number[];
}

export interface OptimizeQoi {
contexts: string[];
method: string;
}

export interface TimeSpan {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import lombok.experimental.Accessors;
import software.uncharted.terarium.hmiserver.annotations.TSModel;
import software.uncharted.terarium.hmiserver.annotations.TSOptional;
import software.uncharted.terarium.hmiserver.models.simulationservice.interventions.Intervention;
import software.uncharted.terarium.hmiserver.models.simulationservice.parts.OptimizeExtra;
import software.uncharted.terarium.hmiserver.models.simulationservice.parts.OptimizeInterventions;
import software.uncharted.terarium.hmiserver.models.simulationservice.parts.OptimizeQoi;
import software.uncharted.terarium.hmiserver.models.simulationservice.parts.PolicyInterventions;
import software.uncharted.terarium.hmiserver.models.simulationservice.parts.TimeSpan;

@Data
Expand All @@ -25,10 +26,11 @@ public class OptimizeRequestCiemss implements Serializable {

@TSOptional
// https://github.com/DARPA-ASKEM/pyciemss-service/blob/main/service/models/operations/optimize.py#L80
private PolicyInterventions policyInterventions;
private OptimizeInterventions optimizeInterventions;

@TSOptional
private UUID fixedStaticParameterInterventions;
@JsonAlias("fixed_static_parameter_interventions")
private List<Intervention> fixedStaticParameterInterventions;

@JsonAlias("step_size")
@TSOptional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Accessors(chain = true)
@TSModel
// Interventions applied by the user within the optimization box.
public class PolicyInterventions {
public class OptimizeInterventions {
// This denotes whether the intervention is on a start date, or a parameter value.
// https://github.com/DARPA-ASKEM/pyciemss-service/blob/main/service/models/operations/optimize.py#L99
private String interventionType;
Expand All @@ -27,6 +27,14 @@ public class PolicyInterventions {
@JsonAlias("start_time")
private List<Integer> startTime;

@TSOptional
@JsonAlias("objective_function_option")
private List<String> objectiveFunctionOption;

@TSOptional
@JsonAlias("initial_guess")
private List<Double> initialGuess;

@Override
public String toString() {
return " { Parameter Names: " + this.paramNames + " start time: " + startTime.toString() + " } ";
Expand Down
Loading