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

Cleanup plots workspace state #3518

Merged
merged 6 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 29 additions & 1 deletion extension/src/plots/model/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PlotsModel } from '.'
import {
CustomPlotType,
DEFAULT_NB_ITEMS_PER_ROW,
DEFAULT_SECTION_COLLAPSED,
DEFAULT_SECTION_NB_ITEMS_PER_ROW_OR_WIDTH,
Expand All @@ -22,7 +23,7 @@ const mockedRevisions = [
describe('plotsModel', () => {
let model: PlotsModel
const exampleDvcRoot = 'test'
const memento = buildMockMemento({
let memento = buildMockMemento({
[PersistenceKey.PLOTS_CUSTOM_ORDER + exampleDvcRoot]:
customPlotsOrderFixture,
[PersistenceKey.PLOT_NB_ITEMS_PER_ROW_OR_WIDTH + exampleDvcRoot]:
Expand All @@ -45,6 +46,33 @@ describe('plotsModel', () => {
jest.clearAllMocks()
})

it('should update outdated custom state', () => {
memento = buildMockMemento({
[PersistenceKey.PLOTS_CUSTOM_ORDER + exampleDvcRoot]: [
{
metric: 'metrics:summary.json:loss',
param: 'params:params.yaml:dropout'
}
]
})
model = new PlotsModel(
exampleDvcRoot,
{
getFirstThreeColumnOrder: mockedGetFirstThreeColumnOrder,
getSelectedRevisions: mockedGetSelectedRevisions,
isReady: () => Promise.resolve(undefined)
} as unknown as Experiments,
memento
)
expect(model.getCustomPlotsOrder()).toStrictEqual([
julieg18 marked this conversation as resolved.
Show resolved Hide resolved
{
metric: 'summary.json:loss',
param: 'params.yaml:dropout',
type: CustomPlotType.METRIC_VS_PARAM
}
])
})

it('should change the plotSize when calling setPlotSize', () => {
expect(
model.getNbItemsPerRowOrWidth(PlotsSection.CUSTOM_PLOTS)
Expand Down
24 changes: 21 additions & 3 deletions extension/src/plots/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export class PlotsModel extends ModelWithPersistence {
)
this.comparisonOrder = this.revive(PersistenceKey.PLOT_COMPARISON_ORDER, [])
this.customPlotsOrder = this.revive(PersistenceKey.PLOTS_CUSTOM_ORDER, [])

this.cleanupOutdatedCustomPlotsState()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How long should we wait before we remove these functions and delete the metrics persistence keys?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattseddon was the one to make the comment, so I'll leave the verdict to him. But do we even need to migrate the data? I'd just delete it and start fresh.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattseddon was the one to make the comment, so I'll leave the verdict to him. But do we even need to migrate the data? I'd just delete it and start fresh.

Personally, I vote we migrate. It's not that difficult to do and it ensures users who have already created custom plots doesn't lose anything saved when they get the latest release. Though, on the other hand, I doubt that many users have created custom plots so no strong preference 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to you. Please set a reminder for one month from now to turn this off.

this.cleanupOutdatedTrendsState()
}

public transformAndSetExperiments() {
Expand Down Expand Up @@ -181,9 +184,7 @@ export class PlotsModel extends ModelWithPersistence {
}

public getCustomPlotsOrder() {
return this.customPlotsOrder.map(value =>
cleanupOldOrderValue(value, FILE_SEPARATOR)
)
return this.customPlotsOrder
}

public updateCustomPlotsOrder(plotsOrder: CustomPlotsOrderValue[]) {
Expand Down Expand Up @@ -401,6 +402,23 @@ export class PlotsModel extends ModelWithPersistence {
return mapping
}

private cleanupOutdatedCustomPlotsState() {
const workspaceHoldsUpToDateState =
this.customPlotsOrder[0].type !== undefined
if (workspaceHoldsUpToDateState) {
return
}
const newOrder = this.customPlotsOrder.map(value =>
cleanupOldOrderValue(value, FILE_SEPARATOR)
)
this.setCustomPlotsOrder(newOrder)
}

private cleanupOutdatedTrendsState() {
this.revive(PersistenceKey.PLOT_METRIC_ORDER, undefined)
this.revive(PersistenceKey.PLOT_SELECTED_METRICS, undefined)
}

private removeStaleData() {
return Promise.all([this.removeStaleCommits(), this.removeStaleRevisions()])
}
Expand Down