-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use plot errors to display correct messages for missing plots (#3520)
- Loading branch information
1 parent
e345fce
commit 1d3cfca
Showing
21 changed files
with
459 additions
and
52 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import { join } from 'path' | ||
import { collectErrors, collectImageErrors } from './collect' | ||
import { EXPERIMENT_WORKSPACE_ID } from '../../cli/dvc/contract' | ||
|
||
describe('collectErrors', () => { | ||
it('should remove errors that belong to revisions that have been fetched', () => { | ||
const errors = collectErrors( | ||
{ data: {} }, | ||
[EXPERIMENT_WORKSPACE_ID], | ||
[ | ||
{ | ||
msg: 'unexpected error', | ||
name: 'fun::plot', | ||
rev: EXPERIMENT_WORKSPACE_ID, | ||
source: 'metrics.json', | ||
type: 'unexpected' | ||
} | ||
], | ||
{} | ||
) | ||
|
||
expect(errors).toStrictEqual([]) | ||
}) | ||
|
||
it('should collect new errors', () => { | ||
const newError = { | ||
msg: 'Blue screen of death', | ||
name: 'fun::plot', | ||
rev: 'd7ad114', | ||
source: 'metrics.json', | ||
type: 'unexpected' | ||
} | ||
|
||
const errors = collectErrors( | ||
{ | ||
data: {}, | ||
errors: [newError] | ||
}, | ||
[EXPERIMENT_WORKSPACE_ID, 'd7ad114'], | ||
[ | ||
{ | ||
msg: 'unexpected error', | ||
name: 'fun::plot', | ||
rev: EXPERIMENT_WORKSPACE_ID, | ||
source: 'metrics.json', | ||
type: 'unexpected' | ||
} | ||
], | ||
{ d7ad114: 'main' } | ||
) | ||
|
||
expect(errors).toStrictEqual([{ ...newError, rev: 'main' }]) | ||
}) | ||
}) | ||
|
||
describe('collectImageErrors', () => { | ||
it('should return undefined if there are no errors for the image', () => { | ||
const error = collectImageErrors( | ||
'misclassified.jpg', | ||
EXPERIMENT_WORKSPACE_ID, | ||
[] | ||
) | ||
expect(error).toBeUndefined() | ||
}) | ||
|
||
it('should collect a single error for an image', () => { | ||
const path = join('training', 'plots', 'images', 'mispredicted.jpg') | ||
const otherPath = 'other' | ||
|
||
const errors = [ | ||
{ | ||
msg: `${otherPath} - file type error\nOnly JSON, YAML, CSV and TSV formats are supported.`, | ||
name: otherPath, | ||
rev: EXPERIMENT_WORKSPACE_ID, | ||
source: otherPath, | ||
type: 'PlotMetricTypeError' | ||
}, | ||
{ | ||
msg: "Could not find provided field ('ste') in data fields ('step, test/acc').", | ||
name: otherPath, | ||
rev: EXPERIMENT_WORKSPACE_ID, | ||
source: otherPath, | ||
type: 'FieldNotFoundError' | ||
}, | ||
{ | ||
msg: '', | ||
name: path, | ||
rev: EXPERIMENT_WORKSPACE_ID, | ||
source: path, | ||
type: 'FileNotFoundError' | ||
}, | ||
{ | ||
msg: '', | ||
name: path, | ||
rev: 'main', | ||
source: path, | ||
type: 'FileNotFoundError' | ||
} | ||
] | ||
|
||
const error = collectImageErrors(path, EXPERIMENT_WORKSPACE_ID, errors) | ||
expect(error).toStrictEqual(`FileNotFoundError: ${path} not found.`) | ||
}) | ||
|
||
it('should concatenate errors together to give a single string', () => { | ||
const path = join('training', 'plots', 'images', 'mispredicted.jpg') | ||
|
||
const errors = [ | ||
{ | ||
msg: '', | ||
name: path, | ||
rev: EXPERIMENT_WORKSPACE_ID, | ||
source: path, | ||
type: 'FileNotFoundError' | ||
}, | ||
{ | ||
msg: 'catastrophic error', | ||
name: path, | ||
rev: EXPERIMENT_WORKSPACE_ID, | ||
source: path, | ||
type: 'SomeError' | ||
}, | ||
{ | ||
msg: '', | ||
name: path, | ||
rev: EXPERIMENT_WORKSPACE_ID, | ||
source: path, | ||
type: 'UNEXPECTEDERRRRROR' | ||
} | ||
] | ||
|
||
const error = collectImageErrors(path, EXPERIMENT_WORKSPACE_ID, errors) | ||
expect(error).toStrictEqual( | ||
`FileNotFoundError: ${path} not found.\nSomeError: catastrophic error\nUNEXPECTEDERRRRROR` | ||
) | ||
}) | ||
}) |
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,53 @@ | ||
import { PlotError, PlotsOutput } from '../../cli/dvc/contract' | ||
|
||
export const collectErrors = ( | ||
data: PlotsOutput, | ||
revs: string[], | ||
errors: PlotError[], | ||
cliIdToLabel: { [id: string]: string } | ||
) => { | ||
const existingErrors = errors.filter( | ||
({ rev }) => !revs.includes(cliIdToLabel[rev] || rev) | ||
) | ||
const newErrors = data?.errors || [] | ||
|
||
return [ | ||
...existingErrors, | ||
...newErrors.map(error => { | ||
const { rev } = error | ||
return { | ||
...error, | ||
rev: cliIdToLabel[rev] || rev | ||
} | ||
}) | ||
] | ||
} | ||
|
||
const getMessage = (error: PlotError): string => { | ||
const { msg, type, source } = error | ||
|
||
if (type === 'FileNotFoundError' && source && !msg) { | ||
return `${type}: ${source} not found.` | ||
} | ||
return [type, msg].filter(Boolean).join(': ') | ||
} | ||
|
||
export const collectImageErrors = ( | ||
path: string, | ||
revision: string, | ||
errors: PlotError[] | ||
): string | undefined => { | ||
const msgs: string[] = [] | ||
for (const error of errors) { | ||
if (error.rev === revision && error.name === path) { | ||
const msg = getMessage(error) | ||
msgs.push(msg) | ||
} | ||
} | ||
|
||
if (msgs.length === 0) { | ||
return undefined | ||
} | ||
|
||
return msgs.join('\n') | ||
} |
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,31 @@ | ||
import { collectErrors, collectImageErrors } from './collect' | ||
import { Disposable } from '../../class/dispose' | ||
import { PlotError, PlotsOutputOrError } from '../../cli/dvc/contract' | ||
import { isDvcError } from '../../cli/dvc/reader' | ||
|
||
export class ErrorsModel extends Disposable { | ||
private readonly dvcRoot: string | ||
|
||
private errors: PlotError[] = [] | ||
|
||
constructor(dvcRoot: string) { | ||
super() | ||
this.dvcRoot = dvcRoot | ||
} | ||
|
||
public transformAndSet( | ||
data: PlotsOutputOrError, | ||
revs: string[], | ||
cliIdToLabel: { [id: string]: string } | ||
) { | ||
if (isDvcError(data)) { | ||
return | ||
} | ||
|
||
this.errors = collectErrors(data, revs, this.errors, cliIdToLabel) | ||
} | ||
|
||
public getImageErrors(path: string, revision: string) { | ||
return collectImageErrors(path, revision, this.errors) | ||
} | ||
} |
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
Oops, something went wrong.