Skip to content

Commit

Permalink
Rename experiment status to executor status
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Jul 27, 2023
1 parent c0f3902 commit 8268783
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 111 deletions.
4 changes: 2 additions & 2 deletions extension/src/cli/dvc/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const isValueTree = (
): value is NonNullable<ValueTree> =>
!!(value && !Array.isArray(value) && typeof value === 'object')

export enum ExperimentStatus {
export enum ExecutorStatus {
FAILED = 'failed',
QUEUED = 'queued',
RUNNING = 'running',
Expand Down Expand Up @@ -81,7 +81,7 @@ export enum Executor {
}

export type ExecutorState = {
state: ExperimentStatus
state: ExecutorStatus
name: Executor | null
local: {
root: string | null
Expand Down
14 changes: 7 additions & 7 deletions extension/src/experiments/model/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '../webview/contract'
import {
EXPERIMENT_WORKSPACE_ID,
ExperimentStatus,
ExecutorStatus,
ExpShowOutput,
ExpState,
Executor,
Expand Down Expand Up @@ -229,19 +229,19 @@ const collectExecutorInfo = (

const { name, state } = executor

if (name && state === ExperimentStatus.RUNNING) {
if (name && state === ExecutorStatus.RUNNING) {
experiment.executor = name
}
if (state && state !== ExperimentStatus.SUCCESS) {
experiment.status = state
if (state && state !== ExecutorStatus.SUCCESS) {
experiment.executorStatus = state
}
}

const collectRunningExperiment = (
acc: ExperimentsAccumulator,
experiment: Experiment
): void => {
if (!isRunning(experiment.status)) {
if (!isRunning(experiment.executorStatus)) {
return
}
acc.runningExperiments.push({
Expand Down Expand Up @@ -310,7 +310,7 @@ const setWorkspaceAsRunning = (
)
) {
acc.workspace.executor = Executor.WORKSPACE
acc.workspace.status = ExperimentStatus.RUNNING
acc.workspace.executorStatus = ExecutorStatus.RUNNING
}

if (dvcLiveOnly) {
Expand Down Expand Up @@ -435,7 +435,7 @@ const collectExperimentsAndCommit = (
): void => {
acc.push(commit)
for (const experiment of experiments) {
if (isQueued(experiment.status)) {
if (isQueued(experiment.executorStatus)) {
continue
}
acc.push(experiment)
Expand Down
10 changes: 6 additions & 4 deletions extension/src/experiments/model/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import dataTypesOutputFixture from '../../test/fixtures/expShow/dataTypes/output
import survivalOutputFixture from '../../test/fixtures/expShow/survival/output'
import survivalRowsFixture from '../../test/fixtures/expShow/survival/rows'
import {
ExperimentStatus,
ExecutorStatus,
EXPERIMENT_WORKSPACE_ID,
Executor,
ExpWithError,
Expand Down Expand Up @@ -111,7 +111,9 @@ describe('ExperimentsModel', () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const runningWorkspace = (model as any).workspace
expect(runningWorkspace?.executor).toStrictEqual(EXPERIMENT_WORKSPACE_ID)
expect(runningWorkspace?.status).toStrictEqual(ExperimentStatus.RUNNING)
expect(runningWorkspace?.executorStatus).toStrictEqual(
ExecutorStatus.RUNNING
)

model.transformAndSetLocal(dvcLiveOnly, ...DEFAULT_DATA)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -292,7 +294,7 @@ describe('ExperimentsModel', () => {
executor: {
local: null,
name: Executor.WORKSPACE,
state: ExperimentStatus.RUNNING
state: ExecutorStatus.RUNNING
},
name: runningExpName,
rev: EXPERIMENT_WORKSPACE_ID
Expand All @@ -305,7 +307,7 @@ describe('ExperimentsModel', () => {
executor: {
local: null,
name: Executor.DVC_TASK,
state: ExperimentStatus.RUNNING
state: ExecutorStatus.RUNNING
},
name: runningTaskName,
rev: EXPERIMENT_WORKSPACE_ID
Expand Down
24 changes: 10 additions & 14 deletions extension/src/experiments/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ import {
WORKSPACE_BRANCH
} from '../webview/contract'
import { reorderListSubset } from '../../util/array'
import {
Executor,
ExpShowOutput,
ExperimentStatus
} from '../../cli/dvc/contract'
import { Executor, ExpShowOutput, ExecutorStatus } from '../../cli/dvc/contract'
import { flattenMapValues } from '../../util/map'
import { ModelWithPersistence } from '../../persistence/model'
import { PersistenceKey } from '../../persistence/constants'
Expand Down Expand Up @@ -184,7 +180,7 @@ export class ExperimentsModel extends ModelWithPersistence {
({ id: expId }) => expId === id
)

if (isQueued(experiment?.status)) {
if (isQueued(experiment?.executorStatus)) {
return UNSELECTED
}

Expand Down Expand Up @@ -378,8 +374,8 @@ export class ExperimentsModel extends ModelWithPersistence {
}

public getExperiments() {
return this.getExperimentsAndQueued().filter(({ status }) => {
return !isQueued(status)
return this.getExperimentsAndQueued().filter(({ executorStatus }) => {
return !isQueued(executorStatus)
})
}

Expand All @@ -397,7 +393,7 @@ export class ExperimentsModel extends ModelWithPersistence {

public getRunningExperiments() {
return this.getExperimentsAndQueued().filter(experiment =>
isRunning(experiment.status)
isRunning(experiment.executorStatus)
)
}

Expand Down Expand Up @@ -471,7 +467,7 @@ export class ExperimentsModel extends ModelWithPersistence {
return this.getExperimentsByCommit(commit)?.map(experiment => ({
...experiment,
hasChildren: false,
type: this.getExperimentType(experiment.status)
type: this.getExperimentType(experiment.executorStatus)
}))
}

Expand Down Expand Up @@ -569,7 +565,7 @@ export class ExperimentsModel extends ModelWithPersistence {
if (
this.remoteExpShas === undefined ||
!experiment.sha ||
![undefined, ExperimentStatus.SUCCESS].includes(experiment.status)
![undefined, ExecutorStatus.SUCCESS].includes(experiment.executorStatus)
) {
return
}
Expand Down Expand Up @@ -670,11 +666,11 @@ export class ExperimentsModel extends ModelWithPersistence {
}
}

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

Expand Down
8 changes: 4 additions & 4 deletions extension/src/experiments/model/status/collect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { collectColoredStatus } from './collect'
import { copyOriginalColors } from './colors'
import { Experiment } from '../../webview/contract'
import {
ExperimentStatus,
ExecutorStatus,
EXPERIMENT_WORKSPACE_ID
} from '../../../cli/dvc/contract'

Expand Down Expand Up @@ -39,7 +39,7 @@ describe('collectColoredStatus', () => {
it('should not push queued experiments into the returned object', () => {
const experiments = [
{ id: 'exp1' },
{ id: 'exp2', status: ExperimentStatus.QUEUED }
{ executorStatus: ExecutorStatus.QUEUED, id: 'exp2' }
] as Experiment[]
const colors = copyOriginalColors()

Expand Down Expand Up @@ -214,8 +214,8 @@ describe('collectColoredStatus', () => {
[
{
executor: null,
id: 'exp-1',
status: ExperimentStatus.SUCCESS
executorStatus: ExecutorStatus.SUCCESS,
id: 'exp-1'
},
{
id: EXPERIMENT_WORKSPACE_ID
Expand Down
8 changes: 5 additions & 3 deletions extension/src/experiments/model/status/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const canAssign = (
): boolean => canSelect(coloredStatus) && definedAndNonEmpty(unassignedColors)

const collectStatus = (acc: ColoredStatus, experiment: Experiment): void => {
const { id, status } = experiment
const { id, executorStatus: status } = experiment
if (!id || isQueued(status) || hasKey(acc, id)) {
return
}
Expand Down Expand Up @@ -164,8 +164,10 @@ const assignSelected = (
return { availableColors, coloredStatus }
}

const cannotSelect = (ids: Set<string>, { id, status }: Experiment): boolean =>
isQueued(status) || ids.has(id)
const cannotSelect = (
ids: Set<string>,
{ id, executorStatus: status }: Experiment
): boolean => isQueued(status) || ids.has(id)

export const collectSelectable = (
selectedExperiments: Experiment[]
Expand Down
6 changes: 3 additions & 3 deletions extension/src/experiments/model/status/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { canSelect, limitToMaxSelected } from '.'
import { copyOriginalColors } from './colors'
import { Experiment } from '../../webview/contract'
import { ExperimentStatus } from '../../../cli/dvc/contract'
import { ExecutorStatus } from '../../../cli/dvc/contract'

describe('canSelect', () => {
const colors = copyOriginalColors()
Expand Down Expand Up @@ -51,9 +51,9 @@ describe('limitToMaxSelected', () => {
...mockedExperiments,
{
branch: 'main',
executorStatus: ExecutorStatus.RUNNING,
id: '1',
label: 'R',
status: ExperimentStatus.RUNNING
label: 'R'
}
])
.map(({ label }) => label)
Expand Down
4 changes: 2 additions & 2 deletions extension/src/experiments/model/status/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const compareTimestamps = (a: Experiment, b: Experiment) =>
export const limitToMaxSelected = (experiments: Experiment[]) =>
[...experiments]
.sort((a, b) => {
if (a.status === b.status) {
if (a.executorStatus === b.executorStatus) {
return compareTimestamps(a, b)
}
return isRunning(a.status) ? -1 : 1
return isRunning(a.executorStatus) ? -1 : 1
})
.slice(0, MAX_SELECTED_EXPERIMENTS)
22 changes: 11 additions & 11 deletions extension/src/experiments/webview/contract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Executor, ExperimentStatus, ValueTree } from '../../cli/dvc/contract'
import { Executor, ExecutorStatus, ValueTree } from '../../cli/dvc/contract'
import { SortDefinition } from '../model/sortBy'

export { ExperimentStatus } from '../../cli/dvc/contract'
export { ExecutorStatus } from '../../cli/dvc/contract'

export interface MetricOrParamColumns {
[filename: string]: ValueTree
Expand Down Expand Up @@ -51,24 +50,25 @@ export type Experiment = {
selected?: boolean
sha?: string
starred?: boolean
status?: ExperimentStatus
executorStatus?: ExecutorStatus
timestamp?: string | null
branch?: string | typeof WORKSPACE_BRANCH
}

export const isRunning = (status: ExperimentStatus | undefined): boolean =>
status === ExperimentStatus.RUNNING
export const isRunning = (
executorStatus: ExecutorStatus | undefined
): boolean => executorStatus === ExecutorStatus.RUNNING

export const isQueued = (status: ExperimentStatus | undefined): boolean =>
status === ExperimentStatus.QUEUED
export const isQueued = (executorStatus: ExecutorStatus | undefined): boolean =>
executorStatus === ExecutorStatus.QUEUED

export const isRunningInQueue = ({
status,
executorStatus,
executor
}: {
status?: ExperimentStatus
executorStatus?: ExecutorStatus
executor?: string | null
}): boolean => isRunning(status) && executor === Executor.DVC_TASK
}): boolean => isRunning(executorStatus) && executor === Executor.DVC_TASK

export interface Commit extends Experiment {
subRows?: Experiment[]
Expand Down
12 changes: 6 additions & 6 deletions extension/src/test/fixtures/expShow/base/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { join } from '../../../util/path'
import {
EXPERIMENT_WORKSPACE_ID,
Executor,
ExperimentStatus,
ExecutorStatus,
ExpShowOutput
} from '../../../../cli/dvc/contract'

Expand Down Expand Up @@ -345,7 +345,7 @@ const data: ExpShowOutput = [
],
executor: {
name: Executor.DVC_TASK,
state: ExperimentStatus.RUNNING,
state: ExecutorStatus.RUNNING,
local: null
}
},
Expand Down Expand Up @@ -580,7 +580,7 @@ const data: ExpShowOutput = [
executor: {
name: Executor.WORKSPACE,
local: { pid: 1234, root: null, log: null, returncode: null },
state: ExperimentStatus.RUNNING
state: ExecutorStatus.RUNNING
}
},
{
Expand All @@ -593,7 +593,7 @@ const data: ExpShowOutput = [
}
}
],
executor: { state: ExperimentStatus.FAILED, local: null, name: null }
executor: { state: ExecutorStatus.FAILED, local: null, name: null }
},
{
name: 'exp-f13bca',
Expand Down Expand Up @@ -811,7 +811,7 @@ const data: ExpShowOutput = [
}
],
executor: {
state: ExperimentStatus.QUEUED,
state: ExecutorStatus.QUEUED,
name: Executor.DVC_TASK,
local: {
root: null,
Expand Down Expand Up @@ -902,7 +902,7 @@ const data: ExpShowOutput = [
}
}
],
executor: { state: ExperimentStatus.FAILED, local: null, name: null }
executor: { state: ExecutorStatus.FAILED, local: null, name: null }
}
]
},
Expand Down
Loading

0 comments on commit 8268783

Please sign in to comment.