Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Improve trial intermediate result graph: trials have not intermediate…
Browse files Browse the repository at this point in the history
… default key (#4171)
  • Loading branch information
Lijiaoa authored Sep 15, 2021
1 parent 69a84cf commit 8875fa7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 23 deletions.
27 changes: 8 additions & 19 deletions ts/webui/src/components/modals/Compare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface CompareProps {
trials: TableObj[];
title: string;
showDetails: boolean;
intermediateKeyList?: string[];
onHideDialog: () => void;
changeSelectTrialIds?: () => void;
}
Expand All @@ -68,7 +69,9 @@ class Compare extends React.Component<CompareProps, CompareState> {
super(props);

this.state = {
intermediateKey: 'default'
// intermediate result maybe don't have the 'default' key...
intermediateKey:
this.props.intermediateKeyList !== undefined ? this.props.intermediateKeyList[0] : 'default'
};
}

Expand Down Expand Up @@ -226,10 +229,9 @@ class Compare extends React.Component<CompareProps, CompareState> {
};

render(): React.ReactNode {
const { trials, title, showDetails } = this.props;
const { trials, title, showDetails, intermediateKeyList } = this.props;
const { intermediateKey } = this.state;
let intermediateAllKeysList: string[] = [];

const intermediateAllKeysList: string[] = intermediateKeyList !== undefined ? intermediateKeyList : [];
const flatten = (m: Map<SingleAxis, any>): Map<string, any> => {
return new Map(Array.from(m).map(([key, value]) => [key.baseName, value]));
};
Expand All @@ -243,20 +245,6 @@ class Compare extends React.Component<CompareProps, CompareState> {
intermediates: _parseIntermediates(trial, intermediateKey)
}));

if (trials[0].intermediates !== undefined && trials[0].intermediates[0]) {
const parsedMetric = parseMetrics(trials[0].intermediates[0].data);
if (parsedMetric !== undefined && typeof parsedMetric === 'object') {
const allIntermediateKeys: string[] = [];
// just add type=number keys
for (const key in parsedMetric) {
if (typeof parsedMetric[key] === 'number') {
allIntermediateKeys.push(key);
}
}
intermediateAllKeysList = allIntermediateKeys;
}
}

return (
<Modal
isOpen={true}
Expand All @@ -276,7 +264,8 @@ class Compare extends React.Component<CompareProps, CompareState> {
onClick={this.closeCompareModal}
/>
</div>
{intermediateAllKeysList.length > 1 ? (
{intermediateAllKeysList.length > 1 ||
(intermediateAllKeysList.length === 1 && intermediateAllKeysList !== ['default']) ? (
<Stack horizontalAlign='end' className='selectKeys'>
<Dropdown
className='select'
Expand Down
43 changes: 39 additions & 4 deletions ts/webui/src/components/trial-detail/TableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@fluentui/react';
import { EXPERIMENT, TRIALS } from '../../static/datamodel';
import { TOOLTIP_BACKGROUND_COLOR } from '../../static/const';
import { convertDuration, formatTimestamp, copyAndSort, parametersType } from '../../static/function';
import { convertDuration, formatTimestamp, copyAndSort, parametersType, parseMetrics } from '../../static/function';
import { TableObj, SortInfo, SearchItems } from '../../static/interface';
import { getTrialsBySearchFilters } from './search/searchFunction';
import { blocked, copy, LineChart, tableListIcon } from '../buttons/Icon';
Expand Down Expand Up @@ -87,6 +87,7 @@ interface TableListState {
sortInfo: SortInfo;
searchItems: Array<SearchItems>;
relation: Map<string, string>;
intermediateKeyList: string[];
}

class TableList extends React.Component<TableListProps, TableListState> {
Expand All @@ -112,7 +113,8 @@ class TableList extends React.Component<TableListProps, TableListState> {
copiedTrialId: undefined,
sortInfo: { field: '', isDescend: true },
searchItems: [],
relation: parametersType()
relation: parametersType(),
intermediateKeyList: []
};

this._expandedTrialIds = new Set<string>();
Expand Down Expand Up @@ -437,7 +439,11 @@ class TableList extends React.Component<TableListProps, TableListState> {
onClick={(): void => {
const { tableSource } = this.props;
const trial = tableSource.find(trial => trial.id === record.id) as TableObj;
this.setState({ intermediateDialogTrial: trial });
const intermediateKeyListResult = this.getIntermediateAllKeys(trial);
this.setState({
intermediateDialogTrial: trial,
intermediateKeyList: intermediateKeyListResult
});
}}
>
{LineChart}
Expand Down Expand Up @@ -469,6 +475,33 @@ class TableList extends React.Component<TableListProps, TableListState> {
}));
};

private getIntermediateAllKeys = (intermediateDialogTrial: any): string[] => {
let intermediateAllKeysList: string[] = [];
if (
intermediateDialogTrial!.intermediateMetrics !== undefined &&
intermediateDialogTrial!.intermediateMetrics[0]
) {
const parsedMetric = parseMetrics(intermediateDialogTrial!.intermediateMetrics[0].data);
if (parsedMetric !== undefined && typeof parsedMetric === 'object') {
const allIntermediateKeys: string[] = [];
// just add type=number keys
for (const key in parsedMetric) {
if (typeof parsedMetric[key] === 'number') {
allIntermediateKeys.push(key);
}
}
intermediateAllKeysList = allIntermediateKeys;
}
}

if (intermediateAllKeysList.includes('default') && intermediateAllKeysList[0] !== 'default') {
intermediateAllKeysList = intermediateAllKeysList.filter(item => item !== 'default');
intermediateAllKeysList.unshift('default');
}

return intermediateAllKeysList;
};

componentDidUpdate(prevProps: TableListProps): void {
if (this.props.tableSource !== prevProps.tableSource) {
this._updateTableSource();
Expand All @@ -489,7 +522,8 @@ class TableList extends React.Component<TableListProps, TableListState> {
selectedRowIds,
intermediateDialogTrial,
copiedTrialId,
searchItems
searchItems,
intermediateKeyList
} = this.state;

return (
Expand Down Expand Up @@ -564,6 +598,7 @@ class TableList extends React.Component<TableListProps, TableListState> {
title='Intermediate results'
showDetails={false}
trials={[intermediateDialogTrial]}
intermediateKeyList={intermediateKeyList}
onHideDialog={(): void => {
this.setState({ intermediateDialogTrial: undefined });
}}
Expand Down

0 comments on commit 8875fa7

Please sign in to comment.