Skip to content

Commit

Permalink
fix: prettier reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
unsigned6 committed Nov 17, 2022
1 parent 91a974f commit 9115b2d
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 221 deletions.
215 changes: 109 additions & 106 deletions src/subworkflows/convergence.js
Original file line number Diff line number Diff line change
@@ -1,122 +1,125 @@
import { UNIT_TYPES } from "../enums";

export const ConvergenceMixin = (superclass) => class extends superclass {
addConvergence({
parameter,
parameterInitial,
result,
resultInitial,
condition,
operator,
tolerance,
maxOccurrences,
}) {
// RF: added TODO comments for future improvements
export const ConvergenceMixin = (superclass) =>
class extends superclass {
addConvergence({
parameter,
parameterInitial,
result,
resultInitial,
condition,
operator,
tolerance,
maxOccurrences,
}) {
// RF: added TODO comments for future improvements

const { units } = this;
// Find unit to converge: should contain passed result in its results list
// TODO: make user to select unit for convergence explicitly
const unitForConvergence = units.find((x) => x.resultNames.find((name) => name === result));
const { units } = this;
// Find unit to converge: should contain passed result in its results list
// TODO: make user to select unit for convergence explicitly
const unitForConvergence = units.find((x) =>
x.resultNames.find((name) => name === result),
);

if (!unitForConvergence) {
// eslint-disable-next-line no-undef
sAlert.error(
if (!unitForConvergence) {
// eslint-disable-next-line no-undef
sAlert.error(
`Subworkflow does not contain unit with '${result}' as extracted property.`,
);
throw new Error("There is no result to converge");
}
);
throw new Error("There is no result to converge");
}

// Replace kgrid to be ready for convergence
// TODO: kgrid should be abstracted and selected by user
unitForConvergence.updateContext({
kgrid: {
dimensions: [`{{${parameter}}}`, `{{${parameter}}}`, `{{${parameter}}}`],
shifts: [0, 0, 0],
},
isKgridEdited: true,
isUsingJinjaVariables: true,
});
// Replace kgrid to be ready for convergence
// TODO: kgrid should be abstracted and selected by user
unitForConvergence.updateContext({
kgrid: {
dimensions: [`{{${parameter}}}`, `{{${parameter}}}`, `{{${parameter}}}`],
shifts: [0, 0, 0],
},
isKgridEdited: true,
isUsingJinjaVariables: true,
});

const prevResult = "prev_result";
const prevResult = "prev_result";

// Assignment with result's initial value
const prevResultInit = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
head: true,
operand: prevResult,
value: resultInitial,
});
// Assignment with result's initial value
const prevResultInit = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
head: true,
operand: prevResult,
value: resultInitial,
});

// Assignment with initial value of convergence parameter
const paramInit = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
operand: parameter,
value: parameterInitial,
});
// Assignment with initial value of convergence parameter
const paramInit = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
operand: parameter,
value: parameterInitial,
});

// Assignment for storing iteration result: extracts 'result' from convergence unit scope
const storePrevResult = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
input: [
{
scope: unitForConvergence.flowchartId,
name: result,
},
],
operand: prevResult,
value: result,
});
// Assignment for storing iteration result: extracts 'result' from convergence unit scope
const storePrevResult = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
input: [
{
scope: unitForConvergence.flowchartId,
name: result,
},
],
operand: prevResult,
value: result,
});

// Assignment for convergence param increase
const nextStep = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
input: [],
operand: parameter,
value: `${parameter} + 1`,
next: unitForConvergence.flowchartId,
});
// Assignment for convergence param increase
const nextStep = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
input: [],
operand: parameter,
value: `${parameter} + 1`,
next: unitForConvergence.flowchartId,
});

// Final step of convergence
const exit = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
name: "exit",
input: [],
operand: parameter,
value: `${parameter} + 0`,
});
// Final step of convergence
const exit = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
name: "exit",
input: [],
operand: parameter,
value: `${parameter} + 0`,
});

// Final step of convergence
const storeResult = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
input: [
{
scope: unitForConvergence.flowchartId,
name: result,
},
],
operand: result,
value: result,
});
// Final step of convergence
const storeResult = this._UnitFactory.create({
type: UNIT_TYPES.assignment,
input: [
{
scope: unitForConvergence.flowchartId,
name: result,
},
],
operand: result,
value: result,
});

// Convergence condition unit
const conditionUnit = this._UnitFactory.create({
type: UNIT_TYPES.condition,
statement: `${condition} ${operator} ${tolerance}`,
then: exit.flowchartId,
else: storePrevResult.flowchartId,
maxOccurrences,
next: storePrevResult.flowchartId,
});
// Convergence condition unit
const conditionUnit = this._UnitFactory.create({
type: UNIT_TYPES.condition,
statement: `${condition} ${operator} ${tolerance}`,
then: exit.flowchartId,
else: storePrevResult.flowchartId,
maxOccurrences,
next: storePrevResult.flowchartId,
});

this.addUnit(prevResultInit, true);
this.addUnit(paramInit, true);
this.addUnit(storeResult);
this.addUnit(conditionUnit);
this.addUnit(storePrevResult);
this.addUnit(nextStep);
this.addUnit(exit);
this.addUnit(prevResultInit, true);
this.addUnit(paramInit, true);
this.addUnit(storeResult);
this.addUnit(conditionUnit);
this.addUnit(storePrevResult);
this.addUnit(nextStep);
this.addUnit(exit);

// `addUnit` adjusts the `next` field, hence the below.
nextStep.next = unitForConvergence.flowchartId;
}
};
// `addUnit` adjusts the `next` field, hence the below.
nextStep.next = unitForConvergence.flowchartId;
}
};
25 changes: 9 additions & 16 deletions src/subworkflows/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ function createMethod({ config, methodFactoryCls }) {
* @param methodFactoryCls {any} method factory class
* @returns {{application: *, method: *, model: (DFTModel|Model), setSearchText: String|null}}
*/
function createTopLevel({
subworkflowData, applicationCls, modelFactoryCls, methodFactoryCls,
}) {
function createTopLevel({ subworkflowData, applicationCls, modelFactoryCls, methodFactoryCls }) {
const { application: appConfig, model: modelConfig, method: methodConfig } = subworkflowData;
const application = createApplication({ config: appConfig, applicationCls });
const model = createModel({ config: modelConfig, modelFactoryCls });
const { method, setSearchText } = createMethod({ config: methodConfig, methodFactoryCls });
return {
application, model, method, setSearchText,
application,
model,
method,
setSearchText,
};
}

Expand All @@ -90,14 +91,10 @@ function createTopLevel({
* @param unitFactoryCls {*} workflow unit class factory
* @returns {*|{head: boolean, preProcessors: [], postProcessors: [], name: *, flowchartId: *, type: *, results: [], monitors: []}}
*/
function createUnit({
config, application, unitBuilders, unitFactoryCls,
}) {
function createUnit({ config, application, unitBuilders, unitFactoryCls }) {
const { type, config: unitConfig } = config;
if (type === "executionBuilder") {
const {
name, execName, flavorName, flowchartId,
} = unitConfig;
const { name, execName, flavorName, flowchartId } = unitConfig;
const builder = new unitBuilders.ExecutionUnitConfigBuilder(
name,
application,
Expand Down Expand Up @@ -153,19 +150,15 @@ function createSubworkflow({
unitFactoryCls = UnitFactory,
unitBuilders = builders,
}) {
const {
application, model, method, setSearchText,
} = createTopLevel({
const { application, model, method, setSearchText } = createTopLevel({
subworkflowData,
applicationCls,
modelFactoryCls,
methodFactoryCls,
});

let units = [];
const {
name, units: unitConfigs, config = {}, dynamicSubworkflow = null,
} = subworkflowData;
const { name, units: unitConfigs, config = {}, dynamicSubworkflow = null } = subworkflowData;
unitConfigs.forEach((_config) => {
units.push(
createUnit({
Expand Down
12 changes: 7 additions & 5 deletions src/subworkflows/dynamic/espresso/getQpointIrrep.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import { UNIT_TYPES } from "../../../enums";
function getQpointIrrep({ unitBuilders, unitFactoryCls, application }) {
const { ExecutionUnitConfigBuilder } = unitBuilders;

const pythonUnit = new ExecutionUnitConfigBuilder("python", application, "python", "espresso_xml_get_qpt_irr").build();
const pythonUnit = new ExecutionUnitConfigBuilder(
"python",
application,
"python",
"espresso_xml_get_qpt_irr",
).build();

const assignmentUnit = unitFactoryCls.create({
type: UNIT_TYPES.assignment,
Expand All @@ -24,10 +29,7 @@ function getQpointIrrep({ unitBuilders, unitFactoryCls, application }) {
value: "json.loads(STDOUT)",
});

return [
pythonUnit,
assignmentUnit,
];
return [pythonUnit, assignmentUnit];
}

export { getQpointIrrep };
5 changes: 1 addition & 4 deletions src/subworkflows/dynamic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ const dynamicSubworkflowsByApp = {
espresso: { getQpointIrrep },
};

export {
getSurfaceEnergySubworkflowUnits,
dynamicSubworkflowsByApp,
};
export { getSurfaceEnergySubworkflowUnits, dynamicSubworkflowsByApp };
Loading

0 comments on commit 9115b2d

Please sign in to comment.