Skip to content

Commit aac745a

Browse files
committed
Move outputs back into experiments store
Partially reverts 0dff547
1 parent 00180dd commit aac745a

File tree

3 files changed

+34
-87
lines changed

3 files changed

+34
-87
lines changed

apps/class-solid/src/components/Analysis.tsx

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { For, Match, Show, Switch, createMemo, createUniqueId } from "solid-js";
22
import { getVerticalProfiles } from "~/lib/profiles";
3-
import {
4-
type Analysis,
5-
deleteAnalysis,
6-
experiments,
7-
outputForExperiment,
8-
outputForPermutation,
9-
} from "~/lib/store";
3+
import { type Analysis, deleteAnalysis, experiments } from "~/lib/store";
104
import LinePlot from "./LinePlot";
115
import { MdiCog, MdiContentCopy, MdiDelete, MdiDownload } from "./icons";
126
import { Button } from "./ui/button";
@@ -37,21 +31,22 @@ export function TimeSeriesPlot() {
3731
return experiments
3832
.filter((e) => e.running === false) // Skip running experiments
3933
.flatMap((e, i) => {
40-
const experimentOutput = outputForExperiment(e);
41-
const permutationRuns = e.permutations.map((perm, j) => {
42-
const permOutput = outputForPermutation(experimentOutput, j);
43-
return {
44-
label: `${e.name}/${perm.name}`,
45-
y: permOutput.h ?? [],
46-
x: permOutput.t ?? [],
47-
color: colors[(j + 1) % 10],
48-
linestyle: linestyles[i % 5],
49-
};
50-
});
34+
const experimentOutput = e.reference.output;
35+
const permutationRuns = e.permutations
36+
.filter((perm) => perm.output !== undefined)
37+
.map((perm, j) => {
38+
return {
39+
label: `${e.name}/${perm.name}`,
40+
y: perm.output?.h ?? [],
41+
x: perm.output?.t ?? [],
42+
color: colors[(j + 1) % 10],
43+
linestyle: linestyles[i % 5],
44+
};
45+
});
5146
return [
5247
{
53-
y: experimentOutput?.reference.h ?? [],
54-
x: experimentOutput?.reference.t ?? [],
48+
y: experimentOutput?.h ?? [],
49+
x: experimentOutput?.t ?? [],
5550
label: e.name,
5651
color: colors[0],
5752
linestyle: linestyles[i],
@@ -77,16 +72,14 @@ export function VerticalProfilePlot() {
7772
return experiments
7873
.filter((e) => e.running === false) // Skip running experiments
7974
.flatMap((e, i) => {
80-
const experimentOutput = outputForExperiment(e);
8175
const permutations = e.permutations.map((p, j) => {
8276
// TODO get additional config info from reference
8377
// permutations probably usually don't have gammaq/gammatetha set?
84-
const permOutput = outputForPermutation(experimentOutput, j);
8578
return {
8679
color: colors[(j + 1) % 10],
8780
linestyle: linestyles[i % 5],
8881
label: `${e.name}/${p.name}`,
89-
...getVerticalProfiles(permOutput, p.config, variable, time),
82+
...getVerticalProfiles(p.output, p.config, variable, time),
9083
};
9184
});
9285

@@ -96,7 +89,7 @@ export function VerticalProfilePlot() {
9689
color: colors[0],
9790
linestyle: linestyles[i],
9891
...getVerticalProfiles(
99-
experimentOutput?.reference ?? {
92+
e.reference.output ?? {
10093
t: [],
10194
h: [],
10295
theta: [],
@@ -127,27 +120,19 @@ function FinalHeights() {
127120
<For each={experiments}>
128121
{(experiment) => {
129122
const h = () => {
130-
const experimentOutput = outputForExperiment(experiment);
131-
return (
132-
experimentOutput?.reference.h[
133-
experimentOutput.reference.h.length - 1
134-
] || 0
135-
);
123+
const experimentOutput = experiment.reference.output;
124+
return experimentOutput?.h[experimentOutput?.h.length - 1] || 0;
136125
};
137126
return (
138127
<Show when={!experiment.running}>
139128
<li class="mb-2" title={experiment.name}>
140129
{experiment.name}: {h().toFixed()} m
141130
</li>
142131
<For each={experiment.permutations}>
143-
{(perm, permIndex) => {
132+
{(perm) => {
144133
const h = () => {
145-
const experimentOutput = outputForExperiment(experiment);
146-
const permOutput = outputForPermutation(
147-
experimentOutput,
148-
permIndex(),
149-
);
150-
return permOutput.h?.length
134+
const permOutput = perm.output;
135+
return permOutput?.h?.length
151136
? permOutput.h[permOutput.h.length - 1]
152137
: 0;
153138
};

apps/class-solid/src/lib/download.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ClassOutput } from "@classmodel/class/runner";
22
import type { ExperimentConfigSchema } from "@classmodel/class/validate";
33
import { BlobReader, BlobWriter, ZipWriter } from "@zip.js/zip.js";
4-
import { type Experiment, outputForExperiment } from "./store";
4+
import type { Experiment } from "./store";
55

66
export function toConfig(experiment: Experiment): ExperimentConfigSchema {
77
return {
@@ -40,29 +40,22 @@ export async function createArchive(experiment: Experiment) {
4040
type: "application/json",
4141
});
4242
await zipWriter.add("config.json", new BlobReader(configBlob));
43-
const output = outputForExperiment(experiment);
44-
if (!output) {
45-
return;
46-
}
4743

48-
if (output.reference) {
49-
const csvBlob = new Blob([outputToCsv(output.reference)], {
44+
if (experiment.reference.output) {
45+
const csvBlob = new Blob([outputToCsv(experiment.reference.output)], {
5046
type: "text/csv",
5147
});
5248
await zipWriter.add(`${experiment.name}.csv`, new BlobReader(csvBlob));
5349
}
5450

55-
let permIndex = 0;
56-
for (const perm of experiment.permutations) {
57-
const name = perm.name;
58-
const permutationOutput = output.permutations[permIndex];
59-
if (output && name) {
51+
for (const permutation of experiment.permutations) {
52+
const permutationOutput = permutation.output;
53+
if (permutationOutput) {
6054
const csvBlob = new Blob([outputToCsv(permutationOutput)], {
6155
type: "text/csv",
6256
});
63-
await zipWriter.add(`${name}.csv`, new BlobReader(csvBlob));
57+
await zipWriter.add(`${permutation.name}.csv`, new BlobReader(csvBlob));
6458
}
65-
permIndex++;
6659
}
6760
await zipWriter.close();
6861
return await zipFileWriter.getData();

apps/class-solid/src/lib/store.ts

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { runClass } from "./runner";
1313
export interface Permutation<C extends PartialConfig = PartialConfig> {
1414
name: string;
1515
config: C;
16+
output?: ClassOutput | undefined;
1617
// TODO Could use per run state to show progress of run of reference and each permutation
1718
// running: boolean;
1819
}
@@ -23,6 +24,7 @@ export interface Experiment {
2324
reference: {
2425
// TODO change reference.config to config, as there are no other keys in reference
2526
config: PartialConfig;
27+
output?: ClassOutput | undefined;
2628
};
2729
permutations: Permutation[];
2830
running: number | false;
@@ -31,34 +33,6 @@ export interface Experiment {
3133
export const [experiments, setExperiments] = createStore<Experiment[]>([]);
3234
export const [analyses, setAnalyses] = createStore<Analysis[]>([]);
3335

34-
interface ExperimentOutput {
35-
reference: ClassOutput;
36-
permutations: ClassOutput[];
37-
}
38-
39-
// Outputs must store outside store as they are too big to wrap in proxy
40-
export const outputs: ExperimentOutput[] = [];
41-
42-
export function outputForExperiment(
43-
index: number | Experiment,
44-
): ExperimentOutput | undefined {
45-
if (typeof index === "object") {
46-
const i = experiments.indexOf(index);
47-
return outputs[i];
48-
}
49-
return outputs[index];
50-
}
51-
52-
export function outputForPermutation(
53-
experiment: ExperimentOutput | undefined,
54-
permutationIndex: number,
55-
) {
56-
if (!experiment || experiment.permutations.length <= permutationIndex) {
57-
return { t: [], h: [], theta: [], dtheta: [] };
58-
}
59-
return experiment.permutations[permutationIndex];
60-
}
61-
6236
// biome-ignore lint/suspicious/noExplicitAny: recursion is hard to type
6337
function mergeConfigurations(reference: any, permutation: any) {
6438
const merged = { ...reference };
@@ -81,7 +55,7 @@ function mergeConfigurations(reference: any, permutation: any) {
8155
export async function runExperiment(id: number) {
8256
const exp = experiments[id];
8357

84-
setExperiments(id, "running", 0);
58+
setExperiments(id, "running", 0.0001);
8559

8660
// TODO make lazy, if config does not change do not rerun
8761
// or make more specific like runReference and runPermutation
@@ -90,18 +64,15 @@ export async function runExperiment(id: number) {
9064
const referenceConfig = unwrap(exp.reference.config);
9165
const newOutput = await runClass(referenceConfig);
9266

93-
outputs[id] = {
94-
reference: newOutput,
95-
permutations: [],
96-
};
67+
setExperiments(id, "reference", "output", newOutput);
9768

9869
// Run permutations
9970
let permCounter = 0;
10071
for (const proxiedPerm of exp.permutations) {
10172
const permConfig = unwrap(proxiedPerm.config);
10273
const combinedConfig = mergeConfigurations(referenceConfig, permConfig);
10374
const newOutput = await runClass(combinedConfig);
104-
outputs[id].permutations[permCounter] = newOutput;
75+
setExperiments(id, "permutations", permCounter, "output", newOutput);
10576
permCounter++;
10677
}
10778

@@ -172,7 +143,6 @@ export function duplicateExperiment(id: number) {
172143

173144
export function deleteExperiment(index: number) {
174145
setExperiments(experiments.filter((_, i) => i !== index));
175-
outputs.splice(index, 1);
176146
}
177147

178148
export async function modifyExperiment(
@@ -226,7 +196,6 @@ export async function deletePermutationFromExperiment(
226196
setExperiments(experimentIndex, "permutations", (perms) =>
227197
perms.filter((_, i) => i !== permutationIndex),
228198
);
229-
outputs[experimentIndex].permutations.splice(permutationIndex, 1);
230199
}
231200

232201
export function findPermutation(exp: Experiment, permutationName: string) {

0 commit comments

Comments
 (0)