Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten table on sort #4685

Merged
merged 14 commits into from
Sep 29, 2023
54 changes: 50 additions & 4 deletions extension/src/experiments/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,19 @@ export class ExperimentsModel extends ModelWithPersistence {
}

public getRowData() {
const commitsBySha = this.applyFiltersToCommits()
const workspaceRow = {
branch: WORKSPACE_BRANCH,
...this.addDetails(this.workspace)
}
const sorts = this.getSorts()
const flattenRowData = sorts.length > 0
if (flattenRowData) {
return this.getFlattenedRowData(workspaceRow)
}

const commitsBySha: { [sha: string]: Commit } = this.applyFiltersToCommits()
const rows: Commit[] = [workspaceRow]

const rows: Commit[] = [
{ branch: WORKSPACE_BRANCH, ...this.addDetails(this.workspace) }
]
for (const { branch, sha } of this.rowOrder) {
julieg18 marked this conversation as resolved.
Show resolved Hide resolved
const commit = commitsBySha[sha]
if (!commit) {
Expand Down Expand Up @@ -829,4 +837,42 @@ export class ExperimentsModel extends ModelWithPersistence {
}
return commitsBySha
}

private applyFiltersToFlattenedCommits() {
const commitsBySha: { [sha: string]: Commit[] } = {}
const filters = this.getFilters()

for (const commit of this.commits) {
const commitWithSelectedAndStarred = this.addDetails(commit)
const experiments = this.getExperimentsByCommit(
commitWithSelectedAndStarred
)

commitsBySha[commit.sha as string] = [
commitWithSelectedAndStarred,
...(experiments || [])
].filter(exp => !!filterExperiment(filters, exp))
}

return commitsBySha
}

private getFlattenedRowData(workspaceRow: Commit): Commit[] {
const commitsBySha: { [sha: string]: Commit[] } =
this.applyFiltersToFlattenedCommits()
const rows = []

for (const { branch, sha } of this.rowOrder) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[C] Once the table is flattened we could have duplicate entries right next to each other. We will need a way to collapse these rows:

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing that will differ between records will be the branch/tags. I think we should consider concatenating the information on multiple lines into a single cell.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! I will open a followup issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be fixed before moving on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be fixed before moving on.

Oh, ok! Apologies, I misunderstood your comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #4735

const commitsAndExps = commitsBySha[sha]
if (!commitsAndExps) {
continue
}

rows.push(
...commitsAndExps.map(commitOrExp => ({ ...commitOrExp, branch }))
)
}

return [workspaceRow, ...sortExperiments(this.getSorts(), rows)]
}
}
199 changes: 199 additions & 0 deletions extension/src/test/fixtures/expShow/sorted/columns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
import { join } from 'path'
import { Column, ColumnType } from '../../../../experiments/webview/contract'
import { buildMetricOrParamPath } from '../../../../experiments/columns/paths'
import { timestampColumn } from '../../../../experiments/columns/constants'

const nestedParamsFile = join('nested', 'params.yaml')

const data: Column[] = [
timestampColumn,
{
type: ColumnType.METRICS,
hasChildren: true,
label: 'summary.json',
parentPath: buildMetricOrParamPath(ColumnType.METRICS),
path: buildMetricOrParamPath(ColumnType.METRICS, 'summary.json')
},
{
type: ColumnType.METRICS,
hasChildren: false,
label: 'loss',
parentPath: buildMetricOrParamPath(ColumnType.METRICS, 'summary.json'),
path: buildMetricOrParamPath(ColumnType.METRICS, 'summary.json', 'loss'),
pathArray: [ColumnType.METRICS, 'summary.json', 'loss'],
firstValueType: 'number'
},
{
type: ColumnType.METRICS,
hasChildren: false,
label: 'accuracy',
parentPath: buildMetricOrParamPath(ColumnType.METRICS, 'summary.json'),
path: buildMetricOrParamPath(
ColumnType.METRICS,
'summary.json',
'accuracy'
),
pathArray: [ColumnType.METRICS, 'summary.json', 'accuracy'],
firstValueType: 'number'
},
{
type: ColumnType.METRICS,
hasChildren: false,
label: 'val_loss',
parentPath: buildMetricOrParamPath(ColumnType.METRICS, 'summary.json'),
path: buildMetricOrParamPath(
ColumnType.METRICS,
'summary.json',
'val_loss'
),
pathArray: [ColumnType.METRICS, 'summary.json', 'val_loss'],
firstValueType: 'number'
},
{
type: ColumnType.METRICS,
hasChildren: false,
label: 'val_accuracy',
parentPath: buildMetricOrParamPath(ColumnType.METRICS, 'summary.json'),
path: buildMetricOrParamPath(
ColumnType.METRICS,
'summary.json',
'val_accuracy'
),
pathArray: [ColumnType.METRICS, 'summary.json', 'val_accuracy'],
firstValueType: 'number'
},
{
type: ColumnType.PARAMS,
hasChildren: true,
label: 'params.yaml',
parentPath: ColumnType.PARAMS,
path: buildMetricOrParamPath(ColumnType.PARAMS, 'params.yaml')
},
{
type: ColumnType.PARAMS,
hasChildren: false,
label: 'code_names',
parentPath: buildMetricOrParamPath(ColumnType.PARAMS, 'params.yaml'),
path: buildMetricOrParamPath(
ColumnType.PARAMS,
'params.yaml',
'code_names'
),
pathArray: [ColumnType.PARAMS, 'params.yaml', 'code_names'],
firstValueType: 'array'
},
{
type: ColumnType.PARAMS,
hasChildren: false,
label: 'epochs',
parentPath: buildMetricOrParamPath(ColumnType.PARAMS, 'params.yaml'),
path: buildMetricOrParamPath(ColumnType.PARAMS, 'params.yaml', 'epochs'),
pathArray: [ColumnType.PARAMS, 'params.yaml', 'epochs'],
firstValueType: 'number'
},
{
type: ColumnType.PARAMS,
hasChildren: false,
label: 'learning_rate',
parentPath: buildMetricOrParamPath(ColumnType.PARAMS, 'params.yaml'),
path: buildMetricOrParamPath(
ColumnType.PARAMS,
'params.yaml',
'learning_rate'
),
pathArray: [ColumnType.PARAMS, 'params.yaml', 'learning_rate'],
firstValueType: 'number'
},
{
type: ColumnType.PARAMS,
hasChildren: false,
label: 'dvc_logs_dir',
parentPath: buildMetricOrParamPath(ColumnType.PARAMS, 'params.yaml'),
path: buildMetricOrParamPath(
ColumnType.PARAMS,
'params.yaml',
'dvc_logs_dir'
),
pathArray: [ColumnType.PARAMS, 'params.yaml', 'dvc_logs_dir'],
firstValueType: 'string'
},
{
type: ColumnType.PARAMS,
hasChildren: false,
label: 'log_file',
parentPath: buildMetricOrParamPath(ColumnType.PARAMS, 'params.yaml'),
path: buildMetricOrParamPath(ColumnType.PARAMS, 'params.yaml', 'log_file'),
pathArray: [ColumnType.PARAMS, 'params.yaml', 'log_file'],
firstValueType: 'string'
},
{
type: ColumnType.PARAMS,
hasChildren: false,
label: 'dropout',
parentPath: buildMetricOrParamPath(ColumnType.PARAMS, 'params.yaml'),
path: buildMetricOrParamPath(ColumnType.PARAMS, 'params.yaml', 'dropout'),
pathArray: [ColumnType.PARAMS, 'params.yaml', 'dropout'],
firstValueType: 'number'
},
{
type: ColumnType.PARAMS,
hasChildren: true,
label: 'process',
parentPath: buildMetricOrParamPath(ColumnType.PARAMS, 'params.yaml'),
path: buildMetricOrParamPath(ColumnType.PARAMS, 'params.yaml', 'process')
},
{
type: ColumnType.PARAMS,
hasChildren: false,
label: 'threshold',
parentPath: buildMetricOrParamPath(
ColumnType.PARAMS,
'params.yaml',
'process'
),
path: buildMetricOrParamPath(
ColumnType.PARAMS,
'params.yaml',
'process',
'threshold'
),
pathArray: [ColumnType.PARAMS, 'params.yaml', 'process', 'threshold'],
firstValueType: 'number'
},
{
type: ColumnType.PARAMS,
hasChildren: true,
label: nestedParamsFile,
parentPath: ColumnType.PARAMS,
path: buildMetricOrParamPath(ColumnType.PARAMS, nestedParamsFile)
},
{
type: ColumnType.PARAMS,
hasChildren: false,
label: 'test',
parentPath: buildMetricOrParamPath(ColumnType.PARAMS, nestedParamsFile),
path: buildMetricOrParamPath(ColumnType.PARAMS, nestedParamsFile, 'test'),
pathArray: [ColumnType.PARAMS, nestedParamsFile, 'test'],
firstValueType: 'boolean'
},
{
type: ColumnType.PARAMS,
hasChildren: false,
label: 'test_arg',
parentPath: buildMetricOrParamPath(
ColumnType.PARAMS,
'params.yaml',
'process'
),
path: buildMetricOrParamPath(
ColumnType.PARAMS,
'params.yaml',
'process',
'test_arg'
),
pathArray: [ColumnType.PARAMS, 'params.yaml', 'process', 'test_arg'],
firstValueType: 'string'
}
]

export default data
Loading
Loading