@milabench/bujang 0.1.16 → 0.1.17

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/types.d.ts CHANGED
@@ -886,7 +886,11 @@ export interface StatsMetric {
886
886
  event: string;
887
887
  field: string;
888
888
  title?: string;
889
+ /** comma separated fields: a row per value of them */
890
+ by?: string;
889
891
  }
892
+ /** A statistic of a stats block; busy: the total over the time from the first `start` to the last `end` */
893
+ export type StatName = 'total' | 'busy' | 'count' | 'mean' | 'std' | 'min' | 'median' | 'p95' | 'p99' | 'max';
890
894
  /** A block of the Overview tab: the log view, the media of the artifact folders, or a chart (Vega-Lite) of one or several events */
891
895
  export type OverviewBlock = {
892
896
  kind: 'artifacts';
@@ -899,6 +903,7 @@ export type OverviewBlock = {
899
903
  kind: 'stats';
900
904
  title?: string;
901
905
  metrics?: StatsMetric[];
906
+ show?: StatName[];
902
907
  } | {
903
908
  kind: 'logs';
904
909
  title?: string;
@@ -924,11 +929,14 @@ export type OverviewBlock = {
924
929
  log_y?: boolean;
925
930
  zero?: boolean;
926
931
  };
927
- /** A panel of the Overview tab: a block, or columns of blocks side by side */
928
- export type OverviewPanel = OverviewBlock | {
932
+ /** Blocks side by side, of the same width or of relative widths */
933
+ export interface ColumnsPanel {
929
934
  kind: 'columns';
930
935
  columns: OverviewBlock[][];
931
- };
936
+ widths?: number[];
937
+ }
938
+ /** A panel of the Overview tab: a block, or columns of blocks side by side */
939
+ export type OverviewPanel = OverviewBlock | ColumnsPanel;
932
940
  export interface OverviewLayout {
933
941
  panels: OverviewPanel[];
934
942
  }
@@ -55,7 +55,9 @@ export declare const LayoutBar: React.FC<{
55
55
  /** The panels of a layout */
56
56
  export declare const LayoutPanels: React.FC<{
57
57
  jrJobId: string;
58
+ /** those of the picked rank with `oneRank` */
58
59
  files: JobData['files'];
60
+ oneRank: boolean;
59
61
  layout: OverviewLayout;
60
62
  /** the charts of the built-in layout */
61
63
  available: OverviewBlock[];
@@ -46,6 +46,8 @@ export declare const VegaChart: React.FC<{
46
46
  export declare const panelEvents: (event?: string) => string[];
47
47
  /** The files that have rows of `event` (comma separated events) */
48
48
  export declare const filesWithEvent: (files: JobData["files"], event: string) => JobData["files"];
49
+ /** The rank of each file (null: of none). In a job whose files have a `rank`, the others are told by their name, <name>.<rank>.jsonl */
50
+ export declare const fileRanks: (files: JobData["files"]) => Map<string, number | null>;
49
51
  /** The fields of `event` (comma separated events) in `files`, merged (counts added, ranges widened, values joined) */
50
52
  export declare const mergeFields: (files: JobData["files"], event: string) => JobDataField[];
51
53
  /** The files a panel reads (`files`: comma separated paths or globs, all when empty) */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milabench/bujang",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/types.ts CHANGED
@@ -943,13 +943,18 @@ export interface StatsMetric {
943
943
  event: string;
944
944
  field: string;
945
945
  title?: string;
946
+ /** comma separated fields: a row per value of them */
947
+ by?: string;
946
948
  }
947
949
 
950
+ /** A statistic of a stats block; busy: the total over the time from the first `start` to the last `end` */
951
+ export type StatName = 'total' | 'busy' | 'count' | 'mean' | 'std' | 'min' | 'median' | 'p95' | 'p99' | 'max';
952
+
948
953
  /** A block of the Overview tab: the log view, the media of the artifact folders, or a chart (Vega-Lite) of one or several events */
949
954
  export type OverviewBlock =
950
955
  | { kind: 'artifacts'; title?: string; files?: string }
951
956
  | { kind: 'files'; title?: string }
952
- | { kind: 'stats'; title?: string; metrics?: StatsMetric[] }
957
+ | { kind: 'stats'; title?: string; metrics?: StatsMetric[]; show?: StatName[] }
953
958
  | { kind: 'logs'; title?: string; levels?: string[]; files?: string }
954
959
  | {
955
960
  kind: 'chart';
@@ -972,8 +977,15 @@ export type OverviewBlock =
972
977
  zero?: boolean;
973
978
  };
974
979
 
980
+ /** Blocks side by side, of the same width or of relative widths */
981
+ export interface ColumnsPanel {
982
+ kind: 'columns';
983
+ columns: OverviewBlock[][];
984
+ widths?: number[];
985
+ }
986
+
975
987
  /** A panel of the Overview tab: a block, or columns of blocks side by side */
976
- export type OverviewPanel = OverviewBlock | { kind: 'columns'; columns: OverviewBlock[][] };
988
+ export type OverviewPanel = OverviewBlock | ColumnsPanel;
977
989
 
978
990
  export interface OverviewLayout {
979
991
  panels: OverviewPanel[];
@@ -35,6 +35,7 @@ import {
35
35
  MARKS,
36
36
  ROLE_ORDER,
37
37
  ROW_LIMIT,
38
+ fileRanks,
38
39
  VegaChart,
39
40
  buildSpec,
40
41
  filesWithEvent,
@@ -124,6 +125,21 @@ export const JobDataOverview: React.FC<{
124
125
  }, [data, dataUpdatedAt, version, jrJobId, queryClient]);
125
126
 
126
127
  const files = useMemo(() => (data?.files || []).filter((f) => !f.error), [data]);
128
+ // a job of several processes, each with its files: the panels show one of them, the first by default
129
+ const ranks = useMemo(() => fileRanks(files), [files]);
130
+ const rankList = useMemo(
131
+ () => [...new Set([...ranks.values()].filter((r): r is number => r !== null))].sort((a, b) => a - b),
132
+ [ranks],
133
+ );
134
+ const [pickedRank, setPickedRank] = useState<number | 'all' | null>(null);
135
+ const rank = rankList.length < 2
136
+ ? 'all'
137
+ : pickedRank === 'all' || (pickedRank !== null && rankList.includes(pickedRank)) ? pickedRank : rankList[0];
138
+ const rankFiles = useMemo(
139
+ // the files of no rank are always there
140
+ () => (rank === 'all' ? files : files.filter((f) => (ranks.get(f.path) ?? rank) === rank)),
141
+ [files, ranks, rank],
142
+ );
127
143
  const [selectedFiles, setSelectedFiles] = useState<string[] | null>(null);
128
144
  const activeFiles = useMemo(
129
145
  () => files.filter((f) => selectedFiles === null || selectedFiles.includes(f.path)),
@@ -318,8 +334,24 @@ export const JobDataOverview: React.FC<{
318
334
  }
319
335
  }}
320
336
  />
337
+ {view === 'job' && rankList.length > 1 && (
338
+ <HStack gap={2} justify="flex-end">
339
+ <Text fontSize="xs" color="var(--color-text-muted)">Rank</Text>
340
+ <NativeSelect.Root size="xs" w="110px" title="The process whose data the panels show">
341
+ <NativeSelect.Field
342
+ aria-label="Rank"
343
+ value={String(rank)}
344
+ onChange={(e) => setPickedRank(e.target.value === 'all' ? 'all' : Number(e.target.value))}
345
+ >
346
+ {rankList.map((r) => <option key={r} value={r}>rank {r}</option>)}
347
+ <option value="all">all ranks</option>
348
+ </NativeSelect.Field>
349
+ <NativeSelect.Indicator />
350
+ </NativeSelect.Root>
351
+ </HStack>
352
+ )}
321
353
  {view === 'job' && (
322
- <LayoutPanels jrJobId={jrJobId} files={files} layout={layout} available={found.blocks ?? []} editing={editing} onChange={setDraft} onEditor={(open) => setFrozen(open ? layout : null)} />
354
+ <LayoutPanels jrJobId={jrJobId} files={rankFiles} oneRank={rank !== 'all'} layout={layout} available={found.blocks ?? []} editing={editing} onChange={setDraft} onEditor={(open) => setFrozen(open ? layout : null)} />
323
355
  )}
324
356
  </>
325
357
  )}
@@ -10,6 +10,7 @@ import {
10
10
  VStack,
11
11
  HStack,
12
12
  Button,
13
+ NativeSelect,
13
14
  Card,
14
15
  Spinner,
15
16
  Alert,
@@ -35,6 +36,30 @@ import type { SlurmJobDetail, ApiError } from '../types';
35
36
  type JobLogsViewProps = Record<string, never>;
36
37
  type JobLogsTab = 'logs' | 'overview';
37
38
 
39
+ // Seconds between two automatic early syncs: 'x2' waits twice the time the last one took
40
+ type AutoSyncEvery = 'x2' | '10' | '30' | '60';
41
+ const AUTO_SYNC_EVERY: { value: AutoSyncEvery; label: string }[] = [
42
+ { value: 'x2', label: '2× sync time' },
43
+ { value: '10', label: '10 s' },
44
+ { value: '30', label: '30 s' },
45
+ { value: '60', label: '60 s' },
46
+ ];
47
+ const AUTO_SYNC_KEY = 'bujang-auto-early-sync';
48
+ /** 'x2' does not go below: each sync starts a step in the job */
49
+ const AUTO_SYNC_MIN = 5;
50
+
51
+ /** Seconds to the next automatic early sync; `took`: seconds of the last one */
52
+ const autoSyncDelay = (every: AutoSyncEvery, took = 0) => (every === 'x2' ? Math.max(AUTO_SYNC_MIN, 2 * took) : Number(every));
53
+
54
+ const savedAutoSyncEvery = (): AutoSyncEvery => {
55
+ try {
56
+ const saved = localStorage.getItem(AUTO_SYNC_KEY);
57
+ return AUTO_SYNC_EVERY.find((o) => o.value === saved)?.value ?? 'x2';
58
+ } catch {
59
+ return 'x2';
60
+ }
61
+ };
62
+
38
63
  const getStatusColor = (status: string) => {
39
64
  switch (status?.toLowerCase()) {
40
65
  case 'running':
@@ -120,6 +145,14 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
120
145
 
121
146
  // Early sync state
122
147
  const [isEarlySync, setIsEarlySync] = useState(false);
148
+ // the job synced automatically: off when the page moves to another job
149
+ const [autoSyncJob, setAutoSyncJob] = useState<string | null>(null);
150
+ const autoSync = !!jrJobId && autoSyncJob === jrJobId;
151
+ const [autoSyncEvery, setAutoSyncEvery] = useState<AutoSyncEvery>(savedAutoSyncEvery);
152
+ const changeAutoSyncEvery = (value: AutoSyncEvery) => {
153
+ try { localStorage.setItem(AUTO_SYNC_KEY, value); } catch { /* this page only */ }
154
+ setAutoSyncEvery(value);
155
+ };
123
156
 
124
157
  // Edit & Resubmit state
125
158
  const [isEditModalOpen, setIsEditModalOpen] = useState(false);
@@ -501,6 +534,32 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
501
534
  }
502
535
  };
503
536
 
537
+ // Automatic early sync, while the job runs. A failed one is tried again at the next turn (the
538
+ // error is shown on the button)
539
+ const { data: autoSyncResult, error: autoSyncFailure } = useQuery({
540
+ queryKey: ['bujang-auto-early-sync', jrJobId, slurmJobId],
541
+ queryFn: async () => {
542
+ const start = performance.now();
543
+ const result = await earlySyncJob(jrJobId!, slurmJobId!);
544
+ const took = (performance.now() - start) / 1000;
545
+ if (result.status === 'ok') {
546
+ queryClient.invalidateQueries({ queryKey: ['slurm-job-logs'] });
547
+ queryClient.invalidateQueries({ queryKey: ['bujang-job-data', jrJobId] });
548
+ }
549
+ return { ...result, took };
550
+ },
551
+ enabled: autoSync && !!slurmJobId && slurmJobId !== '-' && jobStatus?.toUpperCase() === 'RUNNING',
552
+ refetchInterval: (query) => 1000 * autoSyncDelay(autoSyncEvery, query.state.data?.took),
553
+ refetchOnWindowFocus: false,
554
+ retry: false,
555
+ gcTime: 0,
556
+ });
557
+ const autoSyncError = autoSyncFailure
558
+ ? ((autoSyncFailure as unknown as ApiError).message || 'An unexpected error occurred')
559
+ : autoSyncResult && autoSyncResult.status !== 'ok'
560
+ ? (autoSyncResult.error || 'Could not sync the job results early')
561
+ : null;
562
+
504
563
  // Lazy-loaded templates & profiles for the edit modal
505
564
  const { data: templateNames } = useQuery<string[]>({
506
565
  queryKey: ['slurm-templates'],
@@ -666,16 +725,46 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
666
725
  <LuPencil />
667
726
  </Button>
668
727
  </HStack>
669
- <Button
670
- variant="outline"
671
- colorScheme="orange"
672
- onClick={handleEarlySync}
673
- loading={isEarlySync}
674
- disabled={!slurmJobId || slurmJobId === '-' || isJobTerminal}
675
- >
676
- <LuClock />
677
- Early Sync
678
- </Button>
728
+ <HStack gap={0}>
729
+ <Button
730
+ variant="outline"
731
+ colorScheme="orange"
732
+ onClick={handleEarlySync}
733
+ loading={isEarlySync}
734
+ disabled={!slurmJobId || slurmJobId === '-' || isJobTerminal}
735
+ borderRightRadius={0}
736
+ >
737
+ <LuClock />
738
+ Early Sync
739
+ </Button>
740
+ <Button
741
+ variant={autoSync && !isJobTerminal ? 'solid' : 'outline'}
742
+ colorPalette={autoSync && autoSyncError ? 'red' : undefined}
743
+ onClick={() => setAutoSyncJob(autoSync ? null : jrJobId ?? null)}
744
+ disabled={!slurmJobId || slurmJobId === '-' || isJobTerminal}
745
+ aria-pressed={autoSync}
746
+ borderLeftRadius={0}
747
+ borderLeft="none"
748
+ px={2}
749
+ title={autoSync && autoSyncError
750
+ ? `Automatic early sync failed, trying again: ${autoSyncError}`
751
+ : `Early sync while the job runs (${autoSync ? `on: every ${autoSyncDelay(autoSyncEvery, autoSyncResult?.took).toFixed(0)} s` : 'off'})`}
752
+ >
753
+ Auto
754
+ </Button>
755
+ <NativeSelect.Root size="md" w="140px" title="Time between two automatic early syncs">
756
+ <NativeSelect.Field
757
+ aria-label="Time between two automatic early syncs"
758
+ value={autoSyncEvery}
759
+ onChange={(e) => changeAutoSyncEvery(e.target.value as AutoSyncEvery)}
760
+ borderLeftRadius={0}
761
+ borderLeft="none"
762
+ >
763
+ {AUTO_SYNC_EVERY.map((o) => <option key={o.value} value={o.value}>{o.label}</option>)}
764
+ </NativeSelect.Field>
765
+ <NativeSelect.Indicator />
766
+ </NativeSelect.Root>
767
+ </HStack>
679
768
  {canCancelJob(jobStatus) && (
680
769
  <Button
681
770
  variant="outline"