Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
69b56e2
chore: use dotfile for mocha
azech-hqs Oct 23, 2023
44175b9
update: enable typescript
azech-hqs Oct 23, 2023
11c7bdf
chore: move model interface from web-app
azech-hqs Oct 23, 2023
26947e5
chore: inherit from defaultabe in-memory entity
azech-hqs Oct 23, 2023
01d76c7
chore: add mui-path-imports eslint plugin
azech-hqs Oct 23, 2023
8423eb1
update: add application-flavor package
azech-hqs Oct 23, 2023
6207882
chore: adjust imports of modelinterface
azech-hqs Oct 24, 2023
8586512
refactor: remove model tree from model class
azech-hqs Oct 24, 2023
5bd029a
update: inherit from defaultable in-memory entity
azech-hqs Oct 24, 2023
c4e182f
refactor: move slug related functions to utils
azech-hqs Oct 24, 2023
e5d9311
chore: add typescript + utils
azech-hqs Oct 24, 2023
864237a
chore: fix mocha settings
azech-hqs Oct 24, 2023
0e652ee
chore: remove redundant mixwith package
azech-hqs Oct 24, 2023
1179945
refactor: isolate filtering the model list
azech-hqs Oct 24, 2023
a3611a9
refactor: replace slug method with utils
azech-hqs Oct 24, 2023
3b672ff
update: get default config from model list
azech-hqs Oct 24, 2023
d7c090f
test: default functional of dft model
azech-hqs Oct 24, 2023
0c0fdeb
docs: add docstring to getCategorizedModels()
azech-hqs Oct 24, 2023
9ea2848
chore: use explicit import for lodash
azech-hqs Oct 25, 2023
a640a65
chore: remove UI-related functions
azech-hqs Oct 25, 2023
4e7e622
chore: add separate instance method for default config
azech-hqs Oct 25, 2023
1146919
chore: avoid recursion in default getters
azech-hqs Oct 25, 2023
b35e192
refactor: replace tree in model factory
azech-hqs Oct 25, 2023
a4e6620
test: create dft model via factory
azech-hqs Oct 25, 2023
110b9f8
codejs++: use 2023.10.24-0
azech-hqs Oct 25, 2023
ddbdfc7
appl-flavors++: use chore/SOF-6991
azech-hqs Oct 25, 2023
81e9d6d
chore: fix create from application
azech-hqs Oct 25, 2023
00916a3
test: create dft model from application
azech-hqs Oct 25, 2023
4daaf55
test: move model test to typescript
azech-hqs Oct 25, 2023
abc1a68
update: use model interface of chore/SOF-6706
azech-hqs Oct 25, 2023
d358815
update: add method interface
azech-hqs Oct 25, 2023
0aee1ae
update: create default method from model+application
azech-hqs Oct 25, 2023
a38e379
test: verify method type for default dft model
azech-hqs Oct 25, 2023
2ccecce
refactor: use lodash for sortby util
azech-hqs Oct 25, 2023
c7ffe04
style: remove redundant comment
azech-hqs Oct 25, 2023
dd31530
chore: add method filter functions to interface
azech-hqs Oct 26, 2023
c830a31
chore: remove unused functions
azech-hqs Oct 26, 2023
6026e7e
refactor: move default_models to typescript
azech-hqs Oct 26, 2023
6ee7c07
refactor: move default_methods to typescript
azech-hqs Oct 26, 2023
d76c4c3
refactor: remove model tree
azech-hqs Oct 26, 2023
46019aa
refactor: move filter functions to separate file
azech-hqs Oct 26, 2023
4183b68
update: add filter function to model interface
azech-hqs Oct 26, 2023
4801e84
refactor: use filter functions from interfaces
azech-hqs Oct 26, 2023
8b3c3c7
chore: add safeguards for undefined params
azech-hqs Oct 26, 2023
dce6f12
chore: re-implement tree utility functions
azech-hqs Oct 26, 2023
a2499d5
test: verify tree utility functions
azech-hqs Oct 26, 2023
1f1b629
chore: add tsconfig to files
azech-hqs Oct 26, 2023
df5b849
update: adjust tree utility functions based on model list
azech-hqs Oct 26, 2023
32d1b8a
test: verify tree utility functions II
azech-hqs Oct 26, 2023
70a605d
chore: assume model without method in interface
azech-hqs Oct 26, 2023
fdbdc7d
update: handle unknown model case
azech-hqs Oct 26, 2023
fe962bb
test: unknown model is created correctly
azech-hqs Oct 26, 2023
a2d989c
chore: handle undefined functional case
azech-hqs Oct 26, 2023
606b1cd
codejs++: use chore/SOF-6991
azech-hqs Oct 27, 2023
110e53a
appl-flavors++: update chore/SOF-6991
azech-hqs Oct 27, 2023
5c6b47e
test: default models for applications
azech-hqs Oct 27, 2023
2383514
chore: return legacy model if no application
azech-hqs Oct 27, 2023
36851f7
refactor: move tree.js to typescript
azech-hqs Oct 27, 2023
e21ba6e
test: default dft model + group slug
azech-hqs Oct 27, 2023
cb5b68e
chore: handle case of functional as string
azech-hqs Oct 27, 2023
1c5655a
chore: add plugin for typescript imports
azech-hqs Oct 27, 2023
2c87456
test: functional as slugifiedEntry
azech-hqs Oct 27, 2023
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
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
}
],
"@babel/preset-react",
"@babel/preset-typescript"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you split this PR to two: 1) changes for removing model interface; 2) typescript, please? We'll take care of the 2) later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New PR (only JS) here: #35

],
"plugins": [
"@babel/plugin-proposal-class-properties"
Expand Down
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"extends": ["@exabyte-io/eslint-config"]
"extends": [
"@exabyte-io/eslint-config",
"plugin:import/typescript"
]
}

5 changes: 5 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extension": ["ts", "js"],
"spec": "tests/**/*.test.*",
"require": ["ts-node/register"]
}
866 changes: 831 additions & 35 deletions package-lock.json

Large diffs are not rendered by default.

33 changes: 24 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "0.0.0",
"description": "MOdel and method DEfinitions",
"scripts": {
"test": "nyc --reporter=text mocha --recursive --bail --require @babel/register/lib --require tests/setup.js tests",
"test": "mocha",
"lint": "eslint src tests && prettier --write src tests",
"lint:fix": "eslint --fix --cache src tests && prettier --write src tests",
"build:assets": "node build_entities.js && node build_filter.js",
"transpile": "babel --out-dir dist src",
"transpile": "tsc",
"postinstall": "npm run transpile",
"prettier": "prettier --check src tests",
"prepare": "husky install || exit 0"
Expand All @@ -23,7 +23,8 @@
"/src",
".babelrc",
"build_entities.js",
"build_filter.js"
"build_filter.js",
"tsconfig.json"
],
"author": "Exabyte Inc.",
"bugs": {
Expand All @@ -38,46 +39,60 @@
"@babel/plugin-proposal-class-properties": "7.16.0",
"@babel/preset-env": "7.16.4",
"@babel/preset-react": "7.16.7",
"@babel/preset-typescript": "^7.22.5",
"@babel/register": "^7.16.0",
"@babel/runtime-corejs3": "7.16.8",
"ajv": "4.1.7",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"mixwith": "^0.1.1",
"underscore": "^1.13.3",
"underscore.string": "^3.3.4"
},
"devDependencies": {
"@exabyte-io/code.js": "2023.9.14-1",
"@exabyte-io/eslint-config": "^2022.11.17-0",
"@babel/preset-typescript": "^7.22.5",
"@exabyte-io/application-flavors.js": "git+https://github.com/Exabyte-io/application-flavors.git#b3de5b1111d5f1300fe97cd6483265ac28640466",
"@exabyte-io/code.js": "git+https://github.com/Exabyte-io/code.js.git#b94c987f98d620790466cefc04ba354395a1c62d",
"@exabyte-io/eslint-config": "^2023.8.29-1",
"@exabyte-io/made.js": "2022.6.15-0",
"@types/chai": "^4.3.5",
"@types/js-yaml": "^4.0.5",
"@types/mocha": "^10.0.1",
"@types/node": "^20.4.2",
"@types/underscore": "^1.11.6",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"chai": "^4.3.4",
"eslint": "7.32.0",
"eslint-config-airbnb": "19.0.2",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-exports": "^1.0.0-beta.2",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "2.25.3",
"eslint-plugin-jsdoc": "37.1.0",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-mui-path-imports": "0.0.15",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "7.30.0",
"eslint-plugin-simple-import-sort": "7.0.0",
"husky": "^7.0.4",
"lint-staged": "^12.1.2",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"prettier": "^2.7.1"
"prettier": "^2.7.1",
"ts-node": "^10.9.1",
"typescript": "^4.5.5"
},
"peerDependencies": {
"@exabyte-io/ade.js": "*",
"@exabyte-io/application-flavors.js": "*",
"@exabyte-io/code.js": "*",
"@exabyte-io/made.js": "*"
},
"engines": {
"node": ">=12.0.0"
},
"lint-staged": {
"*.js": "eslint --cache --fix",
"*.{js,css}": "prettier --write"
"*.{js,ts}": "eslint --cache --fix",
"*.{js,ts,css}": "prettier --write"
}
}
38 changes: 0 additions & 38 deletions src/default_methods.js

This file was deleted.

20 changes: 20 additions & 0 deletions src/default_methods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
LegacyMethodLocalorbital,
LegacyMethodPseudopotential,
LegacyMethodUnknown,
} from "@exabyte-io/code.js/dist/types";

export const PseudopotentialMethodConfig: LegacyMethodPseudopotential = {
type: "pseudopotential",
subtype: "us",
};

export const LocalOrbitalMethodConfig: LegacyMethodLocalorbital = {
type: "localorbital",
subtype: "pople",
};

export const UnknownMethodConfig: LegacyMethodUnknown = {
type: "unknown",
subtype: "unknown",
};
9 changes: 0 additions & 9 deletions src/default_models.js

This file was deleted.

14 changes: 14 additions & 0 deletions src/default_models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {
LegacyModelDensityFunctionalTheory,
LegacyModelUnknown,
} from "@exabyte-io/code.js/dist/types";

export const DFTModelConfig: Omit<LegacyModelDensityFunctionalTheory, "method"> = {
type: "dft",
subtype: "gga",
};

export const UnknownModelConfig: Omit<LegacyModelUnknown, "method"> = {
type: "unknown",
subtype: "unknown",
};
62 changes: 62 additions & 0 deletions src/filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { filterEntityList, mergeTerminalNodes } from "@exabyte-io/code.js/dist/utils";
import lodash from "lodash";

import modelMethodMap from "./data/model_method_map";

function safelyGet(obj, ...args) {
return lodash.get(obj, args, undefined);
}

/**
* Create list of filter objects based on model categories.
* @param {Object} filterTree - filter tree constructed from assets
* @param {string} tier1 - Level 1 tier
* @param {string} tier2 - Level 2 tier
* @param {string} tier3 - Level 3 tier
* @param {string} type - Type
* @param {string} subtype - Subtype
* @return {*[]}
*/
function getMethodFilterObjects({ filterTree, tier1, tier2, tier3, type, subtype }) {
let filterList;
if (!tier1) {
filterList = mergeTerminalNodes(filterTree);
} else if (!tier2) {
filterList = mergeTerminalNodes(safelyGet(filterTree, tier1));
} else if (!tier3) {
filterList = mergeTerminalNodes(safelyGet(filterTree, tier1, tier2));
} else if (!type) {
filterList = mergeTerminalNodes(safelyGet(filterTree, tier1, tier2, tier3));
} else if (!subtype) {
filterList = mergeTerminalNodes(safelyGet(filterTree, tier1, tier2, tier3, type));
} else {
filterList = safelyGet(filterTree, tier1, tier2, tier3, type, subtype);
}
const extractUniqueBy = (name) => {
return lodash
.chain(filterList)
.filter(Boolean)
.filter((o) => Boolean(o[name]))
.uniqBy(name)
.value();
};

return [].concat(extractUniqueBy("path"), extractUniqueBy("regex"));
}

/**
* Filter list of method configs based on model
* @param {Object[]} methodList - Array of method configs
* @param {Object} model - Model config for which methods should be filtered
* @return {Object[]}
*/
export function filterMethodsByModel({ methodList, model }) {
if (!model) return [];
const { categories } = model;
const filterObjects = getMethodFilterObjects({ filterTree: modelMethodMap, ...categories });
return filterEntityList({
entitiesOrPaths: methodList,
filterObjects,
multiPathSeparator: "::",
});
}
9 changes: 5 additions & 4 deletions src/method.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { InMemoryEntity } from "@exabyte-io/code.js/dist/entity";
import { DefaultableInMemoryEntity } from "@exabyte-io/code.js/dist/entity";
import { deepClone } from "@exabyte-io/code.js/dist/utils";
import lodash from "lodash";
import isEmpty from "lodash/isEmpty";
import omit from "lodash/omit";

import { PseudopotentialMethodConfig } from "./default_methods";

export class Method extends InMemoryEntity {
export class Method extends DefaultableInMemoryEntity {
constructor(config) {
const data = config.data || {};
super({ ...config, data });
Expand Down Expand Up @@ -57,7 +58,7 @@ export class Method extends InMemoryEntity {

get omitInHashCalculation() {
const data = this.prop("data");
return !data.searchText && lodash.isEmpty(lodash.omit(data, "searchText"));
return !data.searchText && isEmpty(omit(data, "searchText"));
}

// data without client-only fields
Expand Down
6 changes: 3 additions & 3 deletions src/methods/pseudopotential.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { safeMakeArray } from "@exabyte-io/code.js/dist/utils";
import _ from "underscore";
import sortBy from "lodash/sortBy";

import { Method } from "../method";

Expand Down Expand Up @@ -71,7 +71,7 @@ export class PseudopotentialMethod extends Method {
// sort by alphabetical order to ensure elements order consistency in VASP POSCAR/POTCAR
this.setData({
...this.data,
pseudo: _.sortBy(pseudopotentials, "element").map((x) => x.toJSON()),
pseudo: sortBy(pseudopotentials, ["element"]).map((x) => x.toJSON()),
});
}

Expand All @@ -82,7 +82,7 @@ export class PseudopotentialMethod extends Method {
// sort by alphabetical order to ensure elements order consistency in VASP POSCAR/POTCAR
this.setData({
...this.data,
allPseudo: _.sortBy(pseudopotentials, "element").map((x) => x.toJSON()),
allPseudo: sortBy(pseudopotentials, ["element"]).map((x) => x.toJSON()),
});
}

Expand Down
Loading