Skip to content

Commit

Permalink
refactor: Update experiment creation process in test suites
Browse files Browse the repository at this point in the history
- Introduce a time metric for search with a max time of 937 batches
- Simplify experiment creation validation logic
- Modify kill experiment functionality to check for cancellation status after kill
  • Loading branch information
thiagodallacqua-hpe committed Oct 30, 2024
1 parent fd15cac commit cb2dc7f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
2 changes: 2 additions & 0 deletions examples/tutorials/mnist_pytorch/adaptive.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ searcher:
smaller_is_better: true
max_trials: 16
max_length: 14
time_metric: batches
max_time: 937 # 60,000 training images with batch size 64
entrypoint: python3 train.py --epochs 1
45 changes: 27 additions & 18 deletions webui/react/src/e2e/tests/experimentList.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import { detExecSync, fullPath } from 'e2e/utils/detCLI';
import { safeName } from 'e2e/utils/naming';
import { repeatWithFallback } from 'e2e/utils/polling';
import { V1Project } from 'services/api-ts-sdk';
import { ExperimentBase } from 'types';
import { ExperimentBase, RunState } from 'types';

dayjs.extend(utcPlugin);

test.describe('Experiment List', () => {
let projectDetailsPage: ProjectDetails;
// trial click to wait for the element to be stable won't work here
const waitTableStable = async () =>
await projectDetailsPage._page.waitForTimeout(2_000);
const waitTableStable = async () => await projectDetailsPage._page.waitForTimeout(2_000);
const getCount = async () => {
const count =
await projectDetailsPage.f_experimentList.tableActionBar.count.pwLocator.textContent();
Expand Down Expand Up @@ -623,13 +622,8 @@ test.describe('Experiment List', () => {
`experiment create ${fullPath('examples/tutorials/mnist_pytorch/adaptive.yaml')} --paused --project_id ${project.id}`,
).split(' ')[2],
); // returns in the format "Created experiment <exp_id>"
killExperiment = Number(
detExecSync(
`experiment create ${fullPath('examples/tutorials/core_api/2_checkpoints.yaml')} --paused --project_id ${project.id}`,
).split(' ')[2],
); // returns in the format "Created experiment <exp_id>"

if (Number.isNaN(experimentId) || Number.isNaN(killExperiment)) throw new Error('No experiment ID was found');
if (Number.isNaN(experimentId)) throw new Error('No experiment ID was found');
},
);

Expand All @@ -640,7 +634,6 @@ test.describe('Experiment List', () => {
detExecSync(`experiment delete ${experimentId} --y`);
}
if (killExperiment !== undefined) {
detExecSync(`experiment kill ${killExperiment}`);
detExecSync(`experiment delete ${killExperiment} --y`);
}

Expand Down Expand Up @@ -687,9 +680,24 @@ test.describe('Experiment List', () => {
await expect(newProjectRows.length).toBe(1);
});

test('kill experiment', async () => {
test('kill experiment', async ({
newProject: {
response: { project },
},
newWorkspace: {
response: { workspace },
},
}) => {
killExperiment = Number(
detExecSync(
`experiment create ${fullPath('examples/tutorials/core_api/2_checkpoints.yaml')} --project_id ${project.id}`,
).split(' ')[2],
);
if (Number.isNaN(killExperiment)) throw new Error('No experiment ID was found');

const grid = projectDetailsPage.f_experimentList.dataGrid;
await grid.setColumnHeight();
await grid.headRow.setColumnDefs();
const newExperimentRow =
await projectDetailsPage.f_experimentList.dataGrid.getRowByColumnValue(
'ID',
Expand All @@ -700,17 +708,18 @@ test.describe('Experiment List', () => {

await experimentActionDropdown.menuItem('Kill').pwLocator.click();

await expect(
experimentActionDropdown.stopKillModal.targetExperiment.pwLocator.textContent(),
).toContain(experimentId.toString());

await experimentActionDropdown.stopKillModal.footer.submit.pwLocator.click();
await experimentActionDropdown.stopKillModal.pwLocator.waitFor({ state: 'visible' });
await experimentActionDropdown.stopKillModal.footer.pwLocator.getByText('Kill').click();
await experimentActionDropdown.stopKillModal.pwLocator.waitFor({ state: 'hidden' });

// eslint-disable-next-line no-console
console.log((await newExperimentRow.getCellByColumnName('State')).pwLocator.innerText());

expect(true).toBe(true);
const experiments: ExperimentBase[] = JSON.parse(
detExecSync(`project list-experiments --json ${workspace.name} ${project.name}`),
);
const killedExperiment = experiments.find(({ id }) => id === killExperiment);
await expect(killedExperiment).not.toBeUndefined();
await expect(killedExperiment?.state).toContain(RunState.Canceled);
});
});
});

0 comments on commit cb2dc7f

Please sign in to comment.