Skip to content

Commit 1416f8b

Browse files
authored
HParams: Add new experiments selector (#6324)
## 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. Getting a mapping of experiment id to name is a prerequisite for this. Also the experiments tests weren't being run? ## Technical description of changes I created a new selector factory which takes in a list of experiment ids and creates a `Record<ExperimentId, ExperimentName>` ## Screenshots of UI changes None ## Detailed steps to verify changes work correctly (as executed by you) The tests should pass (note that the webapp experiments tests should be run)
1 parent 5d6aaa5 commit 1416f8b

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

tensorboard/webapp/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ tf_ng_web_test_suite(
264264
"//tensorboard/webapp/core/views:test_lib",
265265
"//tensorboard/webapp/customization:customization_test_lib",
266266
"//tensorboard/webapp/deeplink:deeplink_test_lib",
267+
"//tensorboard/webapp/experiments/store:store_test_lib",
267268
"//tensorboard/webapp/header:test_lib",
268269
"//tensorboard/webapp/metrics:integration_test",
269270
"//tensorboard/webapp/metrics:test_lib",

tensorboard/webapp/experiments/store/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ tf_ts_library(
6464
deps = [
6565
":selectors",
6666
":testing",
67+
":types",
6768
"//tensorboard/webapp/types",
6869
"@npm//@types/jasmine",
6970
],

tensorboard/webapp/experiments/store/experiments_selectors.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,20 @@ export const getExperiment = createSelector(
4444
return state.experimentMap[experimentId] || null;
4545
}
4646
);
47+
48+
/**
49+
* Returns Observable that emits an object mapping the provided
50+
* experiment ids to experiment names.
51+
*/
52+
export const getExperimentNames = (experimentIds: string[]) =>
53+
createSelector(
54+
getDataState,
55+
(state: ExperimentsDataState): Record<string, string> =>
56+
experimentIds
57+
.map((experimentId) => state.experimentMap[experimentId])
58+
.filter(Boolean)
59+
.reduce((map, experiment) => {
60+
map[experiment.id] = experiment.name;
61+
return map;
62+
}, {} as Record<string, string>)
63+
);

tensorboard/webapp/experiments/store/experiments_selectors_test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515
import * as selectors from './experiments_selectors';
16+
import {State} from './experiments_types';
1617
import {buildExperiment, buildStateFromExperimentsState} from './testing';
1718

1819
describe('experiments selectors', () => {
@@ -47,4 +48,33 @@ describe('experiments selectors', () => {
4748
);
4849
});
4950
});
51+
52+
describe('#getExperimentNames', () => {
53+
let state: State;
54+
55+
beforeEach(() => {
56+
const foo = buildExperiment({id: 'foo', name: 'foo name'});
57+
const bar = buildExperiment({id: 'bar', name: 'bar name'});
58+
59+
state = buildStateFromExperimentsState({
60+
data: {
61+
experimentMap: {foo, bar},
62+
},
63+
});
64+
});
65+
66+
it('translates experiment ids to experiment names', () => {
67+
expect(
68+
selectors.getExperimentNames(['foo', 'bar', 'baz'])(state)
69+
).toEqual({
70+
foo: 'foo name',
71+
bar: 'bar name',
72+
});
73+
});
74+
75+
it('returns an empty object when no experiments are provided', () => {
76+
expect(selectors.getExperimentNames([])(state)).toEqual({});
77+
expect(selectors.getExperimentNames(['abc', '123'])(state)).toEqual({});
78+
});
79+
});
5080
});

0 commit comments

Comments
 (0)