-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmulti.mjs
66 lines (56 loc) · 1.84 KB
/
multi.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// This script exemplifies how to use the Range operator to create
// a multi-execution experiment.
//
// Make sure to have installed dependencies and have the required environment variables
// available, as described in the Quick start example:
//
// https://github.com/modelon-community/impact-client-js#quick-start
//
// Then run the example with: node multi.mjs
import dotenv from 'dotenv'
import {
Analysis,
Client,
ExperimentDefinition,
Model,
Range,
} from '@modelon/impact-client-js'
// Load the .env file variables, install with: npm install dotenv
dotenv.config({ path: '../.env' })
const client = Client.fromImpactApiKey({
impactApiKey: process.env.MODELON_IMPACT_CLIENT_API_KEY,
serverAddress: process.env.MODELON_IMPACT_SERVER,
})
const WorkspaceName = 'test'
const workspace = await client.createWorkspace({
name: WorkspaceName,
})
const analysis = Analysis.from({
type: 'dynamic',
})
const model = Model.from({
className: 'Modelica.Blocks.Examples.PID_Controller',
})
const experimentDefinition = ExperimentDefinition.from({
analysis,
model,
modifiers: {
variables: { 'PI.k': new Range(10, 100, 3).toString() },
},
})
const experiment = await workspace.executeExperimentUntilDone({
experimentDefinition,
timeoutMs: 60 * 1000,
})
const cases = await experiment.getCases()
for (const simCase of cases) {
const timeItems = await simCase.getTrajectories(['time'])
const timeEndValue = timeItems[0].trajectory.pop()
const inertiaItems = await simCase.getTrajectories(['inertia1.phi'])
const inertiaEndValue = inertiaItems[0].trajectory.pop()
const caseInput = await simCase.getInput()
console.log(
`End value for case with PI.k: ${caseInput.parametrization['PI.k']} at time ${timeEndValue}: ${inertiaEndValue}`
)
}
await client.deleteWorkspace(WorkspaceName)