Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
296 changes: 263 additions & 33 deletions webapp/cypress/e2e/task-creation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,264 @@ import { deserializeTaskFromJSON, type Task } from "@epfml/discojs";
import * as tf from "@tensorflow/tfjs";

it("submits with tabular task", () => {
visitAndFillTabularTaskBasics("id", "simple");

cy.get("select[name='trainingInformation.scheme']").select("federated");
fillRemainingTabularFieldsAndSubmit();

cy.wait("@posted")
.its("request.body.task")
.then(deserializeTaskFromJSON)
.should("deep.equal", {
id: "id",
dataType: "tabular",
displayInformation: {
title: "simple",
summary: {
preview: "preview",
overview: "overview",
},
dataExample: [{ name: "name", data: "data" }],
},
trainingInformation: {
scheme: "federated",
aggregationStrategy: "mean",
epochs: 10,
batchSize: 5,
roundDuration: 2,
validationSplit: 0,
minNbOfParticipants: 2,
inputColumns: ["input"],
categoricalColumns: {},
outputColumn: "output",
tensorBackend: "tfjs",
},
} satisfies Task<"tabular", "federated">);
});

for (const aggregation of [
Comment thread
ale18V marked this conversation as resolved.
Resolved
{
scheme: "federated",
aggregationStrategy: "byzantine",
aggregationParams: { clippingRadius: 2.5, maxIterations: 3, beta: 0.8 },
},
{
scheme: "decentralized",
aggregationStrategy: "secure",
aggregationParams: { maxShareValue: 250 },
maxConnectionRetry: 3,
maxPeerConnectionTime: 60_000,
maxModelSyncTime: 30_000,
},
] as const) {
it(`submits with custom aggregation parameters (${aggregation.aggregationStrategy})`, () => {
visitAndFillTabularTaskBasics("aggregation-task", "aggregation title");

cy.get("select[name='trainingInformation.scheme']").select("decentralized");
cy.get("select[name='trainingInformation.aggregationStrategy']").select(
"secure",
);
cy.get("select[name='trainingInformation.scheme']").select("federated");
cy.get("select[name='trainingInformation.aggregationStrategy']").should(
"have.value",
"mean",
);
cy.get(
"select[name='trainingInformation.aggregationStrategy'] option[value='secure']",
).should("not.exist");
cy.get("select[name='trainingInformation.aggregationStrategy']").select(
"byzantine",
);
cy.get(
"input[name='trainingInformation.aggregationParams.clippingRadius']",
).type("2.5");
cy.get("select[name='trainingInformation.scheme']").select("decentralized");
cy.get("select[name='trainingInformation.aggregationStrategy']").select(
"secure",
);
cy.get(
"input[name='trainingInformation.aggregationParams.maxShareValue']",
).type("250");
cy.get("select[name='trainingInformation.scheme']").select(
aggregation.scheme,
);
cy.get("select[name='trainingInformation.aggregationStrategy']").select(
aggregation.aggregationStrategy,
);
for (const [key, value] of Object.entries(aggregation.aggregationParams)) {
cy.get(
`input[name='trainingInformation.aggregationParams.${key}']`,
).clear();
cy.get(`input[name='trainingInformation.aggregationParams.${key}']`).type(
String(value),
);
}

fillRemainingTabularFieldsAndSubmit();

cy.wait("@posted")
.its("request.body.task")
.then(deserializeTaskFromJSON)
.should("deep.equal", {
id: "aggregation-task",
dataType: "tabular",
displayInformation: {
title: "aggregation title",
summary: {
preview: "preview",
overview: "overview",
},
dataExample: [{ name: "name", data: "data" }],
},
trainingInformation: {
...aggregation,
epochs: 10,
batchSize: 5,
roundDuration: 2,
validationSplit: 0,
minNbOfParticipants: 2,
inputColumns: ["input"],
categoricalColumns: {},
outputColumn: "output",
tensorBackend: "tfjs",
},
});
});
}

it("does not submit aggregationParams when switching from byzantine to mean", () => {
visitAndFillTabularTaskBasics(
"aggregation-reset-task",
"aggregation reset title",
);

cy.get("select[name='trainingInformation.scheme']").select("federated");
cy.get("select[name='trainingInformation.aggregationStrategy']").select(
"byzantine",
);
cy.get(
"input[name='trainingInformation.aggregationParams.clippingRadius']",
).type("2.5");
cy.get(
"input[name='trainingInformation.aggregationParams.maxIterations']",
).type("3");
cy.get("input[name='trainingInformation.aggregationParams.beta']").type(
"0.8",
);

cy.get("select[name='trainingInformation.aggregationStrategy']").select(
"mean",
);
cy.get(
"input[name='trainingInformation.aggregationParams.clippingRadius']",
).should("not.exist");

fillRemainingTabularFieldsAndSubmit();

cy.wait("@posted")
.its("request.body.task.trainingInformation")
.should("not.have.property", "aggregationParams");

cy.get("@posted")
.its("request.body.task")
.then(deserializeTaskFromJSON)
.should("deep.equal", {
id: "aggregation-reset-task",
dataType: "tabular",
displayInformation: {
title: "aggregation reset title",
summary: {
preview: "preview",
overview: "overview",
},
dataExample: [{ name: "name", data: "data" }],
},
trainingInformation: {
scheme: "federated",
aggregationStrategy: "mean",
epochs: 10,
batchSize: 5,
roundDuration: 2,
validationSplit: 0,
minNbOfParticipants: 2,
inputColumns: ["input"],
categoricalColumns: {},
outputColumn: "output",
tensorBackend: "tfjs",
},
} satisfies Task<"tabular", "federated">);
});

for (const aggregation of [
{
scheme: "federated",
aggregationStrategy: "byzantine",
aggregationParams: { clippingRadius: 1.0, maxIterations: 1, beta: 0.9 },
},
{
scheme: "decentralized",
aggregationStrategy: "secure",
aggregationParams: { maxShareValue: 100 },
maxConnectionRetry: 3,
maxPeerConnectionTime: 60_000,
maxModelSyncTime: 30_000,
},
] as const) {
it(`falls back to default aggregation parameters (${aggregation.aggregationStrategy})`, () => {
visitAndFillTabularTaskBasics(
"aggregation-default-task",
"aggregation default title",
);

cy.get("select[name='trainingInformation.scheme']").select(
aggregation.scheme,
);
cy.get("select[name='trainingInformation.aggregationStrategy']").select(
aggregation.aggregationStrategy,
);
for (const key of Object.keys(aggregation.aggregationParams)) {
cy.get(
`input[name='trainingInformation.aggregationParams.${key}']`,
).should("have.value", "");
}

fillRemainingTabularFieldsAndSubmit();

cy.wait("@posted")
.its("request.body.task.trainingInformation.aggregationParams")
.should("deep.equal", aggregation.aggregationParams);

cy.get("@posted")
.its("request.body.task")
.then(deserializeTaskFromJSON)
.should("deep.equal", {
id: "aggregation-default-task",
dataType: "tabular",
displayInformation: {
title: "aggregation default title",
summary: {
preview: "preview",
overview: "overview",
},
dataExample: [{ name: "name", data: "data" }],
},
trainingInformation: {
...aggregation,
epochs: 10,
batchSize: 5,
roundDuration: 2,
validationSplit: 0,
minNbOfParticipants: 2,
inputColumns: ["input"],
categoricalColumns: {},
outputColumn: "output",
tensorBackend: "tfjs",
},
});
});
}

function visitAndFillTabularTaskBasics(id: string, title: string): void {
cy.intercept(
{ hostname: "server", pathname: "tasks", method: "POST" },
{ statusCode: 200 },
Expand All @@ -12,10 +270,10 @@ it("submits with tabular task", () => {

cy.get("form").should("be.visible"); // Wait for the form to be fully loaded

cy.get("input[name='id']").type("id");
cy.get("input[name='id']").type(id);
cy.get("select[name='dataType']").select("tabular");

cy.get("input[name='displayInformation.title']").type("simple");
cy.get("input[name='displayInformation.title']").type(title);
cy.get("input[name='displayInformation.summary.preview']").type("preview");
cy.get("textarea[name='displayInformation.summary.overview']").type(
"overview",
Expand All @@ -25,8 +283,9 @@ it("submits with tabular task", () => {
cy.get("input[name='displayInformation.dataExample[0].name']").type("name");
cy.get("input[name='displayInformation.dataExample[0].data']").type("data");
});
}

cy.get("select[name='trainingInformation.scheme']").select("federated");
function fillRemainingTabularFieldsAndSubmit(): void {
cy.get("input[name='trainingInformation.epochs']").type("10");
cy.get("input[name='trainingInformation.batchSize']").type("5");
cy.get("input[name='trainingInformation.roundDuration']").type("2");
Expand Down Expand Up @@ -61,36 +320,7 @@ it("submits with tabular task", () => {
cy.get("input[name='model.optimizer.learningRate']").type("0.01");

cy.get("button[type='submit']").click();

cy.wait("@posted")
.its("request.body.task")
.then(deserializeTaskFromJSON)
.should("deep.equal", {
id: "id",
dataType: "tabular",
displayInformation: {
title: "simple",
summary: {
preview: "preview",
overview: "overview",
},
dataExample: [{ name: "name", data: "data" }],
},
trainingInformation: {
scheme: "federated",
aggregationStrategy: "mean",
epochs: 10,
batchSize: 5,
roundDuration: 2,
validationSplit: 0,
minNbOfParticipants: 2,
inputColumns: ["input"],
categoricalColumns: {},
outputColumn: "output",
tensorBackend: "tfjs",
},
} satisfies Task<"tabular", "federated">);
});
}

async function getArtifacts(
model: tf.LayersModel,
Expand Down
Loading