Skip to content

Commit

Permalink
display model fit error
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Nov 5, 2023
1 parent 994eb8b commit 6a95fa0
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 24 deletions.
9 changes: 9 additions & 0 deletions app/static/src/app/components/fit/FitTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<div v-if="cancelled" id="fit-cancelled-msg" class="small text-danger">{{cancelledMsg}}</div>
</div>
</fit-plot>
<error-info :error="error"></error-info>
</div>
</div>
</template>
Expand All @@ -39,10 +40,12 @@ import { ModelFitMutation } from "../../store/modelFit/mutations";
import { fitRequirementsExplanation, fitUpdateRequiredExplanation } from "./support";
import { allTrue, anyTrue } from "../../utils";
import LoadingButton from "../LoadingButton.vue";
import ErrorInfo from "@/app/components/ErrorInfo.vue";
export default defineComponent({
name: "FitTab",
components: {
ErrorInfo,
LoadingSpinner,
FitPlot,
ActionRequiredMessage,
Expand All @@ -57,6 +60,7 @@ export default defineComponent({
const canFitModel = computed(() => allTrue(fitRequirements.value));
const compileRequired = computed(() => store.state.model.compileRequired);
const fitUpdateRequired = computed(() => store.state.modelFit.fitUpdateRequired);
const error = computed(() => store.state.modelFit.error);
const fitModel = () => store.dispatch(`${namespace}/${ModelFitAction.FitModel}`);
const cancelFit = () => store.commit(`${namespace}/${ModelFitMutation.SetFitting}`, false);
Expand All @@ -68,6 +72,10 @@ export default defineComponent({
const sumOfSquares = computed(() => store.state.modelFit.sumOfSquares);
const actionRequiredMessage = computed(() => {
if (error.value) {
return userMessages.modelFit.errorOccurred;
}
if (!allTrue(fitRequirements.value)) {
return fitRequirementsExplanation(fitRequirements.value);
}
Expand Down Expand Up @@ -119,6 +127,7 @@ export default defineComponent({
cancelledMsg,
sumOfSquares,
actionRequiredMessage,
error,
iconType,
iconClass
};
Expand Down
3 changes: 2 additions & 1 deletion app/static/src/app/serialise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ function serialiseModelFit(modelFit: ModelFitState): SerialisedModelFitState {
converged: modelFit.converged,
sumOfSquares: modelFit.sumOfSquares,
paramsToVary: modelFit.paramsToVary,
result: serialiseSolutionResult(modelFit.result)
result: serialiseSolutionResult(modelFit.result),
error: modelFit.error
};
}

Expand Down
3 changes: 2 additions & 1 deletion app/static/src/app/store/appState/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export enum AppStateMutation {
export const StateUploadMutations = [
AppStateMutation.ClearQueuedStateUpload,
AppStateMutation.SetQueuedStateUpload,
AppStateMutation.SetStateUploadInProgress
AppStateMutation.SetStateUploadInProgress,
AppStateMutation.SetPersisted
] as string[];

export const appStateMutations: MutationTree<AppState> = {
Expand Down
40 changes: 22 additions & 18 deletions app/static/src/app/store/modelFit/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,28 @@ export const actions: ActionTree<ModelFitState, FitState> = {
const { advancedSettings } = rootState.run;
const advancedSettingsOdin = convertAdvancedSettingsToOdin(advancedSettings, pars.base);

const simplex = odinRunnerOde!.wodinFit(
odin!,
data,
pars,
linkedVariable,
advancedSettingsOdin,
{}
);

const inputs = {
data,
endTime,
link
};

commit(ModelFitMutation.SetFitUpdateRequired, null);
commit(ModelFitMutation.SetInputs, inputs);
dispatch(ModelFitAction.FitModelStep, simplex);
try {
const simplex = odinRunnerOde!.wodinFit(
odin!,
data,
pars,
linkedVariable,
advancedSettingsOdin,
{}
);

const inputs = {
data,
endTime,
link
};
commit(ModelFitMutation.SetFitUpdateRequired, null);
commit(ModelFitMutation.SetInputs, inputs);
dispatch(ModelFitAction.FitModelStep, simplex);
} catch (e: unknown) {
commit(ModelFitMutation.SetError, {error: "Model fit error", detail: (e as Error).message});
commit(ModelFitMutation.SetFitting, false);
}
}
},

Expand Down
3 changes: 2 additions & 1 deletion app/static/src/app/store/modelFit/modelFit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export const defaultState: ModelFitState = {
sumOfSquares: null,
paramsToVary: [],
inputs: null,
result: null
result: null,
error: null
};

export const modelFit = {
Expand Down
12 changes: 10 additions & 2 deletions app/static/src/app/store/modelFit/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { MutationTree } from "vuex";
import { ModelFitInputs, ModelFitState, FitUpdateRequiredReasons } from "./state";
import { SimplexResult } from "../../types/responseTypes";
import {SimplexResult, WodinError} from "../../types/responseTypes";

export enum ModelFitMutation {
SetFitting = "SetFitting",
SetResult = "SetResult",
SetInputs = "SetInputs",
SetParamsToVary = "SetParamsToVary",
SetSumOfSquares = "SetSumOfSquares",
SetFitUpdateRequired = "SetFitUpdateRequired"
SetFitUpdateRequired = "SetFitUpdateRequired",
SetError = "SetError"
}

export const mutations: MutationTree<ModelFitState> = {
[ModelFitMutation.SetFitting](state: ModelFitState, payload: boolean) {
state.fitting = payload;
if (payload) {
state.error = null
}
},

[ModelFitMutation.SetResult](state: ModelFitState, payload: SimplexResult) {
Expand Down Expand Up @@ -43,6 +47,10 @@ export const mutations: MutationTree<ModelFitState> = {
state.sumOfSquares = payload;
},

[ModelFitMutation.SetError](state: ModelFitState, payload: WodinError) {
state.error = payload;
},

[ModelFitMutation.SetFitUpdateRequired](state: ModelFitState, payload: null | Partial<FitUpdateRequiredReasons>) {
if (payload === null) {
state.fitUpdateRequired = {
Expand Down
2 changes: 2 additions & 0 deletions app/static/src/app/store/modelFit/state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OdinFitResult } from "../../types/wrapperTypes";
import type { FitData, FitDataLink } from "../fitData/state";
import {WodinError} from "../../types/responseTypes";

export interface ModelFitInputs {
data: FitData;
Expand All @@ -25,6 +26,7 @@ export interface ModelFitState {
paramsToVary: string[],
inputs: ModelFitInputs | null, // all inputs except parameters, which vary
result: OdinFitResult | null, // full solution for current best fit,
error: null | WodinError
}

export interface ModelFitRequirements {
Expand Down
3 changes: 2 additions & 1 deletion app/static/src/app/types/serialisationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export interface SerialisedModelFitState {
converged: boolean | null,
sumOfSquares: number | null,
paramsToVary: string[],
result: SerialisedRunResult | null
result: SerialisedRunResult | null,
error: null | WodinError
}

export interface SerialisedAppState {
Expand Down
1 change: 1 addition & 0 deletions app/static/src/app/userMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default {
notFittedYet: "Model has not been fitted.",
selectParamToVary: "Please select at least one parameter to vary during model fit.",
compileRequired: "Model code has been updated. Compile code and Fit Model for updated best fit.",
errorOccurred: "An error occurred during model fit.",
updateFitReasons: {
prefix: "Fit is out of date:",
unknown: "unknown reasons, contact the administrator, as this is unexpected",
Expand Down

0 comments on commit 6a95fa0

Please sign in to comment.