Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tensorboard/webapp/app_routing/store/app_routing_selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,20 @@ export const getExperimentIdToExperimentAliasMap = createSelector(
return Object.fromEntries(map.entries());
}
);

/**
* Returns a map from experiment id to its user-defined alias text, e.g. the
* aliases set in the compare view URL (`/compare/alias1:eid1,alias2:eid2`).
* Empty when the route does not define experiment aliases.
*/
export const getExperimentIdToAliasTextMap = createSelector(
getExperimentIdToExperimentAliasMap,
(aliasMap): Record<string, string> => {
return Object.fromEntries(
Object.entries(aliasMap).map(([experimentId, alias]) => [
experimentId,
alias.aliasText,
])
);
}
);
38 changes: 38 additions & 0 deletions tensorboard/webapp/app_routing/store/app_routing_selectors_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,44 @@ describe('app_routing_selectors', () => {
});
});

describe('getExperimentIdToAliasTextMap', () => {
beforeEach(() => {
selectors.getExperimentIdToExperimentAliasMap.release();
selectors.getExperimentIdToAliasTextMap.release();
});

it('returns a map of id to alias text for COMPARE route', () => {
const state = buildStateFromAppRoutingState(
buildAppRoutingState({
activeRoute: buildRoute({
routeKind: RouteKind.COMPARE_EXPERIMENT,
params: {
experimentIds: 'exp1:123,exp2:234',
},
}),
})
);

expect(selectors.getExperimentIdToAliasTextMap(state)).toEqual({
123: 'exp1',
234: 'exp2',
});
});

it('returns an empty map for non-compare route', () => {
const state = buildStateFromAppRoutingState(
buildAppRoutingState({
activeRoute: buildRoute({
routeKind: RouteKind.UNKNOWN,
params: {},
}),
})
);

expect(selectors.getExperimentIdToAliasTextMap(state)).toEqual({});
});
});

describe('getRegisteredRouteKinds', () => {
beforeEach(() => {
selectors.getRegisteredRouteKinds.release();
Expand Down
2 changes: 2 additions & 0 deletions tensorboard/webapp/runs/actions/runs_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const fetchRunsSucceeded = createAction(
runsForAllExperiments: Run[];
newRuns: ExperimentIdToRuns;
expNameByExpId?: Record<string, string>;
expAliasByExpId?: Record<string, string>;
}>()
);

Expand Down Expand Up @@ -84,6 +85,7 @@ export const runGroupByChanged = createAction(
experimentIds: string[];
groupBy: GroupBy;
expNameByExpId?: Record<string, string>;
expAliasByExpId?: Record<string, string>;
}>()
);

Expand Down
9 changes: 7 additions & 2 deletions tensorboard/webapp/runs/effects/runs_effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import * as hparamsActions from '../../hparams/_redux/hparams_actions';
import {
getActiveRoute,
getDashboardExperimentNames,
getExperimentIdToAliasTextMap,
getExperimentIdsFromRoute,
getRuns,
getRunsLoadState,
Expand Down Expand Up @@ -226,15 +227,19 @@ export class RunsEffects {
}
return {newRuns, runsForAllExperiments};
}),
withLatestFrom(this.store.select(getDashboardExperimentNames)),
tap(([runsData, expNameByExpId]) => {
withLatestFrom(
this.store.select(getDashboardExperimentNames),
this.store.select(getExperimentIdToAliasTextMap)
),
tap(([runsData, expNameByExpId, expAliasByExpId]) => {
const {newRuns, runsForAllExperiments} = runsData;
this.store.dispatch(
actions.fetchRunsSucceeded({
experimentIds,
newRuns,
runsForAllExperiments,
expNameByExpId,
expAliasByExpId,
})
);
}),
Expand Down
51 changes: 51 additions & 0 deletions tensorboard/webapp/runs/effects/runs_effects_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import * as hparamsActions from '../../hparams/_redux/hparams_actions';
import {
getActiveRoute,
getDashboardExperimentNames,
getExperimentIdToAliasTextMap,
getExperimentIdsFromRoute,
getRuns,
getRunsLoadState,
Expand Down Expand Up @@ -110,6 +111,7 @@ describe('runs_effects', () => {
});
store.overrideSelector(getExperimentIdsFromRoute, null);
store.overrideSelector(getActiveRoute, buildRoute());
store.overrideSelector(getExperimentIdToAliasTextMap, {});
});

afterEach(() => {
Expand Down Expand Up @@ -176,6 +178,7 @@ describe('runs_effects', () => {
456: 'exp2',
123: 'exp1',
},
expAliasByExpId: {},
}),
]);
});
Expand Down Expand Up @@ -262,6 +265,7 @@ describe('runs_effects', () => {
456: 'exp2',
123: 'exp1',
},
expAliasByExpId: {},
}),
]);
});
Expand Down Expand Up @@ -354,6 +358,7 @@ describe('runs_effects', () => {
456: 'exp1',
123: 'exp2',
},
expAliasByExpId: {},
}),
]);
});
Expand Down Expand Up @@ -391,6 +396,7 @@ describe('runs_effects', () => {
runsForAllExperiments: [...createFooRuns()],
newRuns: {},
expNameByExpId: {123: 'exp1'},
expAliasByExpId: {},
}),
]);

Expand All @@ -399,6 +405,46 @@ describe('runs_effects', () => {
expect(actualActions.length).toBe(2);
});

it('includes experiment aliases in fetchRunsSucceeded', () => {
store.overrideSelector(getActiveRoute, buildRoute());
store.overrideSelector(getExperimentIdsFromRoute, ['123']);
store.overrideSelector(getDashboardExperimentNames, {123: 'exp1'});
store.overrideSelector(getExperimentIdToAliasTextMap, {
123: 'alias1',
});
const createFooRuns = () => [
createRun({
id: 'foo/runA',
name: 'runA',
}),
];

selectSpy
.withArgs(getRuns, {experimentId: '123'})
.and.returnValue(of(createFooRuns()));
store.overrideSelector(getRunsLoadState, {
state: DataLoadState.LOADED,
lastLoadedTimeInMs: 0,
});
store.refreshState();

action.next(buildNavigatedAction());

expect(actualActions).toEqual([
actions.fetchRunsRequested({
experimentIds: ['123'],
requestedExperimentIds: [],
}),
actions.fetchRunsSucceeded({
experimentIds: ['123'],
runsForAllExperiments: [...createFooRuns()],
newRuns: {},
expNameByExpId: {123: 'exp1'},
expAliasByExpId: {123: 'alias1'},
}),
]);
});

it('dispatches fetchRunsSucceeded even if data is already loaded', () => {
const createFooRuns = () => [
createRun({
Expand Down Expand Up @@ -434,6 +480,7 @@ describe('runs_effects', () => {
runsForAllExperiments: [...createFooRuns()],
newRuns: {},
expNameByExpId: {foo: 'exp1'},
expAliasByExpId: {},
}),
]);
});
Expand Down Expand Up @@ -515,6 +562,7 @@ describe('runs_effects', () => {
456: {runs: createBarRuns()},
},
expNameByExpId: {456: 'exp1', 123: 'exp2'},
expAliasByExpId: {},
}),
actions.fetchRunsSucceeded({
experimentIds: ['123'],
Expand All @@ -523,6 +571,7 @@ describe('runs_effects', () => {
123: {runs: createFooRuns()},
},
expNameByExpId: {456: 'exp1', 123: 'exp2'},
expAliasByExpId: {},
}),
]);
});
Expand Down Expand Up @@ -652,6 +701,7 @@ describe('runs_effects', () => {
},
},
expNameByExpId: {foo: 'exp1', bar: 'exp2'},
expAliasByExpId: {},
}),
actions.fetchRunsSucceeded({
experimentIds: ['foo', 'bar'],
Expand All @@ -665,6 +715,7 @@ describe('runs_effects', () => {
},
},
expNameByExpId: {foo: 'exp1', bar: 'exp2'},
expAliasByExpId: {},
}),
]);
});
Expand Down
10 changes: 6 additions & 4 deletions tensorboard/webapp/runs/store/runs_reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ const dataReducer: ActionReducer<RunsDataState, Action> = createReducer(
}),
on(
runsActions.fetchRunsSucceeded,
(state, {runsForAllExperiments, expNameByExpId}) => {
(state, {runsForAllExperiments, expNameByExpId, expAliasByExpId}) => {
const groupKeyToColorId = new Map(state.groupKeyToColorId);
const defaultRunColorIdForGroupBy = new Map(
state.defaultRunColorIdForGroupBy
Expand All @@ -223,7 +223,8 @@ const dataReducer: ActionReducer<RunsDataState, Action> = createReducer(
groupBy,
runsForAllExperiments,
state.runIdToExpId,
expNameByExpId
expNameByExpId,
expAliasByExpId
);

Object.entries(groups.matches).forEach(([groupId, runs]) => {
Expand Down Expand Up @@ -252,7 +253,7 @@ const dataReducer: ActionReducer<RunsDataState, Action> = createReducer(
runsActions.runGroupByChanged,
(
state: RunsDataState,
{experimentIds, groupBy, expNameByExpId}
{experimentIds, groupBy, expNameByExpId, expAliasByExpId}
): RunsDataState => {
// Reset the groupKeyToColorId
const groupKeyToColorId = new Map<string, number>();
Expand All @@ -268,7 +269,8 @@ const dataReducer: ActionReducer<RunsDataState, Action> = createReducer(
groupBy,
allRuns,
state.runIdToExpId,
expNameByExpId
expNameByExpId,
expAliasByExpId
);

Object.entries(groups.matches).forEach(([groupId, runs]) => {
Expand Down
25 changes: 19 additions & 6 deletions tensorboard/webapp/runs/store/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@ import {GroupBy, GroupByKey, Run, RunGroup} from '../types';

import {ExperimentId, RunId} from './runs_types';

/**
* Groups runs according to `groupBy`.
*
* For `GroupByKey.REGEX_BY_EXP`, the regex is first matched against the
* user-defined experiment alias (e.g. set in the compare view URL), when
* available, and falls back to the experiment name otherwise.
*/
export function groupRuns(
groupBy: GroupBy,
runs: Run[],
runIdToExpId: Readonly<Record<RunId, ExperimentId>>,
expNameByExpId?: Record<string, string>
expNameByExpId?: Record<string, string>,
expAliasByExpId?: Record<string, string>
): RunGroup {
const matches: {[id: string]: Run[]} = {};
const nonMatches: Run[] = [];
Expand Down Expand Up @@ -79,8 +87,8 @@ export function groupRuns(
case GroupByKey.REGEX_BY_EXP:
if (
!groupBy.regexString ||
!expNameByExpId ||
Object.keys(expNameByExpId).length === 0
((!expNameByExpId || Object.keys(expNameByExpId).length === 0) &&
(!expAliasByExpId || Object.keys(expAliasByExpId).length === 0))
) {
break;
}
Expand All @@ -92,9 +100,14 @@ export function groupRuns(
}

for (const run of runs) {
// Tries to match against experiment alias of the run.
const experimentName = expNameByExpId[runIdToExpId[run.id]];
const matchesList = experimentName.match(regExp);
// Tries to match against the experiment alias of the run first, then
// falls back to the experiment name.
const experimentId = runIdToExpId[run.id];
const experimentAlias = expAliasByExpId?.[experimentId];
const experimentName = expNameByExpId?.[experimentId];
const matchesList =
(experimentAlias ? experimentAlias.match(regExp) : null) ??
(experimentName ? experimentName.match(regExp) : null);
if (matchesList) {
const hasCapturingGroup = matchesList.length > 1;
// In case regex string does not have a capturing group, we use pseudo
Expand Down
Loading
Loading