Skip to content

Commit

Permalink
Enable experiment operations when experiment(s) are running in the qu…
Browse files Browse the repository at this point in the history
…eue (#3832)

* switch from disable on running to disable on running in workspace

* fix use of context values

* how about using redux instead of prop drilling

* fix workspace method (for telemetry event)

* add running context value to prevent actions on experiments running in the queue
  • Loading branch information
mattseddon authored May 8, 2023
1 parent 59ae23d commit ea310a5
Show file tree
Hide file tree
Showing 29 changed files with 365 additions and 199 deletions.
111 changes: 58 additions & 53 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,11 @@
},
{
"command": "dvc.applyExperiment",
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running"
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running.workspace"
},
{
"command": "dvc.branchExperiment",
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running"
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running.workspace"
},
{
"command": "dvc.checkout",
Expand Down Expand Up @@ -708,7 +708,7 @@
},
{
"command": "dvc.experimentGarbageCollect",
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running"
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running.workspace"
},
{
"command": "dvc.findInFolder",
Expand Down Expand Up @@ -752,35 +752,35 @@
},
{
"command": "dvc.modifyExperimentParamsAndQueue",
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running"
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running.workspace"
},
{
"command": "dvc.modifyExperimentParamsAndRun",
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running && !dvc.experiment.checkpoints"
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running.workspace && !dvc.experiment.checkpoints"
},
{
"command": "dvc.modifyExperimentParamsAndResume",
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running && dvc.experiment.checkpoints"
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running.workspace && dvc.experiment.checkpoints"
},
{
"command": "dvc.modifyExperimentParamsResetAndRun",
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running && dvc.experiment.checkpoints"
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running.workspace && dvc.experiment.checkpoints"
},
{
"command": "dvc.pushExperiments",
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running"
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running.workspace"
},
{
"command": "dvc.queueExperiment",
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running"
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running.workspace"
},
{
"command": "dvc.removeExperiments",
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running"
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running.workspace"
},
{
"command": "dvc.removeExperimentQueue",
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running"
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running.workspace"
},
{
"command": "dvc.removeExperimentsTableFilters",
Expand Down Expand Up @@ -808,15 +808,15 @@
},
{
"command": "dvc.runExperiment",
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running && !dvc.experiment.checkpoints"
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running.workspace && !dvc.experiment.checkpoints"
},
{
"command": "dvc.resumeCheckpointExperiment",
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running && dvc.experiment.checkpoints"
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running.workspace && dvc.experiment.checkpoints"
},
{
"command": "dvc.resetAndRunCheckpointExperiment",
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running && dvc.experiment.checkpoints"
"when": "dvc.commands.available && dvc.project.available && !dvc.experiment.running.workspace && dvc.experiment.checkpoints"
},
{
"command": "dvc.startExperimentsQueue",
Expand Down Expand Up @@ -1029,59 +1029,64 @@
],
"editor/title": [
{
"command": "dvc.runExperiment",
"command": "dvc.stopAllRunningExperiments",
"group": "navigation@0",
"when": "dvc.params.file.active && !dvc.experiment.running && dvc.commands.available && !dvc.experiment.checkpoints"
"when": "dvc.params.file.active && dvc.experiment.running && dvc.commands.available"
},
{
"command": "dvc.runExperiment",
"command": "dvc.stopAllRunningExperiments",
"group": "navigation@0",
"when": "dvc.experiments.webview.active && !dvc.experiment.running && dvc.commands.available && !dvc.experiment.checkpoints"
"when": "dvc.experiments.webview.active && dvc.experiment.running && dvc.commands.available"
},
{
"command": "dvc.stopAllRunningExperiments",
"group": "navigation@0",
"when": "dvc.experiment.running && dvc.commands.available"
"command": "dvc.runExperiment",
"group": "navigation@1",
"when": "dvc.params.file.active && !dvc.experiment.running.workspace && dvc.commands.available && !dvc.experiment.checkpoints"
},
{
"command": "dvc.resetAndRunCheckpointExperiment",
"command": "dvc.runExperiment",
"group": "navigation@1",
"when": "dvc.experiments.webview.active && !dvc.experiment.running && dvc.commands.available && dvc.experiment.checkpoints"
"when": "dvc.experiments.webview.active && !dvc.experiment.running.workspace && dvc.commands.available && !dvc.experiment.checkpoints"
},
{
"command": "dvc.resetAndRunCheckpointExperiment",
"group": "navigation@1",
"when": "dvc.params.file.active && !dvc.experiment.running && dvc.commands.available && dvc.experiment.checkpoints"
"group": "navigation@2",
"when": "dvc.experiments.webview.active && !dvc.experiment.running.workspace && dvc.commands.available && dvc.experiment.checkpoints"
},
{
"command": "dvc.resumeCheckpointExperiment",
"command": "dvc.resetAndRunCheckpointExperiment",
"group": "navigation@2",
"when": "dvc.experiments.webview.active && !dvc.experiment.running && dvc.commands.available && dvc.experiment.checkpoints"
"when": "dvc.params.file.active && !dvc.experiment.running.workspace && dvc.commands.available && dvc.experiment.checkpoints"
},
{
"command": "dvc.resumeCheckpointExperiment",
"group": "navigation@2",
"when": "dvc.params.file.active && !dvc.experiment.running && dvc.commands.available && dvc.experiment.checkpoints"
"group": "navigation@3",
"when": "dvc.experiments.webview.active && !dvc.experiment.running.workspace && dvc.commands.available && dvc.experiment.checkpoints"
},
{
"command": "dvc.startExperimentsQueue",
"command": "dvc.resumeCheckpointExperiment",
"group": "navigation@3",
"when": "dvc.experiments.webview.active && !dvc.experiment.running && dvc.commands.available"
"when": "dvc.params.file.active && !dvc.experiment.running.workspace && dvc.commands.available && dvc.experiment.checkpoints"
},
{
"command": "dvc.startExperimentsQueue",
"group": "navigation@3",
"when": "dvc.params.file.active && !dvc.experiment.running && dvc.commands.available"
"group": "navigation@4",
"when": "dvc.experiments.webview.active && dvc.commands.available"
},
{
"command": "dvc.queueExperiment",
"command": "dvc.startExperimentsQueue",
"group": "navigation@4",
"when": "dvc.experiments.webview.active && !dvc.experiment.running && dvc.commands.available"
"when": "dvc.params.file.active && dvc.commands.available"
},
{
"command": "dvc.queueExperiment",
"group": "navigation@4",
"when": "dvc.params.file.active && !dvc.experiment.running && dvc.commands.available"
"group": "navigation@5",
"when": "dvc.experiments.webview.active && !dvc.experiment.running.workspace && dvc.commands.available"
},
{
"command": "dvc.queueExperiment",
"group": "navigation@5",
"when": "dvc.params.file.active && !dvc.experiment.running.workspace && dvc.commands.available"
}
],
"view/item/context": [
Expand Down Expand Up @@ -1158,42 +1163,42 @@
{
"command": "dvc.views.experiments.applyExperiment",
"group": "inline@1",
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem == experiment && !dvc.experiment.running"
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem == experiment && !dvc.experiment.running.workspace"
},
{
"command": "dvc.views.experiments.branchExperiment",
"group": "inline@2",
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem == experiment && !dvc.experiment.running"
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem == experiment && !dvc.experiment.running.workspace"
},
{
"command": "dvc.views.experimentsTree.removeExperiment",
"group": "inline@3",
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem =~ /^(experiment|queued)$/ && !dvc.experiment.running"
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem =~ /^(experiment|queued)$/ && !dvc.experiment.running.workspace"
},
{
"command": "dvc.views.experimentsTree.pushExperiment",
"group": "1_share@0",
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem == experiment && !dvc.experiment.running"
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem == experiment && !dvc.experiment.running.workspace"
},
{
"command": "dvc.views.experiments.runExperiment",
"group": "2_modify@1",
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem =~ /^(workspace|commit|experiment|queued)$/ && !dvc.experiment.running && !dvc.experiment.checkpoints"
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem =~ /^(workspace|commit|experiment|queued)$/ && !dvc.experiment.running.workspace && !dvc.experiment.checkpoints"
},
{
"command": "dvc.views.experiments.resetAndRunCheckpointExperiment",
"group": "2_modify@1",
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem =~ /^(workspace|commit|experiment|queued)$/ && !dvc.experiment.running && dvc.experiment.checkpoints"
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem =~ /^(workspace|commit|experiment|queued)$/ && !dvc.experiment.running.workspace && dvc.experiment.checkpoints"
},
{
"command": "dvc.views.experiments.resumeCheckpointExperiment",
"group": "2_modify@2",
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem =~ /^(workspace|commit|experiment|queued)$/ && !dvc.experiment.running && dvc.experiment.checkpoints"
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem =~ /^(workspace|commit|experiment|queued)$/ && !dvc.experiment.running.workspace && dvc.experiment.checkpoints"
},
{
"command": "dvc.views.experiments.queueExperiment",
"group": "2_modify@3",
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem =~ /^(workspace|commit|experiment|queued)$/ && !dvc.experiment.running"
"when": "view == dvc.views.experimentsTree && dvc.commands.available && viewItem =~ /^(workspace|commit|experiment|queued)$/ && !dvc.experiment.running.workspace"
}
],
"view/title": [
Expand All @@ -1214,17 +1219,17 @@
},
{
"command": "dvc.runExperiment",
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running && !dvc.experiment.checkpoints",
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running.workspace && !dvc.experiment.checkpoints",
"group": "navigation@1"
},
{
"command": "dvc.resetAndRunCheckpointExperiment",
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running && dvc.experiment.checkpoints",
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running.workspace && dvc.experiment.checkpoints",
"group": "navigation@1"
},
{
"command": "dvc.resumeCheckpointExperiment",
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running && dvc.experiment.checkpoints",
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running.workspace && dvc.experiment.checkpoints",
"group": "navigation@2"
},
{
Expand All @@ -1249,27 +1254,27 @@
},
{
"command": "dvc.modifyExperimentParamsAndRun",
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running && !dvc.experiment.checkpoints",
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running.workspace && !dvc.experiment.checkpoints",
"group": "2_modify@1"
},
{
"command": "dvc.modifyExperimentParamsAndResume",
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running && dvc.experiment.checkpoints",
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running.workspace && dvc.experiment.checkpoints",
"group": "2_modify@1"
},
{
"command": "dvc.modifyExperimentParamsResetAndRun",
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running && dvc.experiment.checkpoints",
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running.workspace && dvc.experiment.checkpoints",
"group": "2_modify@2"
},
{
"command": "dvc.modifyExperimentParamsAndQueue",
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running",
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running.workspace",
"group": "2_modify@3"
},
{
"command": "dvc.queueExperiment",
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running",
"when": "view == dvc.views.experimentsTree && !dvc.experiment.running.workspace",
"group": "3_queue@1"
},
{
Expand Down
16 changes: 14 additions & 2 deletions extension/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,22 @@ export class Context extends Disposable {
}

private setIsExperimentRunning(repositories: Experiments[] = []) {
const workspaceRunningInRunner = this.dvcRunner.isExperimentRunning()

const getContextValue = (
method: 'hasRunningWorkspaceExperiment' | 'hasRunningExperiment'
): boolean =>
workspaceRunningInRunner ||
repositories.some(experiments => experiments[method]())

void setContextValue(
ContextKey.EXPERIMENT_RUNNING_WORKSPACE,
getContextValue('hasRunningWorkspaceExperiment')
)

void setContextValue(
ContextKey.EXPERIMENT_RUNNING,
this.dvcRunner.isExperimentRunning() ||
repositories.some(experiments => experiments.hasRunningExperiment())
getContextValue('hasRunningExperiment')
)
}
}
6 changes: 5 additions & 1 deletion extension/src/experiments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,10 @@ export class Experiments extends BaseRepository<TableData> {
return this.experiments.hasRunningExperiment()
}

public hasRunningWorkspaceExperiment() {
return this.experiments.hasRunningWorkspaceExperiment()
}

public getFirstThreeColumnOrder() {
return this.columns.getFirstThreeColumnOrder()
}
Expand Down Expand Up @@ -617,7 +621,7 @@ export class Experiments extends BaseRepository<TableData> {
this.dvcLiveOnlyCleanupInitialized = true
void pollSignalFileForProcess(this.dvcLiveOnlySignalFile, () => {
this.dvcLiveOnlyCleanupInitialized = false
if (this.hasRunningExperiment()) {
if (this.hasRunningWorkspaceExperiment()) {
void this.data.update()
}
})
Expand Down
27 changes: 21 additions & 6 deletions extension/src/experiments/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import { definedAndNonEmpty, reorderListSubset } from '../../util/array'
import {
EXPERIMENT_WORKSPACE_ID,
Executor,
ExpShowOutput
ExpShowOutput,
ExperimentStatus
} from '../../cli/dvc/contract'
import { flattenMapValues } from '../../util/map'
import { ModelWithPersistence } from '../../persistence/model'
Expand All @@ -39,10 +40,11 @@ export type SelectedExperimentWithColor = Experiment & {
}

export enum ExperimentType {
WORKSPACE = 'workspace',
COMMIT = 'commit',
EXPERIMENT = 'experiment',
QUEUED = 'queued'
RUNNING = 'running',
QUEUED = 'queued',
WORKSPACE = 'workspace'
}

export class ExperimentsModel extends ModelWithPersistence {
Expand Down Expand Up @@ -166,6 +168,10 @@ export class ExperimentsModel extends ModelWithPersistence {
return this.running.length > 0
}

public hasRunningWorkspaceExperiment() {
return this.running.some(({ executor }) => executor === Executor.WORKSPACE)
}

public hasCheckpoints() {
return this.checkpoints
}
Expand Down Expand Up @@ -372,9 +378,7 @@ export class ExperimentsModel extends ModelWithPersistence {
return this.getExperimentsByCommit(commit)?.map(experiment => ({
...experiment,
hasChildren: false,
type: isQueued(experiment.status)
? ExperimentType.QUEUED
: ExperimentType.EXPERIMENT
type: this.getExperimentType(experiment.status)
}))
}

Expand Down Expand Up @@ -556,6 +560,17 @@ export class ExperimentsModel extends ModelWithPersistence {
}
}

private getExperimentType(status?: ExperimentStatus) {
if (isQueued(status)) {
return ExperimentType.QUEUED
}
if (isRunning(status)) {
return ExperimentType.RUNNING
}

return ExperimentType.EXPERIMENT
}

private getDisplayColor(id: string) {
const color = this.coloredStatus[id]
if (!color) {
Expand Down
Loading

0 comments on commit ea310a5

Please sign in to comment.