Skip to content

Commit 8ca380e

Browse files
authored
Remove running checkpoint experiment workspace race condition code from plots (#2882)
* rip out race condition logic for watching checkpoint experiment plots in the workspace * remove some more dead code
1 parent 71e6d27 commit 8ca380e

File tree

10 files changed

+24
-260
lines changed

10 files changed

+24
-260
lines changed

extension/src/cli/dvc/runner.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ import { Disposable } from '../../class/dispose'
2020
export const autoRegisteredCommands = {
2121
EXPERIMENT_RESET_AND_RUN: 'runExperimentReset',
2222
EXPERIMENT_RUN: 'runExperiment',
23-
EXPERIMENT_RUN_QUEUED: 'runExperimentQueue',
24-
IS_EXPERIMENT_RUNNING: 'isExperimentRunning'
23+
EXPERIMENT_RUN_QUEUED: 'runExperimentQueue'
2524
} as const
2625

2726
export class DvcRunner extends Disposable implements ICli {

extension/src/experiments/model/collect.test.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,6 @@ describe('collectMutableRevisions', () => {
169169
{ label: 'workspace', selected: false, status: ExperimentStatus.FAILED }
170170
] as Experiment[]
171171

172-
it('should not return the workspace when there is a selected running checkpoint experiment (race condition)', () => {
173-
const experiments = [
174-
{
175-
label: 'exp-123',
176-
selected: true,
177-
status: ExperimentStatus.RUNNING
178-
},
179-
...baseExperiments
180-
] as Experiment[]
181-
182-
const mutableRevisions = collectMutableRevisions(experiments, true)
183-
expect(mutableRevisions).toStrictEqual([])
184-
})
185-
186172
it('should return the workspace when there is an unselected running checkpoint experiment', () => {
187173
const experiments = [
188174
{

extension/src/experiments/model/collect.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import {
1313
ExperimentFieldsOrError,
1414
ExperimentFields,
1515
ExperimentsBranchOutput,
16-
ExperimentsOutput,
17-
ExperimentStatus
16+
ExperimentsOutput
1817
} from '../../cli/dvc/contract'
1918
import { addToMapArray } from '../../util/map'
2019
import { uniqueValues } from '../../util/array'
@@ -328,27 +327,13 @@ export const collectExperiments = (
328327
return acc
329328
}
330329

331-
const getDefaultMutableRevision = (hasCheckpoints: boolean): string[] => {
332-
if (hasCheckpoints) {
333-
return []
334-
}
335-
return ['workspace']
336-
}
337-
338-
const noWorkspaceVsSelectedRaceCondition = (
339-
hasCheckpoints: boolean,
340-
status: ExperimentStatus | undefined,
341-
selected: boolean | undefined
342-
): boolean => !!(hasCheckpoints && isRunning(status) && !selected)
330+
const getDefaultMutableRevision = (): string[] => ['workspace']
343331

344332
const collectMutableRevision = (
345333
acc: string[],
346-
{ label, status, selected }: Experiment,
334+
{ label, status }: Experiment,
347335
hasCheckpoints: boolean
348336
) => {
349-
if (noWorkspaceVsSelectedRaceCondition(hasCheckpoints, status, selected)) {
350-
acc.push('workspace')
351-
}
352337
if (isRunning(status) && !hasCheckpoints) {
353338
acc.push(label)
354339
}
@@ -358,7 +343,7 @@ export const collectMutableRevisions = (
358343
experiments: Experiment[],
359344
hasCheckpoints: boolean
360345
): string[] => {
361-
const acc = getDefaultMutableRevision(hasCheckpoints)
346+
const acc = getDefaultMutableRevision()
362347

363348
for (const experiment of experiments) {
364349
collectMutableRevision(acc, experiment, hasCheckpoints)

extension/src/plots/data/index.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import { collectFiles } from './collect'
33
import { PlotsOutputOrError } from '../../cli/dvc/contract'
44
import { AvailableCommands, InternalCommands } from '../../commands/internal'
55
import { BaseData } from '../../data'
6-
import {
7-
definedAndNonEmpty,
8-
flattenUnique,
9-
sameContents
10-
} from '../../util/array'
6+
import { flattenUnique, sameContents } from '../../util/array'
117
import { PlotsModel } from '../model'
128

139
export class PlotsData extends BaseData<{
@@ -43,15 +39,6 @@ export class PlotsData extends BaseData<{
4339
this.model.getMutableRevisions()
4440
])
4541

46-
if (
47-
(await this.internalCommands.executeCommand<boolean>(
48-
AvailableCommands.IS_EXPERIMENT_RUNNING
49-
)) &&
50-
!definedAndNonEmpty(revs)
51-
) {
52-
return
53-
}
54-
5542
const args = this.getArgs(revs)
5643
const data = await this.internalCommands.executeCommand<PlotsOutputOrError>(
5744
AvailableCommands.PLOTS_DIFF,

extension/src/plots/model/collect.test.ts

Lines changed: 1 addition & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
import { join } from 'path'
22
import omit from 'lodash.omit'
33
import isEmpty from 'lodash.isempty'
4-
import cloneDeep from 'lodash.clonedeep'
5-
import merge from 'lodash.merge'
64
import {
75
collectData,
86
collectCheckpointPlotsData,
97
collectTemplates,
108
collectMetricOrder,
11-
collectWorkspaceRunningCheckpoint,
12-
collectWorkspaceRaceConditionData,
139
collectOverrideRevisionDetails
1410
} from './collect'
1511
import plotsDiffFixture from '../../test/fixtures/plotsDiff/output'
1612
import expShowFixture from '../../test/fixtures/expShow/base/output'
1713
import modifiedFixture from '../../test/fixtures/expShow/modified/output'
1814
import checkpointPlotsFixture from '../../test/fixtures/expShow/base/checkpointPlots'
1915
import { ExperimentsOutput, ExperimentStatus } from '../../cli/dvc/contract'
20-
import {
21-
definedAndNonEmpty,
22-
sameContents,
23-
uniqueValues
24-
} from '../../util/array'
16+
import { definedAndNonEmpty, sameContents } from '../../util/array'
2517
import { TemplatePlot } from '../webview/contract'
2618
import { getCLIBranchId } from '../../test/fixtures/plotsDiff/util'
2719
import { SelectedExperimentWithColor } from '../../experiments/model'
@@ -83,34 +75,6 @@ describe('collectCheckpointPlotsData', () => {
8375
})
8476
})
8577

86-
describe('collectWorkspaceRunningCheckpoint', () => {
87-
const fixtureCopy = cloneDeep(expShowFixture)
88-
const runningCheckpointFixture: ExperimentsOutput = merge(fixtureCopy, {
89-
'53c3851f46955fa3e2b8f6e1c52999acc8c9ea77': {
90-
'4fb124aebddb2adf1545030907687fa9a4c80e70': {
91-
data: {
92-
executor: 'workspace'
93-
}
94-
}
95-
}
96-
})
97-
98-
it('should return the expected sha from the test fixture', () => {
99-
const checkpointRunningInTheWorkspace = collectWorkspaceRunningCheckpoint(
100-
runningCheckpointFixture,
101-
true
102-
)
103-
104-
expect(checkpointRunningInTheWorkspace).toStrictEqual('4fb124a')
105-
})
106-
107-
it('should always return undefined when there are no checkpoints', () => {
108-
expect(
109-
collectWorkspaceRunningCheckpoint(runningCheckpointFixture, false)
110-
).toBeUndefined()
111-
})
112-
})
113-
11478
describe('collectMetricOrder', () => {
11579
it('should return an empty array if there is no checkpoints data', () => {
11680
const metricOrder = collectMetricOrder(
@@ -302,66 +266,6 @@ describe('collectTemplates', () => {
302266
})
303267
})
304268

305-
describe('collectWorkspaceRaceConditionData', () => {
306-
const { comparisonData, revisionData } = collectData(plotsDiffFixture, {
307-
'1ba7bcd': '1ba7bcd',
308-
'42b8736': '42b8736',
309-
'4fb124a': '4fb124a',
310-
'53c3851': 'main',
311-
workspace: 'workspace'
312-
})
313-
314-
it('should return no overwrite data if there is no selected checkpoint experiment running in the workspace', () => {
315-
const { overwriteComparisonData, overwriteRevisionData } =
316-
collectWorkspaceRaceConditionData(undefined, comparisonData, revisionData)
317-
expect(overwriteComparisonData).toStrictEqual({})
318-
expect(overwriteRevisionData).toStrictEqual({})
319-
})
320-
321-
it('should return no overwrite data if there is no data relating to the requested checkpoint', () => {
322-
const { overwriteComparisonData, overwriteRevisionData } =
323-
collectWorkspaceRaceConditionData('7c500fd', comparisonData, revisionData)
324-
expect(overwriteComparisonData).toStrictEqual({})
325-
expect(overwriteRevisionData).toStrictEqual({})
326-
})
327-
328-
it('should return the appropriate overwrite data if the revision exists inside of the given data', () => {
329-
const { overwriteComparisonData, overwriteRevisionData } =
330-
collectWorkspaceRaceConditionData('4fb124a', comparisonData, revisionData)
331-
332-
expect(overwriteComparisonData.workspace).toStrictEqual(
333-
comparisonData['4fb124a']
334-
)
335-
336-
expect(overwriteRevisionData.workspace).not.toStrictEqual(
337-
revisionData['4fb124a']
338-
)
339-
340-
const allWorkspaceValues = Object.values(overwriteRevisionData.workspace)
341-
const allOverwriteValues = Object.values(revisionData['4fb124a'])
342-
343-
expect(allWorkspaceValues.length).toBeTruthy()
344-
expect(allWorkspaceValues).toHaveLength(allOverwriteValues.length)
345-
346-
const allWorkspaceRevValues: string[] = []
347-
const allWorkspaceNonRevValues: Record<string, unknown>[] = []
348-
349-
for (const values of allWorkspaceValues) {
350-
for (const { rev, ...rest } of values) {
351-
allWorkspaceRevValues.push(rev as string)
352-
allWorkspaceNonRevValues.push(rest)
353-
}
354-
}
355-
356-
expect(uniqueValues(allWorkspaceRevValues)).toStrictEqual(['workspace'])
357-
expect(allWorkspaceNonRevValues).toStrictEqual(
358-
allOverwriteValues.flatMap(values =>
359-
values.map(value => omit(value, 'rev'))
360-
)
361-
)
362-
})
363-
})
364-
365269
describe('collectOverrideRevisionDetails', () => {
366270
it('should override the revision details for running checkpoint tips', () => {
367271
const runningId = 'b'

extension/src/plots/model/collect.ts

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import cloneDeep from 'lodash.clonedeep'
21
import omit from 'lodash.omit'
32
import { TopLevelSpec } from 'vega-lite'
43
import {
@@ -16,7 +15,6 @@ import {
1615
} from '../webview/contract'
1716
import {
1817
ExperimentFieldsOrError,
19-
ExperimentsBranchOutput,
2018
ExperimentsOutput,
2119
ExperimentStatus,
2220
isValueTree,
@@ -241,35 +239,6 @@ export const collectCheckpointPlotsData = (
241239
return plotsData
242240
}
243241

244-
const isRunningInWorkspace = (experiment: ExperimentFieldsOrError) =>
245-
experiment.data?.executor === 'workspace'
246-
247-
const collectRunningFromBranch = (
248-
experimentsObject: ExperimentsBranchOutput
249-
): string | undefined => {
250-
for (const [sha, experiment] of Object.entries(experimentsObject)) {
251-
if (isRunningInWorkspace(experiment)) {
252-
return shortenForLabel(sha)
253-
}
254-
}
255-
}
256-
257-
export const collectWorkspaceRunningCheckpoint = (
258-
data: ExperimentsOutput,
259-
hasCheckpoints: boolean
260-
): string | undefined => {
261-
if (!hasCheckpoints) {
262-
return
263-
}
264-
for (const experimentsObject of Object.values(omit(data, 'workspace'))) {
265-
const checkpointRunningInWorkspace =
266-
collectRunningFromBranch(experimentsObject)
267-
if (checkpointRunningInWorkspace) {
268-
return checkpointRunningInWorkspace
269-
}
270-
}
271-
}
272-
273242
type MetricOrderAccumulator = {
274243
newOrder: string[]
275244
uncollectedMetrics: string[]
@@ -437,54 +406,6 @@ export const collectData = (
437406
return acc
438407
}
439408

440-
const collectWorkspaceRevisionData = (
441-
overwriteRevisionData: RevisionPathData
442-
) => {
443-
const acc: RevisionPathData = {}
444-
445-
for (const [path, values] of Object.entries(overwriteRevisionData)) {
446-
acc[path] = []
447-
for (const value of values) {
448-
acc[path].push({ ...value, rev: 'workspace' })
449-
}
450-
}
451-
452-
return acc
453-
}
454-
455-
export const collectWorkspaceRaceConditionData = (
456-
runningSelectedCheckpoint: string | undefined,
457-
comparisonData: ComparisonData,
458-
revisionData: RevisionData
459-
): {
460-
overwriteComparisonData: ComparisonData
461-
overwriteRevisionData: RevisionData
462-
} => {
463-
if (!runningSelectedCheckpoint) {
464-
return { overwriteComparisonData: {}, overwriteRevisionData: {} }
465-
}
466-
467-
const overwriteComparisonData = cloneDeep(
468-
comparisonData[runningSelectedCheckpoint]
469-
)
470-
const overwriteRevisionData = cloneDeep(
471-
revisionData[runningSelectedCheckpoint]
472-
)
473-
474-
if (!overwriteComparisonData && !overwriteRevisionData) {
475-
return { overwriteComparisonData: {}, overwriteRevisionData: {} }
476-
}
477-
478-
const workspaceRevisionData = collectWorkspaceRevisionData(
479-
overwriteRevisionData
480-
)
481-
482-
return {
483-
overwriteComparisonData: { workspace: overwriteComparisonData },
484-
overwriteRevisionData: { workspace: workspaceRevisionData }
485-
}
486-
}
487-
488409
export type TemplateAccumulator = { [path: string]: string }
489410

490411
const collectTemplate = (

0 commit comments

Comments
 (0)