Skip to content
Draft
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
6 changes: 2 additions & 4 deletions apps/class-solid/src/lib/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ const asyncRunner = wrap<typeof runClass>(worker);

export async function runClassAsync(config: Config): Promise<ClassOutput> {
try {
const output = asyncRunner(config);
return output;
return await asyncRunner(config);
} catch (error) {
console.error({ config, error });
// TODO use toast to give feedback to the user
throw error;
}
throw new Error("Model run failed");
}
32 changes: 27 additions & 5 deletions apps/class-solid/src/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
mergeConfigurations,
pruneConfig,
} from "@classmodel/class/config_utils";
import { showToast } from "~/components/ui/toast";
import { decodeAppState } from "./encode";
import { parseExperimentConfig } from "./experiment_config";
import type { ExperimentConfig } from "./experiment_config";
Expand Down Expand Up @@ -38,9 +39,19 @@ export async function runExperiment(id: number) {

// Run reference
const referenceConfig = unwrap(exp.config.reference);
const newOutput = await runClassAsync(referenceConfig);

setExperiments(id, "output", "reference", newOutput);
try {
const newOutput = await runClassAsync(referenceConfig);
setExperiments(id, "output", "reference", newOutput);
} catch (error) {
showToast({
title: "Error running reference configuration",
description: `${(error as Error).message}; Please correct configuration and try again.`,
variant: "destructive",
duration: Number.POSITIVE_INFINITY,
});
setExperiments(id, "output", "running", false);
return;
}

// Run permutations
let permCounter = 0;
Expand All @@ -50,8 +61,19 @@ export async function runExperiment(id: number) {
referenceConfig,
permConfig,
) as Config;
const newOutput = await runClassAsync(combinedConfig);
setExperiments(id, "output", "permutations", permCounter, newOutput);
try {
const newOutput = await runClassAsync(combinedConfig);
setExperiments(id, "output", "permutations", permCounter, newOutput);
} catch (error) {
showToast({
title: `Error running permutation: ${permConfig.name}`,
description: `${(error as Error).message}. Please correct configuration and try again.`,
variant: "destructive",
duration: Number.POSITIVE_INFINITY,
});
setExperiments(id, "output", "running", false);
return;
}
permCounter++;
}

Expand Down
5 changes: 5 additions & 0 deletions packages/class/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export function runClass(config: Config, freq = 600): ClassOutput {
// Initial time
writeOutput();

// TODO remove when we see this error rendered
if (config.runtime === 42_000) {
throw new Error("Runtime cannot be 42_000 seconds.");
}

// Update loop
while (model.t <= config.runtime) {
model.update();
Expand Down