Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add all experiments to runs view #673

Merged
merged 6 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions extension/src/experiments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ export class Experiments {
return this.getRepository(dvcRoot).getFilter(id)
}

public getRunningOrQueued(dvcRoot: string): string[] {
return this.getRepository(dvcRoot).getRunningOrQueued()
public getExperimentNames(dvcRoot: string): string[] {
return this.getRepository(dvcRoot).getExperimentNames()
}

public getExperiment(dvcRoot: string, name: string) {
Expand Down
9 changes: 5 additions & 4 deletions extension/src/experiments/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ export class ExperimentsModel {
return this.columnStatus[path]
}

public getRunningOrQueued(): string[] {
return [this.workspace, ...this.getExperiments()]
.filter(experiment => experiment?.queued || experiment?.running)
.map(experiment => experiment.displayName)
public getExperimentNames(): string[] {
const workspace = this.workspace.running ? [this.workspace] : []
return [...workspace, ...this.getExperiments()].map(
experiment => experiment?.displayName
)
}

public getExperiment(name: string) {
Expand Down
4 changes: 2 additions & 2 deletions extension/src/experiments/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ export class ExperimentsRepository {
}
}

public getRunningOrQueued(): string[] {
return this.model.getRunningOrQueued()
public getExperimentNames(): string[] {
return this.model.getExperimentNames()
}

public getExperiment(name: string) {
Expand Down
61 changes: 44 additions & 17 deletions extension/src/experiments/views/runsTree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const mockedDisposable = mocked(Disposable)
const mockedGetDvcRoots = jest.fn()
const mockedGetExperiment = jest.fn()
const mockedGetCheckpointNames = jest.fn()
const mockedGetRunningOrQueued = jest.fn()
const mockedGetExperimentNames = jest.fn()
const mockedExperiments = {
experimentsRowsChanged: mockedExperimentsRowsChanged,
getCheckpointNames: mockedGetCheckpointNames,
getDvcRoots: mockedGetDvcRoots,
getExperiment: mockedGetExperiment,
getRunningOrQueued: mockedGetRunningOrQueued,
getExperimentNames: mockedGetExperimentNames,
isReady: () => true
} as unknown as Experiments

Expand All @@ -48,7 +48,7 @@ describe('ExperimentsRunsTree', () => {
it('should return an empty array when no experiments are queued for any of the repositories', async () => {
const experimentsRunsTree = new ExperimentsRunsTree(mockedExperiments)
mockedGetDvcRoots.mockReturnValueOnce(['demo'])
mockedGetRunningOrQueued.mockReturnValueOnce([])
mockedGetExperimentNames.mockReturnValueOnce([])

const rootElements = await experimentsRunsTree.getChildren()

Expand All @@ -59,9 +59,9 @@ describe('ExperimentsRunsTree', () => {
const dvcRoots = ['demo', 'and/mock', 'other/repo']
const experimentsRunsTree = new ExperimentsRunsTree(mockedExperiments)
mockedGetDvcRoots.mockReturnValueOnce(dvcRoots)
mockedGetRunningOrQueued.mockReturnValueOnce([])
mockedGetRunningOrQueued.mockReturnValueOnce([])
mockedGetRunningOrQueued.mockReturnValueOnce(['90aea7f'])
mockedGetExperimentNames.mockReturnValueOnce([])
mockedGetExperimentNames.mockReturnValueOnce([])
mockedGetExperimentNames.mockReturnValueOnce(['90aea7f'])

const rootElements = await experimentsRunsTree.getChildren()

Expand All @@ -71,8 +71,8 @@ describe('ExperimentsRunsTree', () => {
it('should return an array of queued experiment names when an element is provided', async () => {
const queuedExperiments = ['90aea7f', 'f0778b3', 'f81f1b5']
const experimentsRunsTree = new ExperimentsRunsTree(mockedExperiments)
mockedGetRunningOrQueued.mockReturnValueOnce(queuedExperiments)
mockedGetRunningOrQueued.mockReturnValueOnce(queuedExperiments)
mockedGetExperimentNames.mockReturnValueOnce(queuedExperiments)
mockedGetExperimentNames.mockReturnValueOnce(queuedExperiments)

mockedGetDvcRoots.mockReturnValueOnce(['repo'])
await experimentsRunsTree.getChildren()
Expand All @@ -90,8 +90,8 @@ describe('ExperimentsRunsTree', () => {
'15c9c56'
]
const experimentsRunsTree = new ExperimentsRunsTree(mockedExperiments)
mockedGetRunningOrQueued.mockReturnValueOnce(runningOrQueuedExperiments)
mockedGetRunningOrQueued.mockReturnValueOnce(runningOrQueuedExperiments)
mockedGetExperimentNames.mockReturnValueOnce(runningOrQueuedExperiments)
mockedGetExperimentNames.mockReturnValueOnce(runningOrQueuedExperiments)

mockedGetDvcRoots.mockReturnValueOnce(['repo'])
await experimentsRunsTree.getChildren()
Expand All @@ -117,7 +117,7 @@ describe('ExperimentsRunsTree', () => {

const experimentsRunsTree = new ExperimentsRunsTree(mockedExperiments)
mockedGetDvcRoots.mockReturnValueOnce(['demo'])
mockedGetRunningOrQueued.mockReturnValueOnce([])
mockedGetExperimentNames.mockReturnValueOnce([])

await experimentsRunsTree.getChildren()

Expand All @@ -139,8 +139,8 @@ describe('ExperimentsRunsTree', () => {
const experimentsRunsTree = new ExperimentsRunsTree(mockedExperiments)
mockedGetDvcRoots.mockReturnValueOnce(['demo'])
const mockedQueuedExperiment = 'f0778b3'
mockedGetRunningOrQueued.mockReturnValueOnce([mockedQueuedExperiment])
mockedGetRunningOrQueued.mockReturnValueOnce([mockedQueuedExperiment])
mockedGetExperimentNames.mockReturnValueOnce([mockedQueuedExperiment])
mockedGetExperimentNames.mockReturnValueOnce([mockedQueuedExperiment])
mockedGetExperiment.mockReturnValueOnce({
queued: true,
running: false
Expand Down Expand Up @@ -168,8 +168,8 @@ describe('ExperimentsRunsTree', () => {
const experimentsRunsTree = new ExperimentsRunsTree(mockedExperiments)
mockedGetDvcRoots.mockReturnValueOnce(['demo'])
const mockedRunningExperiment = 'workspace'
mockedGetRunningOrQueued.mockReturnValueOnce([mockedRunningExperiment])
mockedGetRunningOrQueued.mockReturnValueOnce([mockedRunningExperiment])
mockedGetExperimentNames.mockReturnValueOnce([mockedRunningExperiment])
mockedGetExperimentNames.mockReturnValueOnce([mockedRunningExperiment])

await experimentsRunsTree.getChildren()
await experimentsRunsTree.getChildren('demo')
Expand All @@ -195,8 +195,8 @@ describe('ExperimentsRunsTree', () => {
const experimentsRunsTree = new ExperimentsRunsTree(mockedExperiments)
mockedGetDvcRoots.mockReturnValueOnce(['demo'])
const mockedRunningExperiment = 'f0778b3'
mockedGetRunningOrQueued.mockReturnValueOnce([mockedRunningExperiment])
mockedGetRunningOrQueued.mockReturnValueOnce([mockedRunningExperiment])
mockedGetExperimentNames.mockReturnValueOnce([mockedRunningExperiment])
mockedGetExperimentNames.mockReturnValueOnce([mockedRunningExperiment])
mockedGetExperiment.mockReturnValueOnce({
hasChildren: true,
running: true
Expand Down Expand Up @@ -226,6 +226,33 @@ describe('ExperimentsRunsTree', () => {
const experimentsRunsTree = new ExperimentsRunsTree(mockedExperiments)

const treeItem = experimentsRunsTree.getTreeItem('f0778b3')
expect(treeItem).toEqual({
...mockedItem,
iconPath: { id: 'debug-stackframe-dot' }
})
})

it('should return a tree item for an existing experiment', async () => {
let mockedItem = {}
mockedTreeItem.mockImplementationOnce(function (uri, collapsibleState) {
mockedItem = { collapsibleState, uri }
return mockedItem
})
mockedThemeIcon.mockImplementationOnce(function (id) {
return { id }
})

const experimentsRunsTree = new ExperimentsRunsTree(mockedExperiments)
mockedGetDvcRoots.mockReturnValueOnce(['demo'])
const mockedExistingExperiment = 'f0998a3'
mockedGetExperimentNames.mockReturnValueOnce([mockedExistingExperiment])
mockedGetExperimentNames.mockReturnValueOnce([mockedExistingExperiment])
mockedGetExperiment.mockReturnValueOnce({})

await experimentsRunsTree.getChildren()
await experimentsRunsTree.getChildren('demo')

const treeItem = experimentsRunsTree.getTreeItem(mockedExistingExperiment)
expect(treeItem).toEqual({
...mockedItem,
iconPath: { id: 'primitive-dot' }
Expand Down
26 changes: 20 additions & 6 deletions extension/src/experiments/views/runsTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export class ExperimentsRunsTree implements TreeDataProvider<string> {
return this.getRunning(element, experiment?.hasChildren)
}

return this.getQueued(element)
if (experiment?.queued) {
return this.getQueued(element)
}

return this.getExistingExperiment(element, experiment?.hasChildren)
mattseddon marked this conversation as resolved.
Show resolved Hide resolved
}

public getChildren(element?: string): Promise<string[]> {
Expand All @@ -58,7 +62,7 @@ export class ExperimentsRunsTree implements TreeDataProvider<string> {
}

if (this.isRoot(element)) {
return Promise.resolve(this.getRunningOrQueued(element))
return Promise.resolve(this.getExperimentNames(element))
}

return Promise.resolve(
Expand All @@ -70,7 +74,7 @@ export class ExperimentsRunsTree implements TreeDataProvider<string> {
return this.getTreeItemWithIcon(
element,
TreeItemCollapsibleState.None,
'primitive-dot'
'debug-stackframe-dot'
)
}

Expand All @@ -90,6 +94,16 @@ export class ExperimentsRunsTree implements TreeDataProvider<string> {
)
}

private getExistingExperiment(element: string, hasChildren?: boolean) {
return this.getTreeItemWithIcon(
element,
hasChildren
? TreeItemCollapsibleState.Collapsed
: TreeItemCollapsibleState.None,
'primitive-dot'
)
}

private getTreeItemWithIcon(
element: string,
collapsibleState: TreeItemCollapsibleState,
Expand All @@ -106,7 +120,7 @@ export class ExperimentsRunsTree implements TreeDataProvider<string> {
const runningOrQueued = flatten(
dvcRoots.map(dvcRoot => {
this.runRoots[dvcRoot] = dvcRoot
return this.experiments.getRunningOrQueued(dvcRoot)
return this.experiments.getExperimentNames(dvcRoot)
})
)
if (definedAndNonEmpty(runningOrQueued)) {
Expand All @@ -116,8 +130,8 @@ export class ExperimentsRunsTree implements TreeDataProvider<string> {
return []
}

private getRunningOrQueued(dvcRoot: string): string[] {
const runningOrQueued = this.experiments.getRunningOrQueued(dvcRoot)
private getExperimentNames(dvcRoot: string): string[] {
const runningOrQueued = this.experiments.getExperimentNames(dvcRoot)
runningOrQueued.forEach(name => (this.runRoots[name] = dvcRoot))
return runningOrQueued
}
Expand Down
9 changes: 6 additions & 3 deletions extension/src/test/suite/experiments/repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ suite('Experiments Repository Test Suite', () => {
})
})

describe('getRunningOrQueued', () => {
it('should return the currently running or queued experiments', async () => {
describe('getExperimentNames', () => {
it("should return all existing experiments' names", async () => {
const config = disposable.track(new Config())
const cliReader = disposable.track(new CliReader(config))
stub(cliReader, 'experimentShow').resolves(complexExperimentsOutput)
Expand All @@ -87,11 +87,14 @@ suite('Experiments Repository Test Suite', () => {
)
await experimentsRepository.isReady()

const runningOrQueued = experimentsRepository.getRunningOrQueued()
const runningOrQueued = experimentsRepository.getExperimentNames()

expect(runningOrQueued).to.deep.equal([
'workspace',
'exp-05694',
'exp-e7a67',
'test-branch',
'exp-83425',
'90aea7f'
])
})
Expand Down