Skip to content

Commit 49cc84a

Browse files
authored
HParams: Add new selector factory to get runs from experiment ids (#6360)
## Motivation for features / changes As part of the effort to bring hparams to the time series dashboard a handful of new selectors need to be created. In particular I will be creating a new one to handle runs filtering by moving the logic out of the runs_table_container into the selector layer. This will ensure filtered runs are consistent across the dashboard. ## Technical description of changes This new selector is not meaningfully different from the existing one but the factory allows it to be called with an encapsulated experiment id.
1 parent e166112 commit 49cc84a

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

tensorboard/webapp/runs/store/runs_selectors.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ export const getRuns = createSelector(
7979
}
8080
);
8181

82+
export const getRunsFromExperimentIds = (experimentIds: string[]) =>
83+
createSelector(
84+
getDataState,
85+
(state: RunsDataState): Array<Run & {experimentId: string}> => {
86+
return experimentIds.reduce((runs, experimentId) => {
87+
(state.runIds[experimentId] || [])
88+
.filter((id) => Boolean(state.runMetadata[id]))
89+
.forEach((runId) => {
90+
runs.push({...state.runMetadata[runId], experimentId});
91+
});
92+
93+
return runs;
94+
}, [] as Array<Run & {experimentId: string}>);
95+
}
96+
);
97+
8298
/**
8399
* Returns Observable that emits runs list for an experiment.
84100
*/

tensorboard/webapp/runs/store/runs_selectors_test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,57 @@ describe('runs_selectors', () => {
176176
});
177177
});
178178

179+
describe('#getRunsFromExperimentIds', () => {
180+
it('returns runs', () => {
181+
const state = buildStateFromRunsState(
182+
buildRunsState({
183+
runIds: {
184+
eid: ['run1'],
185+
},
186+
runMetadata: {
187+
run1: buildRun({id: 'run1'}),
188+
},
189+
})
190+
);
191+
expect(selectors.getRunsFromExperimentIds(['eid'])(state)).toEqual([
192+
{
193+
...buildRun({
194+
id: 'run1',
195+
}),
196+
experimentId: 'eid',
197+
},
198+
]);
199+
});
200+
201+
it('returns runs for the ones that has metadata', () => {
202+
const state = buildStateFromRunsState(
203+
buildRunsState({
204+
runIds: {
205+
eid: ['run1', 'run2'],
206+
},
207+
runMetadata: {
208+
run1: buildRun({id: 'run1'}),
209+
},
210+
})
211+
);
212+
expect(selectors.getRunsFromExperimentIds(['eid'])(state)).toEqual([
213+
{
214+
...buildRun({
215+
id: 'run1',
216+
}),
217+
experimentId: 'eid',
218+
},
219+
]);
220+
});
221+
222+
it('returns empty list if experiment id does not exist', () => {
223+
const state = buildStateFromRunsState(buildRunsState());
224+
expect(
225+
selectors.getRunsFromExperimentIds(['i_do_not_exist'])(state)
226+
).toEqual([]);
227+
});
228+
});
229+
179230
describe('#getRunIdsForExperiment', () => {
180231
beforeEach(() => {
181232
// Clear the memoization.

0 commit comments

Comments
 (0)