Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
dream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
dream
Commits
e5eb6c70
Commit
e5eb6c70
authored
Apr 21, 2015
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ACO: simpler distribution using parrallel subprocesses
parent
b8666f1f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
6 deletions
+30
-6
dream/plugins/ACO.py
dream/plugins/ACO.py
+27
-5
dream/plugins/Batches/BatchesACO.py
dream/plugins/Batches/BatchesACO.py
+1
-0
dream/plugins/plugin.py
dream/plugins/plugin.py
+2
-1
No files found.
dream/plugins/ACO.py
View file @
e5eb6c70
...
@@ -6,13 +6,19 @@ import time
...
@@ -6,13 +6,19 @@ import time
import
random
import
random
import
operator
import
operator
import
xmlrpclib
import
xmlrpclib
import
signal
from
multiprocessing
import
Pool
from
dream.simulation.Queue
import
Queue
from
dream.simulation.Queue
import
Queue
from
dream.simulation.Operator
import
Operator
from
dream.simulation.Operator
import
Operator
from
dream.simulation.Globals
import
getClassFromName
from
dream.simulation.Globals
import
getClassFromName
class
ACO
(
plugin
.
ExecutionPlugin
):
# run an ant in a subrocess. Can be parrallelized.
def
runAntInSubProcess
(
ant
):
ant
[
'result'
]
=
plugin
.
ExecutionPlugin
.
runOneScenario
(
ant
[
'input'
])[
'result'
]
return
ant
class
ACO
(
plugin
.
ExecutionPlugin
):
def
_calculateAntScore
(
self
,
ant
):
def
_calculateAntScore
(
self
,
ant
):
"""Calculate the score of this ant.
"""Calculate the score of this ant.
"""
"""
...
@@ -57,6 +63,8 @@ class ACO(plugin.ExecutionPlugin):
...
@@ -57,6 +63,8 @@ class ACO(plugin.ExecutionPlugin):
if
distributor_url
:
if
distributor_url
:
distributor
=
xmlrpclib
.
Server
(
distributor_url
)
distributor
=
xmlrpclib
.
Server
(
distributor_url
)
multiprocessorCount
=
data
[
'general'
].
get
(
'multiprocessorCount'
)
tested_ants
=
set
()
tested_ants
=
set
()
start
=
time
.
time
()
# start counting execution time
start
=
time
.
time
()
# start counting execution time
...
@@ -97,10 +105,24 @@ class ACO(plugin.ExecutionPlugin):
...
@@ -97,10 +105,24 @@ class ACO(plugin.ExecutionPlugin):
scenario_list
.
append
(
ant
)
scenario_list
.
append
(
ant
)
if
distributor
is
None
:
if
distributor
is
None
:
# synchronous
if
multiprocessorCount
:
for
ant
in
scenario_list
:
self
.
logger
.
info
(
"running multiprocessing ACO with %s processes"
%
multiprocessorCount
)
ant
[
'result'
]
=
self
.
runOneScenario
(
ant
[
'input'
])[
'result'
]
# We unset our signal handler to print traceback at the end
# otherwise logs are confusing.
sigterm_handler
=
signal
.
getsignal
(
signal
.
SIGTERM
)
pool
=
Pool
(
processes
=
multiprocessorCount
)
try
:
signal
.
signal
(
signal
.
SIGTERM
,
signal
.
SIG_DFL
)
scenario_list
=
pool
.
map
(
runAntInSubProcess
,
scenario_list
)
pool
.
close
()
pool
.
join
()
finally
:
signal
.
signal
(
signal
.
SIGTERM
,
sigterm_handler
)
else
:
# synchronous
for
ant
in
scenario_list
:
ant
[
'result'
]
=
self
.
runOneScenario
(
ant
[
'input'
])[
'result'
]
else
:
# asynchronous
else
:
# asynchronous
self
.
logger
.
info
(
"Registering a job for %s scenarios"
%
len
(
scenario_list
))
self
.
logger
.
info
(
"Registering a job for %s scenarios"
%
len
(
scenario_list
))
start_register
=
time
.
time
()
start_register
=
time
.
time
()
...
...
dream/plugins/Batches/BatchesACO.py
View file @
e5eb6c70
...
@@ -83,6 +83,7 @@ class BatchesACO(ACO):
...
@@ -83,6 +83,7 @@ class BatchesACO(ACO):
# else run ACO
# else run ACO
data
[
'general'
][
'numberOfSolutions'
]
=
1
# default of 1 solution for this instance
data
[
'general'
][
'numberOfSolutions'
]
=
1
# default of 1 solution for this instance
data
[
"general"
][
"distributorURL"
]
=
None
# no distributor currently, to be added in the GUI
data
[
"general"
][
"distributorURL"
]
=
None
# no distributor currently, to be added in the GUI
data
[
"general"
][
"multiprocessorCount"
]
=
8
# number of parrallel processes, to be added to the GUI
ACO
.
run
(
self
,
data
)
ACO
.
run
(
self
,
data
)
data
[
"result"
][
"result_list"
][
-
1
][
"score"
]
=
''
data
[
"result"
][
"result_list"
][
-
1
][
"score"
]
=
''
data
[
"result"
][
"result_list"
][
-
1
][
"key"
]
=
"Go To Results Page"
data
[
"result"
][
"result_list"
][
-
1
][
"key"
]
=
"Go To Results Page"
...
...
dream/plugins/plugin.py
View file @
e5eb6c70
...
@@ -59,7 +59,8 @@ class Plugin(object):
...
@@ -59,7 +59,8 @@ class Plugin(object):
class
ExecutionPlugin
(
Plugin
):
class
ExecutionPlugin
(
Plugin
):
"""Plugin to handle the execution of multiple simulation runs.
"""Plugin to handle the execution of multiple simulation runs.
"""
"""
def
runOneScenario
(
self
,
data
):
@
staticmethod
def
runOneScenario
(
data
):
"""default method for running one scenario
"""default method for running one scenario
"""
"""
return
json
.
loads
(
simulate_line_json
(
input_data
=
json
.
dumps
(
data
)))
return
json
.
loads
(
simulate_line_json
(
input_data
=
json
.
dumps
(
data
)))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment