Skip to content

Commit b408561

Browse files
authored
Hparam: Add selectors to retrieve data written by the new hparams effects (#6544)
## Motivation for features / changes This is a continuation of #6540 Now that data is being retrieved from the hparams plugin and written to the store I am adding a pair of selectors to retrieve it and inject it into the the data retrieved from `getRuns` and `getRunsForExperimentId`. The logic used to translate `SessionGroups` to `Record<RunId/Group, Value>` is very similar to that being used by the old code in `runs_data_source`. I could imagine this being refactored to retrieve the run/group relationships from another part of the store in the future in order to better integrate with our plans to stop relying on the metrics portion of the hparams payload. ## Note For Reviewer(s) A large majority of the lines changed in this PR are indent changes resulting from changing the method used to mock the state during tests. I have opted not to add additional test to the runs or common selectors (though I did have to fix 16) as the intention is for this to be a drop in replacement with no new features added. The number of test failures which I had to fix left me feeling confident of the existing test coverage.
1 parent fd3b82e commit b408561

File tree

19 files changed

+783
-258
lines changed

19 files changed

+783
-258
lines changed

tensorboard/webapp/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,16 @@ tf_ng_module(
142142
"app_state.ts",
143143
],
144144
deps = [
145+
"//tensorboard/plugins/debugger_v2/tf_debugger_v2_plugin/store:types",
146+
"//tensorboard/webapp/alert/store:types",
145147
"//tensorboard/webapp/app_routing/store:types",
146148
"//tensorboard/webapp/core/store",
147149
"//tensorboard/webapp/experiments/store:types",
148150
"//tensorboard/webapp/feature_flag/store:types",
149151
"//tensorboard/webapp/hparams:types",
150152
"//tensorboard/webapp/metrics/store:types",
151153
"//tensorboard/webapp/notification_center/_redux:types",
154+
"//tensorboard/webapp/persistent_settings/_redux:types",
152155
"//tensorboard/webapp/runs/store:types",
153156
"//tensorboard/webapp/settings",
154157
],

tensorboard/webapp/alert/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ tf_ts_library(
3737
"types.ts",
3838
],
3939
deps = [
40-
"//tensorboard/webapp:app_state",
4140
"@npm//@ngrx/store",
4241
"@npm//rxjs",
4342
],

tensorboard/webapp/alert/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15-
import {Action, Store} from '@ngrx/store';
16-
import {State} from '../app_state';
15+
import {Action} from '@ngrx/store';
1716

1817
/**
1918
* An alert structure used when creating newly reported alerts.
@@ -35,7 +34,7 @@ export interface AlertReport {
3534
* when the followup action is requested, a newly created Promise will be
3635
* awaited, and the resulting action is dispatched.
3736
*/
38-
getFollowupAction: (store: Store<State>) => Promise<Action>;
37+
getFollowupAction: () => Promise<Action>;
3938
};
4039
}
4140

tensorboard/webapp/alert/views/alert_display_snackbar_container.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ export class AlertDisplaySnackbarContainer {
4343
async onActionButtonClicked() {
4444
this.snackBarRef.dismiss();
4545

46-
const followupAction = await this.alert.followupAction!.getFollowupAction(
47-
this.store
48-
);
46+
const followupAction = await this.alert.followupAction!.getFollowupAction();
4947
this.store.dispatch(followupAction);
5048
}
5149

tensorboard/webapp/app_state.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515

16+
import {State as DebuggerState} from '../plugins/debugger_v2/tf_debugger_v2_plugin/store/debugger_types';
17+
import {State as AlertState} from './alert/store/alert_types';
1618
import {State as AppRoutingState} from './app_routing/store/app_routing_types';
1719
import {State as CoreState} from './core/store/core_types';
1820
import {State as ExperimentsState} from './experiments/store/experiments_types';
1921
import {State as FeatureFlagState} from './feature_flag/store/feature_flag_types';
2022
import {State as HparamsState} from './hparams/types';
2123
import {State as MetricsState} from './metrics/store/metrics_types';
2224
import {State as NotificationState} from './notification_center/_redux/notification_center_types';
25+
import {State as PersistentSettingsState} from './persistent_settings/_redux/persistent_settings_types';
2326
import {State as RunsState} from './runs/store/runs_types';
2427
import {State as SettingsState} from './settings';
2528

@@ -31,4 +34,7 @@ export type State = AppRoutingState &
3134
MetricsState &
3235
RunsState &
3336
SettingsState &
34-
NotificationState;
37+
NotificationState &
38+
DebuggerState &
39+
AlertState &
40+
PersistentSettingsState;

tensorboard/webapp/hparams/_redux/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ tf_ts_library(
168168
"//tensorboard/webapp/runs/data_source:testing",
169169
"//tensorboard/webapp/runs/store:testing",
170170
"//tensorboard/webapp/testing:utils",
171+
"//tensorboard/webapp/util:types",
171172
"//tensorboard/webapp/webapp_data_source:http_client_testing",
172173
"@npm//@ngrx/effects",
173174
"@npm//@ngrx/store",

tensorboard/webapp/hparams/_redux/hparams_selectors.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515
import {createFeatureSelector, createSelector} from '@ngrx/store';
16-
import {DiscreteFilter, HparamAndMetricSpec, IntervalFilter} from '../types';
16+
import {
17+
DiscreteFilter,
18+
HparamAndMetricSpec,
19+
HparamValue,
20+
IntervalFilter,
21+
RunToHparamsAndMetrics,
22+
} from '../types';
1723
import {combineHparamAndMetricSpecs} from './hparams_selectors_utils';
1824
import {HparamsState, HPARAMS_FEATURE_KEY} from './types';
1925
import {
@@ -178,3 +184,51 @@ export const getExperimentsHparamsAndMetricsSpecs = createSelector(
178184
);
179185
}
180186
);
187+
188+
export const getDashboardHparamsAndMetricsSpecs = createSelector(
189+
getHparamsState,
190+
(state: HparamsState) => {
191+
return state.dashboardSpecs;
192+
}
193+
);
194+
195+
export const getDashboardRunsToHparamsAndMetrics = createSelector(
196+
getHparamsState,
197+
(state): RunToHparamsAndMetrics => {
198+
const runToHparamsAndMetrics: RunToHparamsAndMetrics = {};
199+
200+
for (const sessionGroup of state.dashboardSessionGroups) {
201+
const hparams: HparamValue[] = Object.entries(sessionGroup.hparams).map(
202+
(keyValue) => {
203+
const [hparam, value] = keyValue;
204+
return {name: hparam, value};
205+
}
206+
);
207+
208+
for (const session of sessionGroup.sessions) {
209+
runToHparamsAndMetrics[session.name] = {
210+
metrics: [],
211+
hparams,
212+
};
213+
214+
for (const metricValue of session.metricValues) {
215+
const runId = metricValue.name.group
216+
? `${session.name}/${metricValue.name.group}`
217+
: session.name;
218+
219+
const hparamsAndMetrics = runToHparamsAndMetrics[runId] || {
220+
metrics: [],
221+
hparams,
222+
};
223+
hparamsAndMetrics.metrics.push({
224+
tag: metricValue.name.tag,
225+
trainingStep: metricValue.trainingStep,
226+
value: metricValue.value,
227+
});
228+
runToHparamsAndMetrics[runId] = hparamsAndMetrics;
229+
}
230+
}
231+
}
232+
return runToHparamsAndMetrics;
233+
}
234+
);

0 commit comments

Comments
 (0)