Skip to content

Commit

Permalink
Merge pull request #27 from Exabyte-io/chore/SOF-6322
Browse files Browse the repository at this point in the history
refactor: mode context providers from mode to wode
  • Loading branch information
azech-hqs authored Feb 3, 2023
2 parents aaac558 + acb911e commit 2a116e3
Show file tree
Hide file tree
Showing 9 changed files with 618 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/context/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { BoundaryConditionsFormDataProvider } from "./providers/BoundaryConditionsFormDataProvider";
import { MLSettingsContextProvider } from "./providers/MLSettingsContextProvider";
import { MLTrainTestSplitContextProvider } from "./providers/MLTrainTestSplitContextProvider";
import { NEBFormDataProvider } from "./providers/NEBFormDataProvider";
import { PlanewaveCutoffsContextProvider } from "./providers/PlanewaveCutoffsContextProvider";
import { PointsGridFormDataProvider } from "./providers/PointsGridFormDataProvider";
import {
ExplicitPointsPath2PIBAFormDataProvider,
ExplicitPointsPathFormDataProvider,
PointsPathFormDataProvider,
} from "./providers/PointsPathFormDataProvider";

export default {
BoundaryConditionsFormDataProvider,
MLSettingsContextProvider,
MLTrainTestSplitContextProvider,
NEBFormDataProvider,
PlanewaveCutoffsContextProvider,
PointsGridFormDataProvider,
PointsPathFormDataProvider,
ExplicitPointsPathFormDataProvider,
ExplicitPointsPath2PIBAFormDataProvider,
};
2 changes: 1 addition & 1 deletion src/context/providers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { context } from "@exabyte-io/mode.js";
import context from "./context";

const {
BoundaryConditionsFormDataProvider,
Expand Down
76 changes: 76 additions & 0 deletions src/context/providers/BoundaryConditionsFormDataProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { JSONSchemaFormDataProvider, MaterialContextMixin } from "@exabyte-io/code.js/dist/context";
import { deepClone } from "@exabyte-io/code.js/dist/utils";
import { Made } from "@exabyte-io/made.js";
import { mix } from "mixwith";

export class BoundaryConditionsFormDataProvider extends mix(JSONSchemaFormDataProvider).with(
MaterialContextMixin,
) {
static Material = Made.Material;

get boundaryConditions() {
return this.material.metadata.boundaryConditions || {};
}

// eslint-disable-next-line class-methods-use-this
get defaultData() {
return {
type: this.boundaryConditions.type || "pbc",
offset: this.boundaryConditions.offset || 0,
electricField: 0,
targetFermiEnergy: 0,
};
}

// eslint-disable-next-line class-methods-use-this
get uiSchema() {
return {
type: { "ui:disabled": true },
offset: { "ui:disabled": true },
electricField: {},
targetFermiEnergy: {},
};
}

// eslint-disable-next-line class-methods-use-this
get humanName() {
return "Boundary Conditions";
}

yieldDataForRendering() {
const data = deepClone(this.yieldData());
data.boundaryConditions.offset *= Made.coefficients.ANGSTROM_TO_BOHR;
data.boundaryConditions.targetFermiEnergy *= Made.coefficients.EV_TO_RY;
data.boundaryConditions.electricField *= Made.coefficients.EV_A_TO_RY_BOHR;
return data;
}

get jsonSchema() {
return {
$schema: "http://json-schema.org/draft-04/schema#",
type: "object",
properties: {
type: {
type: "string",
title: "Type",
default: this.defaultData.type,
},
offset: {
type: "number",
title: "Offset (A)",
default: this.defaultData.offset,
},
electricField: {
type: "number",
title: "Electric Field (eV/A)",
default: this.defaultData.electricField,
},
targetFermiEnergy: {
type: "number",
title: "Target Fermi Energy (eV)",
default: this.defaultData.targetFermiEnergy,
},
},
};
}
}
43 changes: 43 additions & 0 deletions src/context/providers/MLSettingsContextProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Application } from "@exabyte-io/ade.js";
import { ApplicationContextMixin, ContextProvider } from "@exabyte-io/code.js/dist/context";
import { mix } from "mixwith";

export class MLSettingsContextProvider extends mix(ContextProvider).with(ApplicationContextMixin) {
static Application = Application;

// eslint-disable-next-line class-methods-use-this
get uiSchema() {
return {
target_column_name: {},
problem_category: {},
};
}

// eslint-disable-next-line class-methods-use-this
get defaultData() {
return {
target_column_name: "target",
problem_category: "regression",
};
}

get jsonSchema() {
return {
$schema: "http://json-schema.org/draft-04/schema#",
title: " ",
description: "Settings important to machine learning runs.",
type: "object",
properties: {
target_column_name: {
type: "string",
default: this.defaultData.target_column_name,
},
problem_category: {
type: "string",
default: this.defaultData.problem_category,
enum: ["regression", "classification", "clustering"],
},
},
};
}
}
42 changes: 42 additions & 0 deletions src/context/providers/MLTrainTestSplitContextProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Application } from "@exabyte-io/ade.js";
import { ApplicationContextMixin, ContextProvider } from "@exabyte-io/code.js/dist/context";
import { mix } from "mixwith";

export class MLTrainTestSplitContextProvider extends mix(ContextProvider).with(
ApplicationContextMixin,
) {
static Application = Application;

// eslint-disable-next-line class-methods-use-this
get uiSchema() {
return {
target_column_name: {},
problem_category: {},
};
}

// eslint-disable-next-line class-methods-use-this
get defaultData() {
return {
fraction_held_as_test_set: 0.2,
};
}

get jsonSchema() {
return {
$schema: "http://json-schema.org/draft-04/schema#",
title: " ",
description:
"Fraction held as the test set. For example, a value of 0.2 corresponds to an 80/20 train/test split.",
type: "object",
properties: {
fraction_held_as_test_set: {
type: "number",
default: this.defaultData.fraction_held_as_test_set,
minimum: 0,
maximum: 1,
},
},
};
}
}
32 changes: 32 additions & 0 deletions src/context/providers/NEBFormDataProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { JSONSchemaFormDataProvider } from "@exabyte-io/code.js/dist/context";

export class NEBFormDataProvider extends JSONSchemaFormDataProvider {
// eslint-disable-next-line class-methods-use-this
get defaultData() {
return {
nImages: 1,
};
}

// eslint-disable-next-line class-methods-use-this
get uiSchema() {
return {
nImages: {},
};
}

get jsonSchema() {
return {
$schema: "http://json-schema.org/draft-04/schema#",
title: " ",
description: "Number of intermediate NEB images.",
type: "object",
properties: {
nImages: {
type: "number",
default: this.defaultData.nImages,
},
},
};
}
}
65 changes: 65 additions & 0 deletions src/context/providers/PlanewaveCutoffsContextProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Application } from "@exabyte-io/ade.js";
import { ApplicationContextMixin, ContextProvider } from "@exabyte-io/code.js/dist/context";
import { mix } from "mixwith";

const cutoffConfig = {
vasp: {}, // assuming default cutoffs for VASP
espresso: {
// assuming the default GBRV set of pseudopotentials is used
wavefunction: 40,
density: 200,
},
};

export class PlanewaveCutoffsContextProvider extends mix(ContextProvider).with(
ApplicationContextMixin,
) {
static Application = Application;

// eslint-disable-next-line class-methods-use-this
get uiSchema() {
return {
wavefunction: {},
density: {},
};
}

get defaultData() {
return {
wavefunction: this.defaultECUTWFC,
density: this.defaultECUTRHO,
};
}

get _cutoffConfigPerApplication() {
return cutoffConfig[this.application.name];
}

get defaultECUTWFC() {
return this._cutoffConfigPerApplication.wavefunction || null;
}

get defaultECUTRHO() {
return this._cutoffConfigPerApplication.density || null;
}

get jsonSchema() {
return {
$schema: "http://json-schema.org/draft-04/schema#",
title: " ",
description:
"Planewave cutoff parameters for electronic wavefunctions and density. Units are specific to simulation engine.",
type: "object",
properties: {
wavefunction: {
type: "number",
default: this.defaultECUTWFC,
},
density: {
type: "number",
default: this.defaultECUTRHO,
},
},
};
}
}
Loading

0 comments on commit 2a116e3

Please sign in to comment.