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

chore/SOF-6990-1: refactor method data propagation #46

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/cicd.yml
Expand Up @@ -29,6 +29,7 @@ jobs:
uses: ./actions/yaml/lint
with:
python-version: 3.8
targets: ./assets

run-js-tests:
runs-on: ubuntu-latest
Expand Down
7 changes: 5 additions & 2 deletions assets/subworkflows/vasp/band_gap.yml
@@ -1,10 +1,13 @@
application:
name: vasp
version: 5.3.5
method:
name: PseudopotentialMethod
model:
name: DFTModel
method:
name: PseudopotentialMethod
config:
type: pseudopotential
subtype: paw
name: Band Gap
units:
- config:
Expand Down
7 changes: 5 additions & 2 deletions assets/subworkflows/vasp/band_structure.yml
@@ -1,10 +1,13 @@
application:
name: vasp
version: 5.3.5
method:
name: PseudopotentialMethod
model:
name: DFTModel
method:
name: PseudopotentialMethod
config:
type: pseudopotential
subtype: paw
name: Band Structure
units:
- config:
Expand Down
7 changes: 5 additions & 2 deletions assets/subworkflows/vasp/band_structure_dos.yml
@@ -1,10 +1,13 @@
application:
name: vasp
version: 5.3.5
method:
name: PseudopotentialMethod
model:
name: DFTModel
method:
name: PseudopotentialMethod
config:
type: pseudopotential
subtype: paw
name: Band Structure + Density of States
units:
- config:
Expand Down
7 changes: 5 additions & 2 deletions assets/subworkflows/vasp/dos.yml
@@ -1,10 +1,13 @@
application:
name: vasp
version: 5.3.5
method:
name: PseudopotentialMethod
model:
name: DFTModel
method:
name: PseudopotentialMethod
config:
type: pseudopotential
subtype: paw
name: Density of States
units:
- config:
Expand Down
7 changes: 5 additions & 2 deletions assets/subworkflows/vasp/fixed_cell_relaxation.yml
@@ -1,10 +1,13 @@
application:
name: vasp
version: 5.3.5
method:
name: PseudopotentialMethod
model:
name: DFTModel
method:
name: PseudopotentialMethod
config:
type: pseudopotential
subtype: paw
name: Fixed-cell Relaxation
units:
- config:
Expand Down
7 changes: 5 additions & 2 deletions assets/subworkflows/vasp/initial_final_total_energies.yml
Expand Up @@ -5,10 +5,13 @@ config:
isMultiMaterial: true
functions:
setDefaultCompute: null
method:
name: PseudopotentialMethod
model:
name: DFTModel
method:
name: PseudopotentialMethod
config:
type: pseudopotential
subtype: paw
name: Initial/Final Total Energies
units:
- config:
Expand Down
7 changes: 5 additions & 2 deletions assets/subworkflows/vasp/neb_subworkflow.yml
Expand Up @@ -3,10 +3,13 @@ application:
version: 5.3.5
config:
isMultiMaterial: true
method:
name: PseudopotentialMethod
model:
name: DFTModel
method:
name: PseudopotentialMethod
config:
type: pseudopotential
subtype: paw
name: Nudged Elastic Band (NEB)
units:
- config:
Expand Down
7 changes: 5 additions & 2 deletions assets/subworkflows/vasp/recalculate_bands.yml
@@ -1,10 +1,13 @@
application:
name: vasp
version: 5.3.5
method:
name: PseudopotentialMethod
model:
name: DFTModel
method:
name: PseudopotentialMethod
config:
type: pseudopotential
subtype: paw
name: Recalculate Bands
units:
- config:
Expand Down
7 changes: 5 additions & 2 deletions assets/subworkflows/vasp/surface_energy.yml
Expand Up @@ -3,10 +3,13 @@ application:
version: 5.3.5
dynamicSubworkflow:
name: surfaceEnergy
method:
name: PseudopotentialMethod
model:
name: DFTModel
method:
name: PseudopotentialMethod
config:
type: pseudopotential
subtype: paw
name: Surface Energy
units:
- config:
Expand Down
7 changes: 5 additions & 2 deletions assets/subworkflows/vasp/total_energy.yml
@@ -1,10 +1,13 @@
application:
name: vasp
version: 5.3.5
method:
name: PseudopotentialMethod
model:
name: DFTModel
method:
name: PseudopotentialMethod
config:
type: pseudopotential
subtype: paw
name: Total Energy
units:
- config:
Expand Down
7 changes: 5 additions & 2 deletions assets/subworkflows/vasp/variable_cell_relaxation.yml
Expand Up @@ -3,10 +3,13 @@ application:
version: 5.3.5
config:
systemName: vasp-variable-cell-relaxation
method:
name: PseudopotentialMethod
model:
name: DFTModel
method:
name: PseudopotentialMethod
config:
type: pseudopotential
subtype: paw
name: Variable-cell Relaxation
units:
- config:
Expand Down
7 changes: 5 additions & 2 deletions assets/subworkflows/vasp/zero_point_energy.yml
@@ -1,10 +1,13 @@
application:
name: vasp
version: 5.3.5
method:
name: PseudopotentialMethod
model:
name: DFTModel
method:
name: PseudopotentialMethod
config:
type: pseudopotential
subtype: paw
name: Zero Point Energy
units:
- config:
Expand Down
31 changes: 24 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -52,7 +52,8 @@
"@exabyte-io/eslint-config": "^2022.11.17-0",
"@exabyte-io/ide.js": "2022.7.28-1",
"@exabyte-io/made.js": "2023.3.8-0",
"@exabyte-io/mode.js": "2023.9.19-0",
"@exabyte-io/mode.js": "git+https://github.com/Exabyte-io/mode.js.git#8b3e5c5c9836a334a36ba7001ab06e5640eb7010",
"@exabyte-io/prode.js": "git+https://github.com/Exabyte-io/prode.js.git#6b2e55c442ae5faa990e1db2d89bec4061188cd8",
"chai": "^4.3.4",
"eslint": "7.32.0",
"eslint-config-airbnb": "19.0.2",
Expand Down
23 changes: 20 additions & 3 deletions src/subworkflows/subworkflow.js
Expand Up @@ -31,14 +31,15 @@ export class Subworkflow extends BaseSubworkflow {
this._Application = Application;
this._ModelFactory = ModelFactory;
this._UnitFactory = UnitFactory;
this.initialize();
this.initialize(config.extraConfig);
}

initialize() {
initialize(extraConfig) {
this._application = new this._Application(this.prop("application"));
this._model = this._ModelFactory.create({
...this.prop("model"),
application: this.prop("application"),
extraConfig: { ...extraConfig, application: this.prop("application") },
});
this._units = setNextLinks(setUnitsHead(this.prop("units", [])), this.id).map((cfg) =>
this._UnitFactory.create(
Expand Down Expand Up @@ -103,7 +104,12 @@ export class Subworkflow extends BaseSubworkflow {
return this._application;
}

setApplication(application) {
/**
* Set application and update dependencies.
* @param {Application} application - Application instance
* @param {Object} extraConfig - Object containing dependencies to construct method data.
*/
setApplication(application, extraConfig) {
// TODO: adjust the logic above to take into account whether units need re-rendering after version change etc.
// reset units if application name changes
const previousApplicationName = this.application.name;
Expand All @@ -124,6 +130,10 @@ export class Subworkflow extends BaseSubworkflow {
this.setModel(
this._ModelFactory.createFromApplication({
application: this.prop("application"),
extraConfig: {
...extraConfig,
application: this.prop("application"),
},
}),
);
}
Expand Down Expand Up @@ -285,6 +295,13 @@ export class Subworkflow extends BaseSubworkflow {
return this.model.method.data;
}

initializeMethodData(extraConfig) {
const method = this.model?.method;
if (!method) return;
const cfg = { ...extraConfig, application: this.application, model: this.model };
method.initializeData(cfg);
}

/**
* @summary Calculates hash of the subworkflow. Meaningful fields are units, app and model.
* units must be sorted topologically before hashing (already sorted).
Expand Down
18 changes: 14 additions & 4 deletions src/workflows/workflow.js
Expand Up @@ -33,7 +33,7 @@ export class Workflow extends BaseWorkflow {
this._UnitFactory = UnitFactory;
this._Workflow = Workflow;
this._MapUnit = MapUnit;
if (!config.skipInitialize) this.initialize();
if (!config.skipInitialize) this.initialize(config.extraConfig);
}

// TODO: figure out how to avoid circular dependency on import in the platform webapp and re-enable or remove
Expand All @@ -44,12 +44,16 @@ export class Workflow extends BaseWorkflow {
// }
// }

initialize() {
initialize(extraConfig) {
const me = this;
this._subworkflows = this.prop("subworkflows").map((x) => new me._Subworkflow(x));
this._subworkflows = this.prop("subworkflows").map(
(x) => new me._Subworkflow({ ...x, extraConfig }),
);
this._units = this.prop("units").map((unit) => me._UnitFactory.create(unit));
this._json.workflows = this._json.workflows || [];
this._workflows = this.prop("workflows").map((x) => new me._Workflow(x));
this._workflows = this.prop("workflows").map(
(x) => new me._Workflow({ ...x, extraConfig }),
);
}

static get defaultConfig() {
Expand Down Expand Up @@ -347,4 +351,10 @@ export class Workflow extends BaseWorkflow {
};
return calculateHashFromObject(meaningfulFields);
}

initializeMethodData(extraConfig) {
if (!extraConfig) return;
this.subworkflows.map((sw) => sw.initializeMethodData(extraConfig));
this.workflows.map((wf) => wf.initializeMethodData(extraConfig));
}
}