Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
OptiOrch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Zizhe Wang
OptiOrch
Commits
db875a8f
Commit
db875a8f
authored
11 months ago
by
Zizhe Wang
Browse files
Options
Downloads
Patches
Plain Diff
feat load Modelica libraries
parent
923b9028
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/config.json
+6
-0
6 additions, 0 deletions
src/config.json
src/config.py
+5
-1
5 additions, 1 deletion
src/config.py
src/parallel_computing.py
+17
-1
17 additions, 1 deletion
src/parallel_computing.py
with
28 additions
and
2 deletions
src/config.json
+
6
−
0
View file @
db875a8f
...
...
@@ -30,5 +30,11 @@
"PLOT_TITLE"
:
"Pareto Front of Energy Consumption vs Comfort"
,
"ENABLE_PLOT"
:
false
},
"LIBRARY_CONFIG"
:
{
"LOAD_LIBRARIES"
:
true
,
"LIBRARIES"
:
[
{
"name"
:
""
,
"path"
:
""
}
]
},
"N_JOBS"
:
-1
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/config.py
+
5
−
1
View file @
db875a8f
...
...
@@ -28,9 +28,13 @@ PARAM_BOUNDS = config['PARAM_BOUNDS'] # Parameter range
OPTIMIZATION_CONFIG
=
config
[
'
OPTIMIZATION_CONFIG
'
]
PLOT_CONFIG
=
config
[
'
PLOT_CONFIG
'
]
N_JOBS
=
config
[
'
N_JOBS
'
]
LIBRARY_CONFIG
=
config
.
get
(
'
LIBRARY_CONFIG
'
,
{})
LOAD_LIBRARIES
=
LIBRARY_CONFIG
.
get
(
'
LOAD_LIBRARIES
'
,
False
)
LIBRARIES
=
LIBRARY_CONFIG
.
get
(
'
LIBRARIES
'
,
[])
# Derived configuration
MODEL_PATH
=
os
.
path
.
join
(
os
.
getcwd
(),
MODEL_FILE
)
BASE_DIR
=
os
.
getcwd
()
MODEL_PATH
=
os
.
path
.
join
(
BASE_DIR
,
'
models
'
,
MODEL_FILE
)
# Helper functions to get bounds and types
def
get_bounds
(
param_bounds
):
...
...
This diff is collapsed.
Click to expand it.
src/parallel_computing.py
+
17
−
1
View file @
db875a8f
...
...
@@ -14,10 +14,23 @@ import numpy as np
from
time
import
sleep
from
joblib
import
Parallel
,
delayed
from
OMPython
import
OMCSessionZMQ
from
config
import
MODEL_FILE
,
MODEL_NAME
,
SIMULATION_STOP_TIME
,
PARAMETERS
,
OBJECTIVE_NAMES
,
PARAM_BOUNDS
,
PARAM_TYPES
,
MODEL_PATH
,
PRECISION
,
N_JOBS
from
config
import
MODEL_FILE
,
MODEL_NAME
,
SIMULATION_STOP_TIME
,
PARAMETERS
,
OBJECTIVE_NAMES
,
PARAM_BOUNDS
,
PARAM_TYPES
,
MODEL_PATH
,
PRECISION
,
N_JOBS
,
LOAD_LIBRARIES
,
LIBRARIES
temp_dirs
=
[]
# List to store paths of temporary directories
def
load_libraries
(
omc
):
"""
Function to load Modelica libraries.
"""
for
library
in
LIBRARIES
:
library_path
=
os
.
path
.
join
(
os
.
getcwd
(),
'
models
'
,
library
[
'
path
'
]).
replace
(
'
\\
'
,
'
/
'
)
load_library_result
=
omc
.
sendExpression
(
f
'
loadFile(
"
{
library_path
}
"
)
'
)
print
(
f
"
Load library result:
{
load_library_result
}
"
)
if
load_library_result
is
not
True
:
messages
=
omc
.
sendExpression
(
"
getErrorString()
"
)
print
(
f
"
OpenModelica error messages:
{
messages
}
"
)
raise
RuntimeError
(
f
"
Failed to load library:
{
library
[
'
name
'
]
}
"
)
def
optimization_function
(
param_values
,
retries
=
3
,
delay
=
2
):
"""
Function to optimize the Modelica model given specific parameter values.
...
...
@@ -36,6 +49,9 @@ def optimization_function(param_values, retries=3, delay=2):
temp_model_path
=
os
.
path
.
join
(
temp_dir
,
MODEL_FILE
).
replace
(
'
\\
'
,
'
/
'
)
shutil
.
copy
(
MODEL_PATH
,
temp_model_path
)
if
LOAD_LIBRARIES
:
load_libraries
(
omc
)
# Load the model in the worker session
load_temp_model_result
=
omc
.
sendExpression
(
f
"
loadFile(
\"
{
temp_model_path
}
\"
)
"
)
print
(
f
"
Load model result in worker:
{
load_temp_model_result
}
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment