Skip to content

Commit 7f23202

Browse files
authored
Use DVCLive signal file to indicate that an experiment is running in the workspace (#2923)
* create signal file prototype * rework use of signal file based on current implementation * do not unnecessarily read file system in integration tests
1 parent 9fd5305 commit 7f23202

File tree

19 files changed

+374
-117
lines changed

19 files changed

+374
-117
lines changed

extension/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,7 @@
16141614
"lint-staged": "13.1.0",
16151615
"mocha": "10.0.0",
16161616
"mock-require": "3.0.3",
1617+
"process-exists": "4.1.0",
16171618
"shx": "0.3.4",
16181619
"sinon": "15.0.0",
16191620
"sinon-chai": "3.7.0",

extension/src/cli/dvc/constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ export const MAX_CLI_VERSION = '3'
77
export const UNEXPECTED_ERROR_CODE = 255
88

99
export const TEMP_PLOTS_DIR = join('.dvc', 'tmp', 'plots')
10+
export const DVCLIVE_ONLY_RUNNING_SIGNAL_FILE = join(
11+
'.dvc',
12+
'tmp',
13+
'exps',
14+
'run',
15+
'DVCLIVE_ONLY'
16+
)
17+
1018
export const NUM_OF_COMMITS_TO_SHOW = '3'
1119

1220
export enum Command {

extension/src/experiments/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { join } from 'path'
12
import {
23
ConfigurationChangeEvent,
34
Event,
@@ -40,6 +41,8 @@ import { createTypedAccumulator } from '../util/object'
4041
import { pickPaths } from '../path/selection/quickPick'
4142
import { Toast } from '../vscode/toast'
4243
import { ConfigKey } from '../vscode/config'
44+
import { checkSignalFile } from '../fileSystem'
45+
import { DVCLIVE_ONLY_RUNNING_SIGNAL_FILE } from '../cli/dvc/constants'
4346

4447
export const ExperimentsScale = {
4548
...omit(ColumnType, 'TIMESTAMP'),
@@ -165,9 +168,12 @@ export class Experiments extends BaseRepository<TableData> {
165168
}
166169

167170
public async setState(data: ExperimentsOutput) {
171+
const dvcLiveOnly = await checkSignalFile(
172+
join(this.dvcRoot, DVCLIVE_ONLY_RUNNING_SIGNAL_FILE)
173+
)
168174
await Promise.all([
169175
this.columns.transformAndSet(data),
170-
this.experiments.transformAndSet(data)
176+
this.experiments.transformAndSet(data, dvcLiveOnly)
171177
])
172178

173179
return this.notifyChanged(data)

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ import {
88

99
describe('collectExperiments', () => {
1010
it('should return an empty array if no branches are present', () => {
11-
const { branches } = collectExperiments({
12-
[EXPERIMENT_WORKSPACE_ID]: {
13-
baseline: {}
14-
}
15-
})
11+
const { branches } = collectExperiments(
12+
{
13+
[EXPERIMENT_WORKSPACE_ID]: {
14+
baseline: {}
15+
}
16+
},
17+
false
18+
)
1619
expect(branches).toStrictEqual([])
1720
})
1821

@@ -34,8 +37,10 @@ describe('collectExperiments', () => {
3437
baseline: { data: { name: 'branchB' } }
3538
}
3639
}
37-
const { branches, experimentsByBranch, workspace } =
38-
collectExperiments(repoWithTwoBranches)
40+
const { branches, experimentsByBranch, workspace } = collectExperiments(
41+
repoWithTwoBranches,
42+
false
43+
)
3944

4045
it('should define a workspace', () => {
4146
expect(workspace).toBeDefined()
@@ -77,7 +82,7 @@ describe('collectExperiments', () => {
7782
}
7883
}
7984
}
80-
const acc = collectExperiments(repoWithNestedCheckpoints)
85+
const acc = collectExperiments(repoWithNestedCheckpoints, false)
8186

8287
it('should only list the tip as a top-level experiment', () => {
8388
const { experimentsByBranch } = acc
@@ -98,7 +103,7 @@ describe('collectExperiments', () => {
98103
})
99104

100105
it('should handle the continuation of a modified checkpoint', () => {
101-
const { checkpointsByTip } = collectExperiments(modifiedFixture)
106+
const { checkpointsByTip } = collectExperiments(modifiedFixture, false)
102107

103108
const modifiedCheckpointTip = checkpointsByTip
104109
.get('exp-01b3a')
@@ -154,7 +159,7 @@ describe('collectExperiments', () => {
154159
}
155160
}
156161
}
157-
const acc = collectExperiments(repoWithNestedCheckpoints)
162+
const acc = collectExperiments(repoWithNestedCheckpoints, false)
158163

159164
const { experimentsByBranch, checkpointsByTip } = acc
160165
const [experiment] = experimentsByBranch.get('branchA') || []

extension/src/experiments/model/collect.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
ExperimentFields,
1515
ExperimentsBranchOutput,
1616
ExperimentsOutput,
17-
EXPERIMENT_WORKSPACE_ID
17+
EXPERIMENT_WORKSPACE_ID,
18+
ExperimentStatus
1819
} from '../../cli/dvc/contract'
1920
import { addToMapArray } from '../../util/map'
2021
import { uniqueValues } from '../../util/array'
@@ -311,17 +312,22 @@ const collectFromBranchesObject = (
311312
}
312313

313314
export const collectExperiments = (
314-
data: ExperimentsOutput
315+
data: ExperimentsOutput,
316+
dvcLiveOnly: boolean
315317
): ExperimentsAccumulator => {
316318
const { workspace, ...branchesObject } = data
317-
const workspaceId = EXPERIMENT_WORKSPACE_ID
318319

319320
const workspaceBaseline = transformExperimentData(
320-
workspaceId,
321+
EXPERIMENT_WORKSPACE_ID,
321322
workspace.baseline,
322-
workspaceId
323+
EXPERIMENT_WORKSPACE_ID
323324
)
324325

326+
if (dvcLiveOnly) {
327+
workspaceBaseline.executor = EXPERIMENT_WORKSPACE_ID
328+
workspaceBaseline.status = ExperimentStatus.RUNNING
329+
}
330+
325331
const acc = new ExperimentsAccumulator(workspaceBaseline)
326332

327333
collectFromBranchesObject(acc, branchesObject)

0 commit comments

Comments
 (0)