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
22 changes: 17 additions & 5 deletions extension/src/experiments/columns/extract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Deps, ExperimentFields, ValueTreeRoot } from '../../cli/reader'
import { shortenForLabel } from '../../util/string'
import { DepColumns, MetricOrParamColumns } from '../webview/contract'
import {
DepColumns,
Experiment,
MetricOrParamColumns
} from '../webview/contract'

const extractMetricsOrParams = (
columns?: ValueTreeRoot
Expand All @@ -21,28 +25,36 @@ const extractMetricsOrParams = (
return acc
}

const extractDeps = (columns?: Deps): DepColumns | undefined => {
const extractDeps = (
columns?: Deps,
branch?: Experiment
): DepColumns | undefined => {
if (!columns) {
return
}

const acc: DepColumns = {}

for (const [path, { hash }] of Object.entries(columns)) {
acc[path] = shortenForLabel(hash)
const value = shortenForLabel(hash)
acc[path] = {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could move this below the if clause and add a continue in the if clause. That way you wouldn't assign to acc[path] twice.

changes: !!value && !!branch && branch?.deps?.[path].value !== value,
value
}
}

return acc
}

export const extractColumns = (
experiment: ExperimentFields
experiment: ExperimentFields,
branch?: Experiment
): {
deps: DepColumns | undefined
metrics: MetricOrParamColumns | undefined
params: MetricOrParamColumns | undefined
} => ({
deps: extractDeps(experiment.deps),
deps: extractDeps(experiment.deps, branch),
metrics: extractMetricsOrParams(experiment.metrics),
params: extractMetricsOrParams(experiment.params)
})
25 changes: 16 additions & 9 deletions extension/src/experiments/model/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ const getCheckpointTipId = (

const transformColumns = (
experiment: Experiment,
experimentFields: ExperimentFields
experimentFields: ExperimentFields,
branch?: Experiment
) => {
const { metrics, params, deps } = extractColumns(experimentFields)
const { metrics, params, deps } = extractColumns(experimentFields, branch)

if (metrics) {
experiment.metrics = metrics
Expand All @@ -133,7 +134,8 @@ const transformExperimentData = (
label: string | undefined,
sha?: string,
displayNameOrParent?: string,
logicalGroupName?: string
logicalGroupName?: string,
branch?: Experiment
): Experiment => {
const experiment = {
id,
Expand All @@ -153,7 +155,7 @@ const transformExperimentData = (
experiment.sha = sha
}

transformColumns(experiment, experimentFields)
transformColumns(experiment, experimentFields, branch)

return experiment
}
Expand All @@ -162,7 +164,8 @@ const transformExperimentOrCheckpointData = (
sha: string,
experimentData: ExperimentFieldsOrError,
experimentsObject: ExperimentsObject,
branchSha: string
branchSha: string,
branch: Experiment
): {
checkpointTipId?: string
experiment: Experiment | undefined
Expand All @@ -187,7 +190,8 @@ const transformExperimentOrCheckpointData = (
shortenForLabel(sha),
sha,
getDisplayNameOrParent(sha, branchSha, experimentsObject),
getLogicalGroupName(sha, branchSha, experimentsObject)
getLogicalGroupName(sha, branchSha, experimentsObject),
branch
)
}
}
Expand Down Expand Up @@ -222,14 +226,17 @@ const collectFromExperimentsObject = (
acc: ExperimentsAccumulator,
experimentsObject: ExperimentsObject,
branchSha: string,
branchName: string
branch: Experiment
) => {
const branchName = branch.label

for (const [sha, experimentData] of Object.entries(experimentsObject)) {
const { checkpointTipId, experiment } = transformExperimentOrCheckpointData(
sha,
experimentData,
experimentsObject,
branchSha
branchSha,
branch
)
if (!experiment) {
continue
Expand Down Expand Up @@ -257,7 +264,7 @@ const collectFromBranchesObject = (
const branch = transformExperimentData(name, experimentFields, name, sha)

if (branch) {
collectFromExperimentsObject(acc, experimentsObject, sha, branch.label)
collectFromExperimentsObject(acc, experimentsObject, sha, branch)
collectHasRunningExperiment(acc, branch)

acc.branches.push(branch)
Expand Down
7 changes: 6 additions & 1 deletion extension/src/experiments/webview/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ export interface MetricOrParamColumns {
[filename: string]: ValueTree
}

export interface ValueWithChanges {
value: string | number
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this ever be anything else than a string or number? I think we have a similar interface somewhere and we also have string[], number[], boolean, boolean[] in there.

changes: boolean
}

export interface DepColumns {
[path: string]: string
[path: string]: ValueWithChanges
}

export interface Experiment extends BaseExperimentFields {
Expand Down
Loading