@datagrok/compute 1.44.1 → 1.44.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/148.js.map +1 -1
- package/dist/377.js.map +1 -1
- package/dist/44.js +1 -1
- package/dist/44.js.map +1 -1
- package/dist/package-test.js +1 -1
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +3 -2
- package/src/package.g.ts +140 -0
- package/src/package.ts +327 -287
- package/webpack.config.js +65 -50
package/src/package.ts
CHANGED
|
@@ -17,56 +17,46 @@ import {
|
|
|
17
17
|
makeValidationResult as makeValidationResultInst,
|
|
18
18
|
makeRevalidation as makeRevalidationInst,
|
|
19
19
|
mergeValidationResults as mergeValidationResultsInst,
|
|
20
|
-
} from '@datagrok-libraries/compute-utils
|
|
21
|
-
import {ModelCatalogView,
|
|
20
|
+
} from '@datagrok-libraries/compute-utils';
|
|
21
|
+
import {ModelCatalogView,
|
|
22
|
+
ModelHandler,
|
|
23
|
+
startModelCatalog,
|
|
24
|
+
makeModelTreeBrowser,
|
|
25
|
+
renderRestPanel,
|
|
26
|
+
setModelCatalogEventHandlers,
|
|
27
|
+
setModelCatalogHandler} from '@datagrok-libraries/compute-utils/model-catalog';
|
|
22
28
|
import {
|
|
23
29
|
testPipeline as testPipelineInst,
|
|
24
|
-
} from '@datagrok-libraries/compute-utils
|
|
30
|
+
} from '@datagrok-libraries/compute-utils';
|
|
31
|
+
import {
|
|
32
|
+
deepCopy as deepCopyInst,
|
|
33
|
+
} from '@datagrok-libraries/compute-utils';
|
|
25
34
|
|
|
26
|
-
import {FittingView} from '@datagrok-libraries/compute-utils/function-views/src/fitting-view';
|
|
27
35
|
|
|
36
|
+
import {FittingView} from '@datagrok-libraries/compute-utils/function-views/src/fitting-view';
|
|
37
|
+
export * from './package.g';
|
|
28
38
|
export const _package = new DG.Package();
|
|
29
39
|
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
export
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
//tags: editor
|
|
46
|
-
//input: funccall call
|
|
47
|
-
//output: view result
|
|
48
|
-
export function RichFunctionViewEditor(call: DG.FuncCall) {
|
|
49
|
-
return RichFunctionViewInst.fromFuncCall(call, {historyEnabled: true, isTabbed: false});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
//name: PipelineStepEditor
|
|
53
|
-
//tags: editor
|
|
54
|
-
//input: funccall call
|
|
55
|
-
//output: view result
|
|
56
|
-
export function PipelineStepEditor(call: DG.FuncCall) {
|
|
57
|
-
return RichFunctionViewInst.fromFuncCall(call, {historyEnabled: false, isTabbed: true});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
//name: renderRestPanel
|
|
61
|
-
//input: func func
|
|
62
|
-
//output: widget panel
|
|
63
|
-
export async function renderPanel(func: DG.Func): Promise<DG.Widget> {
|
|
64
|
-
return renderRestPanel(func);
|
|
65
|
-
}
|
|
40
|
+
// for compute-api pakage
|
|
41
|
+
export const testPipeline = testPipelineInst;
|
|
42
|
+
export const deepCopy = deepCopyInst;
|
|
43
|
+
export const CompView = ComputationViewInst;
|
|
44
|
+
export const RFV = RichFunctionViewInst;
|
|
45
|
+
export const CFV = CustomFunctionViewInst;
|
|
46
|
+
export const Pipeline = PipelineViewInst;
|
|
47
|
+
export const makeValidationResult = makeValidationResultInst;
|
|
48
|
+
export const makeAdvice = makeAdviceInst;
|
|
49
|
+
export const makeRevalidation = makeRevalidationInst;
|
|
50
|
+
export const mergeValidationResults = mergeValidationResultsInst;
|
|
51
|
+
export const fileInput = UiUtils.fileInput;
|
|
52
|
+
export const historyInput = UiUtils.historyInput;
|
|
53
|
+
export const historyInputJSON = UiUtils.historyInputJSON;
|
|
54
|
+
export const historyPanel = UiUtils.historyPanel;
|
|
66
55
|
|
|
67
56
|
let startUriLoaded = false;
|
|
68
57
|
let initCompleted = false;
|
|
69
58
|
|
|
59
|
+
|
|
70
60
|
const options = {
|
|
71
61
|
_package,
|
|
72
62
|
ViewClass: ModelCatalogView,
|
|
@@ -77,283 +67,333 @@ const options = {
|
|
|
77
67
|
getStartUriLoaded: () => startUriLoaded,
|
|
78
68
|
};
|
|
79
69
|
|
|
80
|
-
//tags: init
|
|
81
|
-
export function init() {
|
|
82
|
-
if (initCompleted)
|
|
83
|
-
return;
|
|
84
70
|
|
|
85
|
-
|
|
86
|
-
|
|
71
|
+
export class PackageFunctions {
|
|
72
|
+
@grok.decorators.func()
|
|
73
|
+
static openModelFromFuncall(funccall: DG.FuncCall) {
|
|
74
|
+
ModelHandler.openModelFromFunccall(funccall as any);
|
|
75
|
+
}
|
|
87
76
|
|
|
88
|
-
initCompleted = true;
|
|
89
|
-
}
|
|
90
77
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
78
|
+
@grok.decorators.func({
|
|
79
|
+
tags: ['viewer'],
|
|
80
|
+
name: 'OutliersSelectionViewer',
|
|
81
|
+
description: 'Creates an outliers selection viewer',
|
|
82
|
+
outputs: [{type: 'viewer', name: 'result'}],
|
|
83
|
+
})
|
|
84
|
+
static OutliersSelection() {
|
|
85
|
+
return new OutliersSelectionViewer();
|
|
86
|
+
}
|
|
98
87
|
|
|
99
|
-
//input: dynamic treeNode
|
|
100
|
-
//input: view browseView
|
|
101
|
-
export function modelCatalogTreeBrowser(treeNode: DG.TreeViewGroup) {
|
|
102
|
-
makeModelTreeBrowser(treeNode);
|
|
103
|
-
}
|
|
104
88
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
89
|
+
@grok.decorators.editor({outputs: [{type: 'view', name: 'result'}]})
|
|
90
|
+
static RichFunctionViewEditor(call: DG.FuncCall) {
|
|
91
|
+
return RichFunctionViewInst.fromFuncCall(call as any, {historyEnabled: true, isTabbed: false});
|
|
92
|
+
}
|
|
108
93
|
|
|
109
|
-
export const testPipeline = testPipelineInst;
|
|
110
|
-
export const CompView = ComputationViewInst;
|
|
111
|
-
export const RFV = RichFunctionViewInst;
|
|
112
|
-
export const CFV = CustomFunctionViewInst;
|
|
113
|
-
export const Pipeline = PipelineViewInst;
|
|
114
|
-
export const makeValidationResult = makeValidationResultInst;
|
|
115
|
-
export const makeAdvice = makeAdviceInst;
|
|
116
|
-
export const makeRevalidation = makeRevalidationInst;
|
|
117
|
-
export const mergeValidationResults = mergeValidationResultsInst;
|
|
118
|
-
export const fileInput = UiUtils.fileInput;
|
|
119
|
-
export const historyInput = UiUtils.historyInput;
|
|
120
|
-
export const historyInputJSON = UiUtils.historyInputJSON;
|
|
121
|
-
export const historyPanel = UiUtils.historyPanel;
|
|
122
94
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
95
|
+
@grok.decorators.editor({outputs: [{type: 'view', name: 'result'}]})
|
|
96
|
+
static PipelineStepEditor(call: DG.FuncCall) {
|
|
97
|
+
return RichFunctionViewInst.fromFuncCall(call as any, {historyEnabled: false, isTabbed: true});
|
|
98
|
+
}
|
|
126
99
|
|
|
127
100
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
101
|
+
@grok.decorators.func({name: 'renderRestPanel'})
|
|
102
|
+
static async renderPanel(@grok.decorators.param({type: 'func'}) func: DG.Func) : Promise<DG.Widget> {
|
|
103
|
+
return renderRestPanel(func as any) as any;
|
|
104
|
+
}
|
|
131
105
|
|
|
106
|
+
@grok.decorators.init()
|
|
107
|
+
static init() {
|
|
108
|
+
if (initCompleted)
|
|
109
|
+
return;
|
|
132
110
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
//output: object uploadedCalls
|
|
136
|
-
export async function CustomDataUploader(func: DG.Func) {
|
|
137
|
-
await new Promise((r) => setTimeout(r, 1000));
|
|
111
|
+
setModelCatalogHandler();
|
|
112
|
+
setModelCatalogEventHandlers(options as any);
|
|
138
113
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
'initTemp': 100,
|
|
142
|
-
'desiredTemp': 30,
|
|
143
|
-
'area': 0.06,
|
|
144
|
-
'heatCap': 4200,
|
|
145
|
-
'heatTransferCoeff': 8.3,
|
|
146
|
-
'simTime': 21600,
|
|
147
|
-
}).call();
|
|
114
|
+
initCompleted = true;
|
|
115
|
+
}
|
|
148
116
|
|
|
149
|
-
return [dummyFunccall];
|
|
150
|
-
}
|
|
151
117
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const dummyWidget = DG.Widget.fromRoot(ui.panel([ui.divV([
|
|
162
|
-
ui.label('This part of dialog comes from my custom data uploader'),
|
|
163
|
-
ui.divH([uploadBtn], {style: {justifyContent: 'center'}}),
|
|
164
|
-
])]));
|
|
165
|
-
|
|
166
|
-
const setLoadingSub = grok.functions.onBeforeRunAction.pipe(
|
|
167
|
-
filter((call) => call.id === uploadFuncCall.id),
|
|
168
|
-
).subscribe(() => {
|
|
169
|
-
ui.setUpdateIndicator(uploadBtn, true);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
const unsetLoadingSub = grok.functions.onAfterRunAction.pipe(
|
|
173
|
-
filter((call) => call.id === uploadFuncCall.id),
|
|
174
|
-
).subscribe(() => {
|
|
175
|
-
ui.setUpdateIndicator(uploadBtn, false);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
dummyWidget.subs.push(setLoadingSub, unsetLoadingSub);
|
|
179
|
-
|
|
180
|
-
return {uploadWidget: dummyWidget, uploadFuncCall};
|
|
181
|
-
}
|
|
118
|
+
@grok.decorators.app({
|
|
119
|
+
browsePath: 'Compute',
|
|
120
|
+
name: 'Model Hub',
|
|
121
|
+
outputs: [{type: 'view', name: 'result'}],
|
|
122
|
+
})
|
|
123
|
+
static modelCatalog() {
|
|
124
|
+
return startModelCatalog(options as any);
|
|
125
|
+
}
|
|
182
126
|
|
|
183
|
-
//name: CustomCustomizer
|
|
184
|
-
//input: object params
|
|
185
|
-
export function CustomCustomizer(params: {defaultView: DG.TableView}) {
|
|
186
|
-
const comparisonView = params.defaultView;
|
|
187
|
-
comparisonView.scatterPlot({
|
|
188
|
-
'xColumnName': 'Initial temperature',
|
|
189
|
-
'yColumnName': 'Time to cool',
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
127
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return makeValidationResultInst({
|
|
200
|
-
warnings: val < reasonableMin || val > reasonableMax ? [`Minimum reasonable time is ${reasonableMin}. Maximum reasonable time is ${reasonableMax}`]: undefined,
|
|
201
|
-
errors: val < 0 ? [`Time should be strictly positive`]: undefined,
|
|
202
|
-
});
|
|
203
|
-
};
|
|
204
|
-
}
|
|
128
|
+
@grok.decorators.func({
|
|
129
|
+
meta: { role: ' ', app: ' '}
|
|
130
|
+
})
|
|
131
|
+
static modelCatalogTreeBrowser(treeNode: DG.TreeViewGroup, browseView: DG.ViewBase) {
|
|
132
|
+
makeModelTreeBrowser(treeNode as any);
|
|
133
|
+
}
|
|
205
134
|
|
|
206
|
-
//
|
|
207
|
-
//
|
|
208
|
-
//
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
135
|
+
//
|
|
136
|
+
// Testing code
|
|
137
|
+
//
|
|
138
|
+
|
|
139
|
+
@grok.decorators.func({outputs: [{type: 'object', name: 'uploadedCalls'}]})
|
|
140
|
+
static async CustomDataUploader(func: DG.Func) {
|
|
141
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
142
|
+
|
|
143
|
+
const dummyFunccall = await func.prepare({
|
|
144
|
+
'ambTemp': 22,
|
|
145
|
+
'initTemp': 100,
|
|
146
|
+
'desiredTemp': 30,
|
|
147
|
+
'area': 0.06,
|
|
148
|
+
'heatCap': 4200,
|
|
149
|
+
'heatTransferCoeff': 8.3,
|
|
150
|
+
'simTime': 21600,
|
|
151
|
+
}).call();
|
|
152
|
+
|
|
153
|
+
return [dummyFunccall];
|
|
154
|
+
}
|
|
223
155
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
156
|
+
|
|
157
|
+
@grok.decorators.func({
|
|
158
|
+
outputs: [
|
|
159
|
+
{
|
|
160
|
+
name: 'uploadWidget',
|
|
161
|
+
type: 'widget',
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: 'uploadFuncCall',
|
|
165
|
+
type: 'funccall',
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
})
|
|
169
|
+
static async CustomUploader(
|
|
170
|
+
@grok.decorators.param({type: 'object'}) params: {func: DG.Func}) {
|
|
171
|
+
const uploadFunc = await grok.functions.eval('Compute:CustomDataUploader') as DG.Func;
|
|
172
|
+
const uploadFuncCall = uploadFunc.prepare({func: params.func});
|
|
173
|
+
const uploadBtn = ui.bigButton('Click me to get mock calls', () => uploadFuncCall.call());
|
|
174
|
+
|
|
175
|
+
const dummyWidget = DG.Widget.fromRoot(ui.panel([ui.divV([
|
|
176
|
+
ui.label('This part of dialog comes from my custom data uploader'),
|
|
177
|
+
ui.divH([uploadBtn], {style: {justifyContent: 'center'}}),
|
|
178
|
+
])]));
|
|
179
|
+
|
|
180
|
+
const setLoadingSub = grok.functions.onBeforeRunAction.pipe(
|
|
181
|
+
filter((call) => call.id === uploadFuncCall.id),
|
|
182
|
+
).subscribe(() => {
|
|
183
|
+
ui.setUpdateIndicator(uploadBtn, true);
|
|
234
184
|
});
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
185
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
return (val: number, info: ValidationInfo) => {
|
|
243
|
-
const initTemp = info.funcCall.inputs['initTemp'];
|
|
244
|
-
return makeValidationResultInst({
|
|
245
|
-
errors: [
|
|
246
|
-
...(val > initTemp) ? [`Ambient temperature cannot be higher than initial temperature (${initTemp})`]: [],
|
|
247
|
-
],
|
|
186
|
+
const unsetLoadingSub = grok.functions.onAfterRunAction.pipe(
|
|
187
|
+
filter((call) => call.id === uploadFuncCall.id),
|
|
188
|
+
).subscribe(() => {
|
|
189
|
+
ui.setUpdateIndicator(uploadBtn, false);
|
|
248
190
|
});
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
191
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
],
|
|
192
|
+
dummyWidget.subs.push(setLoadingSub, unsetLoadingSub);
|
|
193
|
+
|
|
194
|
+
return {uploadWidget: dummyWidget, uploadFuncCall};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
@grok.decorators.func()
|
|
199
|
+
static CustomCustomizer(
|
|
200
|
+
@grok.decorators.param({type: 'object'}) params: {defaultView: DG.TableView}) {
|
|
201
|
+
const comparisonView = params.defaultView;
|
|
202
|
+
comparisonView.scatterPlot({
|
|
203
|
+
'xColumnName': 'Initial temperature',
|
|
204
|
+
'yColumnName': 'Time to cool',
|
|
266
205
|
});
|
|
267
|
-
}
|
|
268
|
-
}
|
|
206
|
+
}
|
|
269
207
|
|
|
270
|
-
//name: CustomStringInput
|
|
271
|
-
//input: object params
|
|
272
|
-
//output: object input
|
|
273
|
-
export function CustomStringInput(params: any) {
|
|
274
|
-
const defaultInput = ui.input.string('Custom input', {value: ''});
|
|
275
|
-
defaultInput.root.style.backgroundColor = 'aqua';
|
|
276
|
-
defaultInput.input.style.backgroundColor = 'aqua';
|
|
277
|
-
return defaultInput;
|
|
278
|
-
}
|
|
279
208
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
209
|
+
@grok.decorators.func({outputs: [{type: 'object', name: 'validator'}]})
|
|
210
|
+
static SimTimeValidator(
|
|
211
|
+
@grok.decorators.param({type: 'object'}) params: any) {
|
|
212
|
+
const {reasonableMin, reasonableMax} = params;
|
|
213
|
+
return (val: number) => {
|
|
214
|
+
return makeValidationResultInst({
|
|
215
|
+
warnings: val < reasonableMin || val > reasonableMax ?
|
|
216
|
+
[`Minimum reasonable time is ${reasonableMin}. Maximum reasonable time is ${reasonableMax}`]: undefined,
|
|
217
|
+
errors: val < 0 ? [`Time should be strictly positive`]: undefined,
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
@grok.decorators.func({outputs: [{type: 'object', name: 'validator'}]})
|
|
224
|
+
static DesiredTempValidator(
|
|
225
|
+
@grok.decorators.param({type: 'object'}) params: any) {
|
|
226
|
+
return (val: number, info: ValidationInfo) => {
|
|
227
|
+
const ambTemp = info.funcCall.inputs['ambTemp'];
|
|
228
|
+
const initTemp = info.funcCall.inputs['initTemp'];
|
|
229
|
+
return makeValidationResultInst({
|
|
230
|
+
errors: [
|
|
231
|
+
...(val < ambTemp) ?
|
|
232
|
+
[makeAdviceInst(`Desired temperature cannot be less than ambient temperature (${ambTemp}). \n`, [
|
|
233
|
+
{actionName: 'Set desired equal to ambient', action: () => info.funcCall.inputs['desiredTemp'] = ambTemp},
|
|
234
|
+
])]: [],
|
|
235
|
+
...(val > initTemp) ? [`Desired temperature cannot be higher than initial temperature (${initTemp})`]: [],
|
|
236
|
+
],
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
}
|
|
289
240
|
|
|
290
|
-
//name: fitTestFunc
|
|
291
|
-
//description: Test for optimization: multiple scalars output
|
|
292
|
-
//input: double x1 = 1 {caption: param1; min: -3; max: 3}
|
|
293
|
-
//input: double x2 = -1 {caption: param2; min: -3; max: 3}
|
|
294
|
-
//input: dataframe y {caption: table}
|
|
295
|
-
//input: bool bool
|
|
296
|
-
//output: int integer
|
|
297
|
-
//output: double float1
|
|
298
|
-
//output: double float2
|
|
299
|
-
//output: dataframe table1 {viewer: Line chart(block: 60) | Grid(block: 40) }
|
|
300
|
-
//output: dataframe table2 {viewer: Line chart(block: 60) | Grid(block: 40) }
|
|
301
|
-
//editor: Compute:RichFunctionViewEditor
|
|
302
|
-
//meta.features: {"fitting": true, "sens-analysis": true}
|
|
303
|
-
//meta.runOnOpen: true
|
|
304
|
-
//meta.runOnInput: true
|
|
305
|
-
export function fitTestFunc(x1: number, x2: number, y: DG.DataFrame, bool: boolean) {
|
|
306
|
-
return {
|
|
307
|
-
integer: x1**3 * (x1 - 1) * x2**3 * (x2 - 1),
|
|
308
|
-
float1: (x2 - 1)**2 + (x1 - 1)**2,
|
|
309
|
-
float2: (x2 - 1)**4 + (x1 - 1)**4,
|
|
310
|
-
table1: DG.DataFrame.fromColumns([
|
|
311
|
-
DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'arg', [1, 2, 3, 4, 5]),
|
|
312
|
-
DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'func', [x1 + x2 + 1, 4, 9, 16, 25]),
|
|
313
|
-
]),
|
|
314
|
-
table2: DG.DataFrame.fromColumns([
|
|
315
|
-
DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'arg', [1, 2, 3, 4, 5]),
|
|
316
|
-
DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'func', [x1 + x2 + 1, 8, 27, 64, 125]),
|
|
317
|
-
]),
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
241
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
242
|
+
@grok.decorators.func({outputs: [{type: 'object', name: 'validator'}]})
|
|
243
|
+
static InitialTempValidator(
|
|
244
|
+
@grok.decorators.param({type: 'object'}) params: any) {
|
|
245
|
+
return (val: number, info: ValidationInfo) => {
|
|
246
|
+
const ambTemp = info.funcCall.inputs['ambTemp'];
|
|
247
|
+
return makeValidationResultInst({
|
|
248
|
+
errors: [
|
|
249
|
+
...(val < ambTemp) ? [`Initial temperature cannot be less than ambient temperature (${ambTemp}).`]: [],
|
|
250
|
+
],
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
@grok.decorators.func({outputs: [{type: 'object', name: 'validator'}]})
|
|
256
|
+
static AmbTempValidator(
|
|
257
|
+
@grok.decorators.param({type: 'object'}) params: any) {
|
|
258
|
+
return (val: number, info: ValidationInfo) => {
|
|
259
|
+
const initTemp = info.funcCall.inputs['initTemp'];
|
|
260
|
+
return makeValidationResultInst({
|
|
261
|
+
errors: [
|
|
262
|
+
...(val > initTemp) ? [`Ambient temperature cannot be higher than initial temperature (${initTemp})`]: [],
|
|
263
|
+
],
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
@grok.decorators.func({outputs: [{type: 'object', name: 'validator'}]})
|
|
270
|
+
static HeatCapValidator(
|
|
271
|
+
@grok.decorators.param({type: 'object'}) params: any) {
|
|
272
|
+
return (val: number, info: ValidationInfo) => {
|
|
273
|
+
return makeValidationResultInst({
|
|
274
|
+
errors: [
|
|
275
|
+
...val <= 0 ? ['Heat capacity must be greater than zero.']: [],
|
|
276
|
+
],
|
|
277
|
+
notifications: [
|
|
278
|
+
makeAdviceInst(`Heat capacity is only dependent on the object material.`, [
|
|
279
|
+
{actionName: 'Google it', action: () => {window.open(`http://google.com`);}},
|
|
280
|
+
]),
|
|
281
|
+
],
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
325
286
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
287
|
+
@grok.decorators.func({outputs: [{type: 'object', name: 'result'}]})
|
|
288
|
+
static CustomStringInput(
|
|
289
|
+
@grok.decorators.param({type: 'object'}) params: any) {
|
|
290
|
+
const defaultInput = ui.input.string('Custom input', {value: ''});
|
|
291
|
+
defaultInput.root.style.backgroundColor = 'aqua';
|
|
292
|
+
defaultInput.input.style.backgroundColor = 'aqua';
|
|
293
|
+
return defaultInput;
|
|
329
294
|
}
|
|
330
295
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
296
|
+
|
|
297
|
+
@grok.decorators.func({outputs: [{type: 'object', name: 'result'}]})
|
|
298
|
+
static ObjectCoolingSelector(
|
|
299
|
+
@grok.decorators.param({type: 'object'}) params: any) {
|
|
300
|
+
return UiUtils.historyInputJSON(
|
|
301
|
+
'Previous run',
|
|
302
|
+
'ObjectCooling',
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
@grok.decorators.func({
|
|
308
|
+
meta: {
|
|
309
|
+
features: '{"fitting": true, "sens-analysis": true}',
|
|
310
|
+
runOnOpen: 'true',
|
|
311
|
+
runOnInput: 'true',
|
|
312
|
+
},
|
|
313
|
+
outputs: [
|
|
314
|
+
{
|
|
315
|
+
name: 'integer',
|
|
316
|
+
type: 'int',
|
|
351
317
|
},
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
argumentCol: 'arg',
|
|
318
|
+
{
|
|
319
|
+
name: 'float1',
|
|
320
|
+
type: 'double',
|
|
356
321
|
},
|
|
357
|
-
|
|
358
|
-
|
|
322
|
+
{
|
|
323
|
+
name: 'float2',
|
|
324
|
+
type: 'double',
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
name: 'table1',
|
|
328
|
+
type: 'dataframe',
|
|
329
|
+
options: {viewer: 'Line chart(block:60) | Grid(block:40)'},
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
name: 'table2',
|
|
333
|
+
type: 'dataframe',
|
|
334
|
+
options: {viewer: 'Line chart(block:60) | Grid(block:40)'},
|
|
335
|
+
},
|
|
336
|
+
],
|
|
337
|
+
description: 'Test for optimization: multiple scalars output',
|
|
338
|
+
editor: 'Compute:RichFunctionViewEditor',
|
|
339
|
+
})
|
|
340
|
+
static fitTestFunc(
|
|
341
|
+
@grok.decorators.param({options: {caption: 'param1', min: '-3', max: '3', initialValue: '1'}}) x1: number,
|
|
342
|
+
@grok.decorators.param({options: {caption: 'param2', min: '-3', max: '3', initialValue: '-1'}}) x2: number,
|
|
343
|
+
@grok.decorators.param({options: {caption: 'table'}}) y: DG.DataFrame,
|
|
344
|
+
bool: boolean) {
|
|
345
|
+
return {
|
|
346
|
+
integer: x1**3 * (x1 - 1) * x2**3 * (x2 - 1),
|
|
347
|
+
float1: (x2 - 1)**2 + (x1 - 1)**2,
|
|
348
|
+
float2: (x2 - 1)**4 + (x1 - 1)**4,
|
|
349
|
+
table1: DG.DataFrame.fromColumns([
|
|
350
|
+
DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'arg', [1, 2, 3, 4, 5]),
|
|
351
|
+
DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'func', [x1 + x2 + 1, 4, 9, 16, 25]),
|
|
352
|
+
]),
|
|
353
|
+
table2: DG.DataFrame.fromColumns([
|
|
354
|
+
DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'arg', [1, 2, 3, 4, 5]),
|
|
355
|
+
DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'func', [x1 + x2 + 1, 8, 27, 64, 125]),
|
|
356
|
+
]),
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
@grok.decorators.func({description: 'Test for optimization: multiple scalars output'})
|
|
362
|
+
static async testFittingOutputs() {
|
|
363
|
+
const func = await grok.functions.find('Compute:fitTestFunc');
|
|
364
|
+
|
|
365
|
+
if (func === null) {
|
|
366
|
+
grok.shell.error('The function "Compute:fitTestFunc" not found!');
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const targetDf1 = DG.DataFrame.fromColumns([
|
|
371
|
+
DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'arg', [1, 2, 3, 4, 5]),
|
|
372
|
+
DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'func', [1, 4.3, 9.1, 16, 25]),
|
|
373
|
+
]);
|
|
374
|
+
targetDf1.name = 'test-df1';
|
|
375
|
+
|
|
376
|
+
const targetDf2 = DG.DataFrame.fromColumns([
|
|
377
|
+
DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'arg', [1, 2, 3, 4, 5]),
|
|
378
|
+
DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'func', [1, 8.5, 27.6, 64.9, 125]),
|
|
379
|
+
]);
|
|
380
|
+
targetDf2.name = 'test-df2';
|
|
381
|
+
|
|
382
|
+
await FittingView.fromEmpty(func as any, {
|
|
383
|
+
targets: {
|
|
384
|
+
integer: {default: 123, enabled: true},
|
|
385
|
+
float1: {default: 456.789, enabled: true},
|
|
386
|
+
table1: {
|
|
387
|
+
default: targetDf1,
|
|
388
|
+
enabled: true,
|
|
389
|
+
argumentCol: 'arg',
|
|
390
|
+
},
|
|
391
|
+
table2: {
|
|
392
|
+
default: targetDf2,
|
|
393
|
+
enabled: true,
|
|
394
|
+
argumentCol: 'arg',
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
});
|
|
398
|
+
}
|
|
359
399
|
}
|