-
Notifications
You must be signed in to change notification settings - Fork 29
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
Queue experiment from existing #1159
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c6e3745
add queue experiment from existing
mattseddon 48070ee
wire up command with integration test
mattseddon 5a5fc8c
fix collect test
mattseddon 38be36e
add in unchanged params
mattseddon 1ce742d
refactor and add a further test
mattseddon bdae358
Merge branch 'master' into queue-single-experiment
mattseddon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { collectFlatExperimentParams } from './collect' | ||
import rowsFixture from '../../../test/fixtures/expShow/rows' | ||
import { joinParamOrMetricFilePath } from '../../paramsAndMetrics/paths' | ||
import { join } from '../../../test/util/path' | ||
|
||
describe('collectFlatExperimentParams', () => { | ||
it('should flatten the params into an array', () => { | ||
const params = collectFlatExperimentParams(rowsFixture[0].params) | ||
expect(params).toEqual([ | ||
{ path: joinParamOrMetricFilePath('params.yaml', 'epochs'), value: 2 }, | ||
{ | ||
path: joinParamOrMetricFilePath('params.yaml', 'learning_rate'), | ||
value: 2.2e-7 | ||
}, | ||
{ | ||
path: joinParamOrMetricFilePath('params.yaml', 'dvc_logs_dir'), | ||
value: 'dvc_logs' | ||
}, | ||
{ | ||
path: joinParamOrMetricFilePath('params.yaml', 'log_file'), | ||
value: 'logs.csv' | ||
}, | ||
{ | ||
path: joinParamOrMetricFilePath('params.yaml', 'dropout'), | ||
value: 0.122 | ||
}, | ||
{ | ||
path: joinParamOrMetricFilePath('params.yaml', 'process.threshold'), | ||
value: 0.86 | ||
}, | ||
{ | ||
path: joinParamOrMetricFilePath('params.yaml', 'process.test_arg'), | ||
value: 'string' | ||
}, | ||
{ | ||
path: joinParamOrMetricFilePath(join('nested', 'params.yaml'), 'test'), | ||
value: true | ||
} | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Value, ValueTree } from '../../../cli/reader' | ||
import { joinParamOrMetricFilePath } from '../../paramsAndMetrics/paths' | ||
import { ParamsOrMetrics } from '../../webview/contract' | ||
|
||
export type Param = { | ||
path: string | ||
value: number | string | boolean | ||
} | ||
|
||
const collectFromParamsFile = ( | ||
acc: { path: string; value: string | number | boolean }[], | ||
key: string | undefined, | ||
value: Value | ValueTree, | ||
ancestors: string[] = [] | ||
) => { | ||
const pathArray = [...ancestors, key].filter(Boolean) as string[] | ||
|
||
if (typeof value === 'object') { | ||
Object.entries(value as ValueTree).forEach(([childKey, childValue]) => { | ||
return collectFromParamsFile(acc, childKey, childValue, pathArray) | ||
}) | ||
return | ||
} | ||
|
||
const path = joinParamOrMetricFilePath(...pathArray) | ||
|
||
acc.push({ path, value }) | ||
} | ||
|
||
export const collectFlatExperimentParams = (params: ParamsOrMetrics = {}) => { | ||
const acc: { path: string; value: string | number | boolean }[] = [] | ||
Object.keys(params).forEach(file => | ||
collectFromParamsFile(acc, undefined, params[file], [file]) | ||
) | ||
return acc | ||
} |
6 changes: 3 additions & 3 deletions
6
extension/src/experiments/queue.ts → ...sion/src/experiments/model/queue/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { mocked } from 'ts-jest/utils' | ||
import { pickParamsToQueue } from './quickPick' | ||
import { getInput } from '../../../vscode/inputBox' | ||
import { quickPickManyValues } from '../../../vscode/quickPick' | ||
|
||
jest.mock('../../../vscode/inputBox') | ||
jest.mock('../../../vscode/quickPick') | ||
|
||
const mockedGetInput = mocked(getInput) | ||
const mockedQuickPickManyValues = mocked(quickPickManyValues) | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
describe('pickParamsToQueue', () => { | ||
it('should return early if no params are selected', async () => { | ||
mockedQuickPickManyValues.mockResolvedValueOnce(undefined) | ||
|
||
const paramsToQueue = await pickParamsToQueue([ | ||
{ path: 'params.yaml:learning_rate', value: 2e-12 } | ||
]) | ||
|
||
expect(paramsToQueue).toBeUndefined() | ||
expect(mockedGetInput).not.toBeCalled() | ||
}) | ||
|
||
it('should return early if the user exits from the input box', async () => { | ||
const unchanged = { path: 'params.yaml:learning_rate', value: 2e-12 } | ||
const initialUserResponse = [ | ||
{ path: 'params.yaml:dropout', value: 0.15 }, | ||
{ path: 'params.yaml:process.threshold', value: 0.86 } | ||
] | ||
mockedQuickPickManyValues.mockResolvedValueOnce(initialUserResponse) | ||
const firstInput = '0.16' | ||
mockedGetInput.mockResolvedValueOnce(firstInput) | ||
mockedGetInput.mockResolvedValueOnce(undefined) | ||
|
||
const paramsToQueue = await pickParamsToQueue([ | ||
unchanged, | ||
...initialUserResponse | ||
]) | ||
|
||
expect(paramsToQueue).toBeUndefined() | ||
expect(mockedGetInput).toBeCalledTimes(2) | ||
}) | ||
|
||
it('should convert any selected params into the required format', async () => { | ||
const unchanged = { path: 'params.yaml:learning_rate', value: 2e-12 } | ||
const initialUserResponse = [ | ||
{ path: 'params.yaml:dropout', value: 0.15 }, | ||
{ path: 'params.yaml:process.threshold', value: 0.86 } | ||
] | ||
mockedQuickPickManyValues.mockResolvedValueOnce(initialUserResponse) | ||
const firstInput = '0.16' | ||
const secondInput = '0.87' | ||
mockedGetInput.mockResolvedValueOnce(firstInput) | ||
mockedGetInput.mockResolvedValueOnce(secondInput) | ||
|
||
const paramsToQueue = await pickParamsToQueue([ | ||
unchanged, | ||
...initialUserResponse | ||
]) | ||
|
||
expect(paramsToQueue).toEqual([ | ||
'-S', | ||
`params.yaml:dropout=${firstInput}`, | ||
'-S', | ||
`params.yaml:process.threshold=${secondInput}`, | ||
'-S', | ||
[unchanged.path, unchanged.value].join('=') | ||
]) | ||
expect(mockedGetInput).toBeCalledTimes(2) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Param } from './collect' | ||
import { quickPickManyValues } from '../../../vscode/quickPick' | ||
import { getInput } from '../../../vscode/inputBox' | ||
import { Flag } from '../../../cli/args' | ||
import { definedAndNonEmpty } from '../../../util/array' | ||
|
||
const pickParamsToVary = (params: Param[]): Thenable<Param[] | undefined> => | ||
quickPickManyValues<Param>( | ||
params.map(param => ({ | ||
description: `${param.value}`, | ||
label: param.path, | ||
picked: true, | ||
value: param | ||
})), | ||
{ title: 'Select a param to vary' } | ||
) | ||
|
||
const pickNewParamValues = async ( | ||
paramsToVary: Param[] | ||
): Promise<string[] | undefined> => { | ||
const args: string[] = [] | ||
for (const { path, value } of paramsToVary) { | ||
const input = await getInput(`Enter a value for ${path}`, `${value}`) | ||
if (input === undefined) { | ||
return | ||
} | ||
args.push(Flag.SET_PARAM) | ||
args.push([path, input.trim()].join('=')) | ||
} | ||
return args | ||
} | ||
|
||
const addUnchanged = (args: string[], unchanged: Param[]) => { | ||
unchanged.forEach(({ path, value }) => { | ||
args.push(Flag.SET_PARAM) | ||
args.push([path, value].join('=')) | ||
}) | ||
|
||
return args | ||
} | ||
|
||
export const pickParamsToQueue = async ( | ||
params: Param[] | ||
): Promise<string[] | undefined> => { | ||
const paramsToVary = await pickParamsToVary(params) | ||
|
||
if (!definedAndNonEmpty(paramsToVary)) { | ||
return | ||
} | ||
|
||
const args = await pickNewParamValues(paramsToVary) | ||
|
||
if (!args) { | ||
return | ||
} | ||
|
||
const paramPathsToVary = paramsToVary.map(param => param.path) | ||
const unchanged = params.filter( | ||
param => !paramPathsToVary.includes(param.path) | ||
) | ||
|
||
return addUnchanged(args, unchanged) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consolidate this and
pickExperimentName
fromextension/src/experiments/workspace.ts
? As far as I can tell, they do the same thing but this is more efficient since it uses our internal model over runningexp list
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This includes queued experiments. The other does not. I will take a look though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rogermparent we use
AvailableCommands.EXPERIMENT_LIST_CURRENT
for applying and branching experiments. We can switch to using code that pulls the names out of the model. I will follow up.