@milabench/bujang 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +23 -5
- package/dist/constants.d.ts +6 -0
- package/dist/index.js +6231 -5068
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +113 -12
- package/dist/views/JobDataOverview.d.ts +4 -3
- package/dist/views/OverviewPanels.d.ts +37 -0
- package/dist/views/PipelineEditor.d.ts +5 -0
- package/dist/views/PipelinesView.d.ts +1 -1
- package/dist/views/ScheduleDialog.d.ts +14 -0
- package/dist/views/SweepDialog.d.ts +51 -0
- package/dist/views/dataCharts.d.ts +56 -0
- package/package.json +1 -1
- package/src/api.ts +52 -4
- package/src/constants.ts +3 -0
- package/src/types.ts +113 -13
- package/src/views/JanitorView.tsx +101 -32
- package/src/views/JobDataOverview.tsx +126 -213
- package/src/views/JobLogs.tsx +13 -6
- package/src/views/JobSubmit.tsx +377 -318
- package/src/views/JobsView.tsx +34 -21
- package/src/views/LogDisplay.tsx +2 -2
- package/src/views/OverviewPanels.tsx +341 -0
- package/src/views/PipelineEditor.tsx +3 -3
- package/src/views/PipelinesView.tsx +387 -164
- package/src/views/ScheduleDialog.tsx +98 -0
- package/src/views/SettingsView.tsx +131 -1
- package/src/views/SweepDialog.tsx +520 -0
- package/src/views/dataCharts.tsx +261 -0
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sweep: turn the job of the submit page into a pipeline, one step per combination of argument values.
|
|
3
|
+
*
|
|
4
|
+
* Saving writes three files, all named after the sweep: the script as a template (`<name>.sh`, in the
|
|
5
|
+
* cluster's folder), the Slurm settings of the form as a profile (`<cluster>/<name>`), and the pipeline
|
|
6
|
+
* (`<name>`): jobs that run that script with that profile, the swept values in their `env`. The
|
|
7
|
+
* arguments are in numbered steps (1 by default) that run in that order (step 0 PREPARE=1, then step 1
|
|
8
|
+
* sweeping LR and BATCH_SIZE), each step's jobs in parallel or in sequence. Each job can take another profile of
|
|
9
|
+
* the cluster (the pipeline, on the left of the form). "Save & run" also starts it and opens the run.
|
|
10
|
+
*/
|
|
11
|
+
import React, { useMemo, useState } from 'react';
|
|
12
|
+
import { Box, Button, Dialog, HStack, Input, NativeSelect, Text, VStack } from '@chakra-ui/react';
|
|
13
|
+
import { useQuery } from '@tanstack/react-query';
|
|
14
|
+
import { useNavigate } from 'react-router-dom';
|
|
15
|
+
import { getSlurmProfiles, runPipelineTemplate, savePipelineToFile, saveSlurmProfile, saveSlurmTemplate } from '../api';
|
|
16
|
+
import { useBujangPaths } from '../context';
|
|
17
|
+
import { toaster } from '../toast';
|
|
18
|
+
import type { PipelineJob, PipelineNode, PipelineTemplatePayload, SlurmProfile } from '../types';
|
|
19
|
+
import { TYPE_COLOR, profileKey, profileLabel } from './PipelineEditor';
|
|
20
|
+
|
|
21
|
+
export type SweepMode = 'grid' | 'zip';
|
|
22
|
+
|
|
23
|
+
/** "0.1, 0.01 ,0.001" -> ["0.1", "0.01", "0.001"] */
|
|
24
|
+
export function parseValues(text: string): string[] {
|
|
25
|
+
return text.split(',').map(v => v.trim()).filter(v => v !== '');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The env of every job. grid: every combination; zip: the i-th value of each argument together (an
|
|
30
|
+
* argument with one value goes with all of them). The arguments with one value are in every env too.
|
|
31
|
+
*/
|
|
32
|
+
export function sweepEnvs(values: Record<string, string[]>, mode: SweepMode): Record<string, string>[] | string {
|
|
33
|
+
const names = Object.keys(values).filter(n => values[n].length > 0);
|
|
34
|
+
if (mode === 'zip') {
|
|
35
|
+
const lengths = new Set(names.map(n => values[n].length).filter(l => l > 1));
|
|
36
|
+
if (lengths.size > 1) return `zip needs the same number of values for every swept argument (${[...lengths].join(', ')})`;
|
|
37
|
+
const count = lengths.size ? [...lengths][0] : 1;
|
|
38
|
+
return Array.from({ length: count }, (_, i) =>
|
|
39
|
+
Object.fromEntries(names.map(n => [n, values[n].length > 1 ? values[n][i] : values[n][0]])));
|
|
40
|
+
}
|
|
41
|
+
let envs: Record<string, string>[] = [{}];
|
|
42
|
+
for (const n of names) envs = envs.flatMap(env => values[n].map(v => ({ ...env, [n]: v })));
|
|
43
|
+
return envs;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** What tells a job of the sweep apart: its profile is kept under it when the values change */
|
|
47
|
+
const envKey = (env: Record<string, string>) => JSON.stringify(Object.entries(env).sort());
|
|
48
|
+
|
|
49
|
+
type GroupType = 'parallel' | 'sequential';
|
|
50
|
+
|
|
51
|
+
/** A step of the sweep: the jobs of its arguments, run side by side or one after the other */
|
|
52
|
+
export interface SweepStep {
|
|
53
|
+
/** its number: the steps run in the order of their numbers */
|
|
54
|
+
step: number;
|
|
55
|
+
/** the arguments put in this step */
|
|
56
|
+
own: string[];
|
|
57
|
+
/** the arguments with several values in this step: they name its jobs */
|
|
58
|
+
swept: string[];
|
|
59
|
+
envs: Record<string, string>[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The steps of a sweep, in the order of their numbers. An argument in step k (`stepOf`, 1 when unset)
|
|
64
|
+
* takes its values in step k and its value of `elsewhere` in the other steps. Each step makes its jobs
|
|
65
|
+
* as `sweepEnvs` does.
|
|
66
|
+
*/
|
|
67
|
+
const DEFAULT_STEP = 1;
|
|
68
|
+
|
|
69
|
+
export function sweepSteps(
|
|
70
|
+
values: Record<string, string[]>, stepOf: Record<string, number>, elsewhere: Record<string, string>, mode: SweepMode,
|
|
71
|
+
): SweepStep[] | string {
|
|
72
|
+
const names = Object.keys(values);
|
|
73
|
+
const of = (n: string) => stepOf[n] ?? DEFAULT_STEP;
|
|
74
|
+
const used = [...new Set(names.map(of))].sort((a, b) => a - b);
|
|
75
|
+
const steps: SweepStep[] = [];
|
|
76
|
+
for (const step of used.length ? used : [DEFAULT_STEP]) {
|
|
77
|
+
const own = names.filter(n => of(n) === step);
|
|
78
|
+
const these = Object.fromEntries(names.map(n => [n,
|
|
79
|
+
of(n) === step ? values[n] : parseValues(elsewhere[n] ?? '').slice(0, 1)]));
|
|
80
|
+
const envs = sweepEnvs(these, mode);
|
|
81
|
+
if (typeof envs === 'string') return used.length > 1 ? `step ${steps.length + 1}: ${envs}` : envs;
|
|
82
|
+
steps.push({ step, own, swept: names.filter(n => these[n].length > 1), envs });
|
|
83
|
+
}
|
|
84
|
+
return steps;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
const TYPE_LABEL: Record<GroupType | 'job', string> = { job: 'Job', parallel: 'Parallel', sequential: 'Sequential' };
|
|
89
|
+
const INDENT = 12;
|
|
90
|
+
const TAG = { w: '96px', h: '22px', fontSize: '11px', fontWeight: 'semibold' } as const;
|
|
91
|
+
|
|
92
|
+
/** The type of a row of the pipeline, as the pipeline editor shows it; a step can change it */
|
|
93
|
+
const TypeTag: React.FC<{ type: GroupType | 'job'; onChange?: (type: GroupType) => void }> = ({ type, onChange }) =>
|
|
94
|
+
onChange && type !== 'job' ? (
|
|
95
|
+
<NativeSelect.Root size="xs" w={TAG.w} flexShrink={0}>
|
|
96
|
+
<NativeSelect.Field
|
|
97
|
+
value={type}
|
|
98
|
+
onChange={(e) => onChange(e.target.value as GroupType)}
|
|
99
|
+
borderColor={TYPE_COLOR[type]}
|
|
100
|
+
fontWeight={TAG.fontWeight}
|
|
101
|
+
fontSize={TAG.fontSize}
|
|
102
|
+
h={TAG.h}
|
|
103
|
+
ps={1.5}
|
|
104
|
+
pe={5}
|
|
105
|
+
aria-label="Step type"
|
|
106
|
+
>
|
|
107
|
+
<option value="parallel">{TYPE_LABEL.parallel}</option>
|
|
108
|
+
<option value="sequential">{TYPE_LABEL.sequential}</option>
|
|
109
|
+
</NativeSelect.Field>
|
|
110
|
+
<NativeSelect.Indicator boxSize="3" />
|
|
111
|
+
</NativeSelect.Root>
|
|
112
|
+
) : (
|
|
113
|
+
<Box
|
|
114
|
+
w={TAG.w}
|
|
115
|
+
flexShrink={0}
|
|
116
|
+
border="1px solid"
|
|
117
|
+
borderColor={TYPE_COLOR[type]}
|
|
118
|
+
borderRadius="sm"
|
|
119
|
+
px={1.5}
|
|
120
|
+
h={TAG.h}
|
|
121
|
+
lineHeight="20px"
|
|
122
|
+
fontSize={TAG.fontSize}
|
|
123
|
+
fontWeight={TAG.fontWeight}
|
|
124
|
+
color="var(--color-text)"
|
|
125
|
+
>
|
|
126
|
+
{TYPE_LABEL[type]}
|
|
127
|
+
</Box>
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
/** A row of the pipeline tree: its marker ("1." in a sequential group, a dot in a parallel one), type, name, and what goes on the right */
|
|
131
|
+
const TreeRow: React.FC<{
|
|
132
|
+
depth: number;
|
|
133
|
+
marker?: string;
|
|
134
|
+
type: GroupType | 'job';
|
|
135
|
+
onType?: (type: GroupType) => void;
|
|
136
|
+
name: string;
|
|
137
|
+
title?: string;
|
|
138
|
+
children?: React.ReactNode;
|
|
139
|
+
}> = ({ depth, marker, type, onType, name, title, children }) => (
|
|
140
|
+
<HStack gap={2} h="30px" pl={`${depth * INDENT + 2}px`} pr={2} role="treeitem">
|
|
141
|
+
<Text w="16px" flexShrink={0} whiteSpace="nowrap" textAlign="right" fontSize="xs" fontFamily="mono" color="var(--color-text-muted)">
|
|
142
|
+
{marker}
|
|
143
|
+
</Text>
|
|
144
|
+
<TypeTag type={type} onChange={onType} />
|
|
145
|
+
<Text flex={1} minW={0} truncate fontSize="sm" color="var(--color-text)" title={title ?? name}>{name}</Text>
|
|
146
|
+
{children}
|
|
147
|
+
</HStack>
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* The resources of sbatch arguments, to compare a form with a profile: `--key value` as `--key=value`, in
|
|
152
|
+
* any order, without the job name and the dependency (not resources)
|
|
153
|
+
*/
|
|
154
|
+
const resourcesOf = (sbatchArgs: string[]): string =>
|
|
155
|
+
sbatchArgs
|
|
156
|
+
.map(a => a.trim())
|
|
157
|
+
.map(a => (a.startsWith('--') && /\s/.test(a) ? a.replace(/\s+/, '=') : a.replace(/\s+/, ' ')))
|
|
158
|
+
.filter(a => a && !a.startsWith('--job-name') && !a.startsWith('--dependency'))
|
|
159
|
+
.sort()
|
|
160
|
+
.join('\n');
|
|
161
|
+
|
|
162
|
+
const NAME_RE = /^[A-Za-z0-9_.-]+$/;
|
|
163
|
+
const MANY_JOBS = 100;
|
|
164
|
+
|
|
165
|
+
interface SweepDialogProps {
|
|
166
|
+
isOpen: boolean;
|
|
167
|
+
onClose: () => void;
|
|
168
|
+
cluster: string;
|
|
169
|
+
/** what the submit page would submit, read when the sweep is saved */
|
|
170
|
+
getScript: () => string;
|
|
171
|
+
getSbatchArgs: () => string[];
|
|
172
|
+
/** the profile picked on the submit page, if any: the jobs use it when the form still has its settings */
|
|
173
|
+
profile?: SlurmProfile;
|
|
174
|
+
/** the arguments as the form shows them now (name -> value) */
|
|
175
|
+
args: Record<string, string>;
|
|
176
|
+
/** default name: the template or job name */
|
|
177
|
+
baseName: string;
|
|
178
|
+
/** files attached on the submit page: a pipeline does not carry them */
|
|
179
|
+
attachmentCount: number;
|
|
180
|
+
/** runs `go` once the cluster has an ssh connection (the login dialog of the submit page, MFA) */
|
|
181
|
+
ensureConnected: (cluster: string, go: () => void) => Promise<void>;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** the message of an Error or of an ApiError ({message, status}, what the api helpers throw) */
|
|
185
|
+
const messageOf = (error: unknown): string =>
|
|
186
|
+
(error as { message?: string } | null)?.message || String(error);
|
|
187
|
+
|
|
188
|
+
const SweepDialog: React.FC<SweepDialogProps> = ({
|
|
189
|
+
isOpen, onClose, cluster, getScript, getSbatchArgs, profile, args, baseName, attachmentCount, ensureConnected,
|
|
190
|
+
}) => {
|
|
191
|
+
const navigate = useNavigate();
|
|
192
|
+
const paths = useBujangPaths();
|
|
193
|
+
const [name, setName] = useState(`${baseName.replace(/\.sh$/, '') || 'job'}_sweep`);
|
|
194
|
+
const [mode, setMode] = useState<SweepMode>('grid');
|
|
195
|
+
// what the user typed per argument, the current value by default
|
|
196
|
+
const [texts, setTexts] = useState<Record<string, string>>(() => ({ ...args }));
|
|
197
|
+
// the step of each argument (1 by default) and its value in the other steps (the form's by default)
|
|
198
|
+
const [stepOf, setStepOf] = useState<Record<string, number>>({});
|
|
199
|
+
// what the step fields show (an empty one while typing keeps the step it had)
|
|
200
|
+
const [stepTexts, setStepTexts] = useState<Record<string, string>>({});
|
|
201
|
+
const [elsewhere, setElsewhere] = useState<Record<string, string>>(() => ({ ...args }));
|
|
202
|
+
// parallel or sequential, per step, and of the group of the steps (guessed when unset)
|
|
203
|
+
const [types, setTypes] = useState<Record<number, GroupType>>({});
|
|
204
|
+
const [rootType, setRootType] = useState<GroupType | null>(null);
|
|
205
|
+
// the profile of a job ("<step>:<envKey>" -> profile key), the Slurm settings of the form when unset
|
|
206
|
+
const [chosen, setChosen] = useState<Record<string, string>>({});
|
|
207
|
+
const { data: allProfiles = [] } = useQuery({
|
|
208
|
+
queryKey: ['slurm-profiles'],
|
|
209
|
+
queryFn: getSlurmProfiles,
|
|
210
|
+
refetchOnWindowFocus: false,
|
|
211
|
+
staleTime: 300000,
|
|
212
|
+
});
|
|
213
|
+
const [busy, setBusy] = useState(false);
|
|
214
|
+
|
|
215
|
+
const values = useMemo(
|
|
216
|
+
() => Object.fromEntries(Object.keys(args).map(n => [n, parseValues(texts[n] ?? args[n] ?? '')])),
|
|
217
|
+
[args, texts],
|
|
218
|
+
);
|
|
219
|
+
const computed = useMemo(() => sweepSteps(values, stepOf, elsewhere, mode), [values, stepOf, elsewhere, mode]);
|
|
220
|
+
const steps = typeof computed === 'string' ? [] : computed;
|
|
221
|
+
const total = steps.reduce((n, s) => n + s.envs.length, 0);
|
|
222
|
+
const issue =
|
|
223
|
+
typeof computed === 'string' ? computed
|
|
224
|
+
: !NAME_RE.test(name) ? 'the name may only have letters, digits, _ . -'
|
|
225
|
+
: Object.keys(args).some(n => values[n].length === 0) ? 'every argument needs a value'
|
|
226
|
+
: total < 2 ? 'give an argument several values (comma separated), or put arguments in other steps'
|
|
227
|
+
: null;
|
|
228
|
+
|
|
229
|
+
const script = `${name}.sh`;
|
|
230
|
+
// the Slurm settings of the form: the profile picked on the submit page while they are its own,
|
|
231
|
+
// else "custom", saved as the profile <cluster>/<name>
|
|
232
|
+
const formArgs = useMemo(getSbatchArgs, [getSbatchArgs]);
|
|
233
|
+
const sameAsProfile = !!profile && resourcesOf(formArgs) === resourcesOf(profile.sbatch_args);
|
|
234
|
+
const customProfile = `${cluster}/${name}`;
|
|
235
|
+
const formProfile = sameAsProfile ? profileKey(profile) : customProfile;
|
|
236
|
+
// the other slurm profiles of the cluster: the steps of a pipeline run where their profile says
|
|
237
|
+
const profiles = allProfiles.filter((p: SlurmProfile) =>
|
|
238
|
+
(p.cluster || 'mila') === cluster && p.executor !== 'ssh' && profileKey(p) !== formProfile);
|
|
239
|
+
const jobKey = (s: SweepStep, env: Record<string, string>) => `${s.step}:${envKey(env)}`;
|
|
240
|
+
const profileOf = (s: SweepStep, env: Record<string, string>) => chosen[jobKey(s, env)] || formProfile;
|
|
241
|
+
const allJobs = steps.flatMap(s => s.envs.map(env => ({ s, env })));
|
|
242
|
+
const setAll = (profile: string) => setChosen(Object.fromEntries(allJobs.map(({ s, env }) => [jobKey(s, env), profile])));
|
|
243
|
+
const shared = allJobs.length > 0 && allJobs.every(({ s, env }) => profileOf(s, env) === profileOf(allJobs[0].s, allJobs[0].env))
|
|
244
|
+
? profileOf(allJobs[0].s, allJobs[0].env) : '';
|
|
245
|
+
const typeOf = (s: SweepStep): GroupType => types[s.step] ?? 'parallel';
|
|
246
|
+
// the steps one after the other, unless the user says otherwise
|
|
247
|
+
const mainType: GroupType = rootType ?? 'sequential';
|
|
248
|
+
|
|
249
|
+
/** what names a job: its swept values, else the arguments of its step, else the script */
|
|
250
|
+
const jobName = (s: SweepStep, env: Record<string, string>) =>
|
|
251
|
+
s.swept.length ? s.swept.map(n => env[n]).join(' · ')
|
|
252
|
+
: s.own.length ? s.own.map(n => `${n}=${env[n]}`).join(' ')
|
|
253
|
+
: name;
|
|
254
|
+
const stepName = (s: SweepStep) =>
|
|
255
|
+
(steps.length === 1 ? 'sweep' : (s.swept.length ? s.swept : s.own).join('_') || `step${s.step}`).replace(/[^A-Za-z0-9._-]/g, '_');
|
|
256
|
+
const labelOf = (s: SweepStep) => {
|
|
257
|
+
const named = s.swept.length ? s.swept : s.own;
|
|
258
|
+
return named.length ? `${name} ${named.map(n => `${n}={${n}}`).join(' ')}` : name;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const definition = (): PipelineNode => {
|
|
262
|
+
const nodes = steps.map((s): PipelineNode => {
|
|
263
|
+
const jobs = s.envs.map((env): PipelineJob => ({ type: 'job', script, profile: profileOf(s, env), env }));
|
|
264
|
+
if (jobs.length === 1) return { ...jobs[0], label: labelOf(s) };
|
|
265
|
+
return { type: typeOf(s), name: stepName(s), label: labelOf(s), jobs };
|
|
266
|
+
});
|
|
267
|
+
return nodes.length === 1 ? nodes[0] : { type: mainType, name: 'main', jobs: nodes };
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const describe = () => steps.map((s, i) => {
|
|
271
|
+
const what = s.swept.length ? `${mode === 'grid' ? 'every combination' : 'values paired'} of ${s.swept.join(', ')}` : s.own.map(n => `${n}=${values[n][0]}`).join(', ');
|
|
272
|
+
return `${steps.length > 1 ? `step ${i + 1}: ` : ''}${what}${s.envs.length > 1 ? ` (${typeOf(s)})` : ''}`;
|
|
273
|
+
}).join(mainType === 'sequential' ? ', then ' : '; side by side: ');
|
|
274
|
+
|
|
275
|
+
const save = async (run: boolean) => {
|
|
276
|
+
if (issue) return;
|
|
277
|
+
setBusy(true);
|
|
278
|
+
try {
|
|
279
|
+
const saved = await saveSlurmTemplate({ name: `${cluster}/${script}`, content: getScript() });
|
|
280
|
+
if (!saved.success) throw new Error(`saving the script: ${saved.error || 'failed'}`);
|
|
281
|
+
// the Slurm settings of the form, when a job runs with them
|
|
282
|
+
if (!sameAsProfile && allJobs.some(({ s, env }) => profileOf(s, env) === customProfile)) {
|
|
283
|
+
const result = await saveSlurmProfile({ name, cluster, sbatch_args: formArgs });
|
|
284
|
+
if (!result.success) throw new Error(`saving the profile: ${result.error || 'failed'}`);
|
|
285
|
+
}
|
|
286
|
+
const pipeline: PipelineTemplatePayload = {
|
|
287
|
+
name,
|
|
288
|
+
type: 'pipeline',
|
|
289
|
+
description: `Sweep of ${baseName || script} (${describe()}), made from the submit page.`,
|
|
290
|
+
definition: definition(),
|
|
291
|
+
job_id: null,
|
|
292
|
+
};
|
|
293
|
+
const written = await savePipelineToFile(pipeline);
|
|
294
|
+
if (written.error) throw new Error(`saving the pipeline: ${written.error}`);
|
|
295
|
+
if (!run) {
|
|
296
|
+
toaster.create({ title: 'Sweep saved', description: `Pipeline ${name}, ${total} jobs`, type: 'success', duration: 5000 });
|
|
297
|
+
onClose();
|
|
298
|
+
navigate(paths.pipelineDetails(name));
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
await ensureConnected(cluster, () => {
|
|
302
|
+
runPipelineTemplate(name)
|
|
303
|
+
.then((started) => { onClose(); navigate(paths.pipelineDetails(name, started.run_id)); })
|
|
304
|
+
.catch((error) => toaster.create({ title: 'Sweep saved, not started', description: messageOf(error), type: 'error', duration: 8000 }));
|
|
305
|
+
});
|
|
306
|
+
} catch (error) {
|
|
307
|
+
toaster.create({ title: 'Sweep not saved', description: messageOf(error), type: 'error', duration: 8000 });
|
|
308
|
+
} finally {
|
|
309
|
+
setBusy(false);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const profileSelect = (value: string, onChange: (profile: string) => void, label: string, mixed = false) => (
|
|
314
|
+
<NativeSelect.Root size="xs" w="190px" flexShrink={0} title={label}>
|
|
315
|
+
<NativeSelect.Field value={value} onChange={(e) => onChange(e.target.value)} aria-label={label}>
|
|
316
|
+
{mixed && !value && <option value="">mixed</option>}
|
|
317
|
+
<option value={formProfile}>{sameAsProfile ? profileLabel(profile) : 'custom'}</option>
|
|
318
|
+
{profiles.map(p => <option key={profileKey(p)} value={profileKey(p)}>{profileLabel(p)}</option>)}
|
|
319
|
+
</NativeSelect.Field>
|
|
320
|
+
<NativeSelect.Indicator boxSize="3" />
|
|
321
|
+
</NativeSelect.Root>
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
const jobRows = (s: SweepStep, depth: number, sequential: boolean) => (
|
|
325
|
+
<>
|
|
326
|
+
{s.envs.slice(0, MANY_JOBS).map((env, j) => (
|
|
327
|
+
<TreeRow
|
|
328
|
+
key={jobKey(s, env)}
|
|
329
|
+
depth={depth}
|
|
330
|
+
marker={sequential ? `${j + 1}.` : '•'}
|
|
331
|
+
type="job"
|
|
332
|
+
name={jobName(s, env)}
|
|
333
|
+
title={Object.entries(env).map(([k, v]) => `${k}=${v}`).join(' ')}
|
|
334
|
+
>
|
|
335
|
+
{profileSelect(profileOf(s, env), (p) => setChosen({ ...chosen, [jobKey(s, env)]: p }), 'Resources')}
|
|
336
|
+
</TreeRow>
|
|
337
|
+
))}
|
|
338
|
+
{s.envs.length > MANY_JOBS && (
|
|
339
|
+
<Text pl={`${depth * INDENT + 30}px`} fontSize="xs" color="var(--color-text-muted)">... {s.envs.length - MANY_JOBS} more</Text>
|
|
340
|
+
)}
|
|
341
|
+
</>
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
/** a step: its group (or its one job) at `depth` */
|
|
345
|
+
const stepRows = (s: SweepStep, depth: number, marker?: string, right?: React.ReactNode) => {
|
|
346
|
+
if (s.envs.length === 1) {
|
|
347
|
+
const env = s.envs[0];
|
|
348
|
+
return (
|
|
349
|
+
<TreeRow key={s.step} depth={depth} marker={marker} type="job" name={jobName(s, env)}
|
|
350
|
+
title={Object.entries(env).map(([k, v]) => `${k}=${v}`).join(' ')}>
|
|
351
|
+
{profileSelect(profileOf(s, env), (p) => setChosen({ ...chosen, [jobKey(s, env)]: p }), 'Resources')}
|
|
352
|
+
</TreeRow>
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
return (
|
|
356
|
+
<React.Fragment key={s.step}>
|
|
357
|
+
<TreeRow depth={depth} marker={marker} type={typeOf(s)} onType={(t) => setTypes({ ...types, [s.step]: t })} name={stepName(s)}
|
|
358
|
+
title={`step ${s.step}`}>
|
|
359
|
+
{right}
|
|
360
|
+
</TreeRow>
|
|
361
|
+
{jobRows(s, depth + 1, typeOf(s) === 'sequential')}
|
|
362
|
+
</React.Fragment>
|
|
363
|
+
);
|
|
364
|
+
};
|
|
365
|
+
const allSelect = allJobs.length > 1 ? profileSelect(shared, setAll, 'Resources of every job', true) : undefined;
|
|
366
|
+
|
|
367
|
+
const setStep = (n: string, text: string) => {
|
|
368
|
+
setStepTexts({ ...stepTexts, [n]: text });
|
|
369
|
+
if (/^\d+$/.test(text.trim())) setStepOf({ ...stepOf, [n]: Number(text) });
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
return (
|
|
373
|
+
<Dialog.Root open={isOpen} onOpenChange={(details) => { if (!details.open) onClose(); }} size="cover">
|
|
374
|
+
<Dialog.Backdrop />
|
|
375
|
+
<Dialog.Positioner>
|
|
376
|
+
<Dialog.Content maxW="1200px" h="min(760px, 90vh)" display="flex" flexDirection="column">
|
|
377
|
+
<Dialog.Header py={3} px={4} borderBottom="1px solid" borderColor="var(--color-border)">
|
|
378
|
+
<Dialog.Title fontSize="md" color="var(--color-text)">Sweep: a pipeline from this job</Dialog.Title>
|
|
379
|
+
</Dialog.Header>
|
|
380
|
+
<Dialog.Body p={0} flex={1} minH={0} display="flex">
|
|
381
|
+
<Box w="480px" flexShrink={0} borderRight="1px solid" borderColor="var(--color-border)" overflowY="auto" py={1} role="tree">
|
|
382
|
+
{steps.length > 1 ? (
|
|
383
|
+
<>
|
|
384
|
+
<TreeRow
|
|
385
|
+
depth={0}
|
|
386
|
+
type={mainType}
|
|
387
|
+
onType={setRootType}
|
|
388
|
+
name="main"
|
|
389
|
+
title={mainType === 'sequential' ? 'the steps run one after the other' : 'the steps run side by side'}
|
|
390
|
+
>
|
|
391
|
+
{allSelect}
|
|
392
|
+
</TreeRow>
|
|
393
|
+
{steps.map((s, i) => stepRows(s, 1, mainType === 'sequential' ? `${i + 1}.` : '•'))}
|
|
394
|
+
</>
|
|
395
|
+
) : steps.length === 1 ? (
|
|
396
|
+
stepRows(steps[0], 0, undefined, allSelect)
|
|
397
|
+
) : (
|
|
398
|
+
<Text pl="30px" py={1} fontSize="xs" color="var(--color-text-muted)">no job yet</Text>
|
|
399
|
+
)}
|
|
400
|
+
</Box>
|
|
401
|
+
<VStack flex={1} minW={0} p={4} overflowY="auto" align="stretch" gap={4}>
|
|
402
|
+
<HStack gap={3}>
|
|
403
|
+
<Text minW="90px" fontSize="sm" color="var(--color-text)">Name</Text>
|
|
404
|
+
<Input size="sm" value={name} onChange={(e) => setName(e.target.value)} />
|
|
405
|
+
</HStack>
|
|
406
|
+
<HStack gap={3}>
|
|
407
|
+
<Text minW="90px" fontSize="sm" color="var(--color-text)">Values</Text>
|
|
408
|
+
<NativeSelect.Root size="sm">
|
|
409
|
+
<NativeSelect.Field value={mode} onChange={(e) => setMode(e.target.value as SweepMode)}>
|
|
410
|
+
<option value="grid">Grid: every combination</option>
|
|
411
|
+
<option value="zip">Zip: the i-th values together</option>
|
|
412
|
+
</NativeSelect.Field>
|
|
413
|
+
<NativeSelect.Indicator />
|
|
414
|
+
</NativeSelect.Root>
|
|
415
|
+
</HStack>
|
|
416
|
+
|
|
417
|
+
<VStack align="stretch" gap={2}>
|
|
418
|
+
<Text fontSize="sm" fontWeight="semibold" color="var(--color-text)">Arguments</Text>
|
|
419
|
+
<Text fontSize="xs" color="var(--color-text-muted)">
|
|
420
|
+
Comma separated values: an argument with several values is swept, the others keep one value.
|
|
421
|
+
The steps run in the order of their numbers: give PREPARE the step 0 to run it before the
|
|
422
|
+
others (step 1). An argument takes its values in its own step and its value under "other
|
|
423
|
+
steps" in the rest. Change how the steps and their jobs run on the left.
|
|
424
|
+
</Text>
|
|
425
|
+
{Object.keys(args).length === 0 && (
|
|
426
|
+
<Text fontSize="sm" fontStyle="italic" color="var(--color-text-muted)">
|
|
427
|
+
The script has no arguments (<code>export NAME=value</code> lines of its <code># ---- Arguments</code> section).
|
|
428
|
+
</Text>
|
|
429
|
+
)}
|
|
430
|
+
{Object.keys(args).length > 0 && (
|
|
431
|
+
<HStack gap={2} fontSize="xs" color="var(--color-text-muted)">
|
|
432
|
+
<Text w="56px" flexShrink={0}>Step</Text>
|
|
433
|
+
<Text minW="150px">Argument</Text>
|
|
434
|
+
<Text flex={1}>Values</Text>
|
|
435
|
+
<Text w="110px" flexShrink={0} visibility={steps.length > 1 ? 'visible' : 'hidden'}>Other steps</Text>
|
|
436
|
+
</HStack>
|
|
437
|
+
)}
|
|
438
|
+
{Object.keys(args).map(n => (
|
|
439
|
+
<HStack key={n} gap={2}>
|
|
440
|
+
<Input
|
|
441
|
+
size="sm"
|
|
442
|
+
w="56px"
|
|
443
|
+
flexShrink={0}
|
|
444
|
+
type="number"
|
|
445
|
+
min={0}
|
|
446
|
+
step={1}
|
|
447
|
+
textAlign="center"
|
|
448
|
+
value={stepTexts[n] ?? String(stepOf[n] ?? DEFAULT_STEP)}
|
|
449
|
+
onChange={(e) => setStep(n, e.target.value)}
|
|
450
|
+
onBlur={() => setStepTexts({ ...stepTexts, [n]: String(stepOf[n] ?? DEFAULT_STEP) })}
|
|
451
|
+
aria-label={`Step of ${n}`}
|
|
452
|
+
/>
|
|
453
|
+
<Text minW="150px" fontSize="sm" fontWeight="medium" color="var(--color-text)" truncate title={n}>{n}</Text>
|
|
454
|
+
<Input size="sm" flex={1} minW="80px" value={texts[n] ?? ''} onChange={(e) => setTexts({ ...texts, [n]: e.target.value })} />
|
|
455
|
+
<Text minW="56px" fontSize="xs" color="var(--color-text-muted)" textAlign="right">
|
|
456
|
+
{values[n].length > 1 ? `${values[n].length} values` : ''}
|
|
457
|
+
</Text>
|
|
458
|
+
<Input
|
|
459
|
+
size="sm"
|
|
460
|
+
w="110px"
|
|
461
|
+
flexShrink={0}
|
|
462
|
+
placeholder="other steps"
|
|
463
|
+
title="Its value in the other steps"
|
|
464
|
+
visibility={steps.length > 1 ? 'visible' : 'hidden'}
|
|
465
|
+
value={elsewhere[n] ?? ''}
|
|
466
|
+
onChange={(e) => setElsewhere({ ...elsewhere, [n]: e.target.value })}
|
|
467
|
+
/>
|
|
468
|
+
</HStack>
|
|
469
|
+
))}
|
|
470
|
+
</VStack>
|
|
471
|
+
|
|
472
|
+
<Box borderTop="1px solid" borderColor="var(--color-border)" pt={3}>
|
|
473
|
+
<Text fontSize="sm" color="var(--color-text)">
|
|
474
|
+
{total} job{total === 1 ? '' : 's'}
|
|
475
|
+
{steps.length > 1 ? ` in ${steps.length} steps, ${mainType === 'sequential' ? 'one after the other' : 'side by side'}` : steps[0] && steps[0].envs.length > 1 ? ` in ${typeOf(steps[0])}` : ''}
|
|
476
|
+
{total > MANY_JOBS && <Text as="span" color="orange.500"> (that is a lot)</Text>}
|
|
477
|
+
</Text>
|
|
478
|
+
<Text fontSize="xs" color="var(--color-text-muted)" mt={2}>
|
|
479
|
+
{sameAsProfile ? (
|
|
480
|
+
<>Saves the script as <code>{name}.sh</code> and the pipeline <code>{name}</code> (both replaced if they exist).</>
|
|
481
|
+
) : (
|
|
482
|
+
<>
|
|
483
|
+
Saves the script as <code>{name}.sh</code>, the Slurm settings of the form ("custom") as the profile{' '}
|
|
484
|
+
<code>{customProfile}</code> (when a job uses them) and the pipeline <code>{name}</code> (all three replaced if they exist).
|
|
485
|
+
</>
|
|
486
|
+
)}
|
|
487
|
+
</Text>
|
|
488
|
+
{attachmentCount > 0 && (
|
|
489
|
+
<Text fontSize="xs" color="orange.500" mt={1}>
|
|
490
|
+
The {attachmentCount} attached file{attachmentCount === 1 ? '' : 's'} are not sent: a pipeline step has no attachments.
|
|
491
|
+
</Text>
|
|
492
|
+
)}
|
|
493
|
+
</Box>
|
|
494
|
+
</VStack>
|
|
495
|
+
</Dialog.Body>
|
|
496
|
+
<Dialog.Footer py={3} px={4} borderTop="1px solid" borderColor="var(--color-border)">
|
|
497
|
+
{issue && <Text fontSize="sm" color="var(--color-text-muted)" mr="auto">{issue}</Text>}
|
|
498
|
+
<Button variant="ghost" size="sm" onClick={onClose} color="var(--color-text)">Cancel</Button>
|
|
499
|
+
<Button variant="outline" size="sm" onClick={() => save(false)} disabled={!!issue} loading={busy}>
|
|
500
|
+
Save pipeline
|
|
501
|
+
</Button>
|
|
502
|
+
<Button
|
|
503
|
+
size="sm"
|
|
504
|
+
onClick={() => save(true)}
|
|
505
|
+
disabled={!!issue}
|
|
506
|
+
loading={busy}
|
|
507
|
+
bg="var(--color-primary)"
|
|
508
|
+
color="var(--color-primary-text)"
|
|
509
|
+
_hover={{ bg: 'var(--color-primary-hover)' }}
|
|
510
|
+
>
|
|
511
|
+
Save & run
|
|
512
|
+
</Button>
|
|
513
|
+
</Dialog.Footer>
|
|
514
|
+
</Dialog.Content>
|
|
515
|
+
</Dialog.Positioner>
|
|
516
|
+
</Dialog.Root>
|
|
517
|
+
);
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
export default SweepDialog;
|