Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
TopFarm2
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
TOPFARM
TopFarm2
Commits
38a16cbc
Commit
38a16cbc
authored
5 years ago
by
Pierre-Elouan Rethore
Browse files
Options
Downloads
Patches
Plain Diff
tweaks on the random search in parallel
parent
9f614d82
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!127
Electrical cost and Parallel RandomSearch
Pipeline
#10094
failed
5 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
topfarm/drivers/random_search_driver.py
+17
-3
17 additions, 3 deletions
topfarm/drivers/random_search_driver.py
with
17 additions
and
3 deletions
topfarm/drivers/random_search_driver.py
+
17
−
3
View file @
38a16cbc
...
...
@@ -4,15 +4,24 @@ import numpy as np
from
openmdao.core.analysis_error
import
AnalysisError
import
topfarm
import
time
from
openmdao.recorders.recording_manager
import
RecordingManager
from
openmdao.utils.concurrent
import
concurrent_eval
from
openmdao.utils.record_util
import
create_local_meta
class
MyRecordingManager
(
RecordingManager
):
def
record_iteration
(
self
,
recording_requester
,
data
,
metadata
):
#print('In MyRecordingManager record_iteration', self.rank)
#for recorder in self._recorders:
# print(recorder.__class__, recorder._parallel)
super
().
record_iteration
(
recording_requester
,
data
,
metadata
)
class
RandomSearchDriver
(
Driver
):
def
__init__
(
self
,
randomize_func
,
**
kwargs
):
self
.
randomize_func
=
randomize_func
super
().
__init__
(
**
kwargs
)
self
.
_rec_mgr
=
MyRecordingManager
()
# What we support
self
.
supports
[
'
integer_design_vars
'
]
=
True
...
...
@@ -157,7 +166,7 @@ class RandomSearchDriver(Driver):
x0
[
i
:
i
+
size
]
=
desvar_vals
[
name
]
i
+=
size
obj_value_x0
,
success
=
self
.
objective_callback
(
x0
)
obj_value_x0
,
success
=
self
.
objective_callback
(
x0
,
record
=
True
)
x1
=
x0
.
copy
()
n_iter
=
0
...
...
@@ -174,6 +183,7 @@ class RandomSearchDriver(Driver):
desvar_dict
[
name
][
0
][:]
=
x0
[
i
:
j
].
copy
()
if
comm
is
not
None
:
#print('Parallel', comm.rank)
## We do it in parallel: One case per CPU available
cases
=
[]
if
comm
.
rank
==
0
:
...
...
@@ -202,8 +212,9 @@ class RandomSearchDriver(Driver):
# n_iter += 1
if
one_success
:
n_iter
+=
1
obj_value_x0
,
success
=
self
.
objective_callback
(
x0
,
record
=
True
)
if
disp
and
comm
.
rank
==
0
:
obj_value_x0
,
success
=
self
.
objective_callback
(
x0
,
record
=
Tru
e
)
#
obj_value_x0, success = self.objective_callback(x0, record=
Fals
e)
print
(
'
rank:
'
,
comm
.
rank
,
n_iter
,
obj_value_x0
)
else
:
## We only use one CPU
...
...
@@ -228,6 +239,7 @@ class RandomSearchDriver(Driver):
obj_value_x1
,
success
=
self
.
objective_callback
(
x0
,
record
=
True
)
return
False
def
objective_callback
(
self
,
x
,
record
=
False
):
"""
Evaluate problem objective at the requested point.
...
...
@@ -253,6 +265,8 @@ class RandomSearchDriver(Driver):
for
name
in
self
.
_designvars
:
i
,
j
=
self
.
_desvar_idx
[
name
]
#if record:
# print('setting', name, 'to', x[i:j])
self
.
set_design_var
(
name
,
x
[
i
:
j
])
# Execute the model
...
...
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