Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91444827
launchRuns.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Nov 11, 04:42
Size
2 KB
Mime Type
text/x-python
Expires
Wed, Nov 13, 04:42 (2 d)
Engine
blob
Format
Raw Data
Handle
22264117
Attached To
R3127 blackdynamite
launchRuns.py
View Options
#!/usr/bin/env python
import
BlackDynamite
as
BD
import
os
,
sys
import
socket
from
types
import
ModuleType
def
main
(
argv
=
None
):
if
(
type
(
argv
)
==
str
):
argv
=
argv
.
split
()
parser
=
BD
.
BDParser
()
parser
.
register_params
(
group
=
"launchRuns.py"
,
params
=
{
"outpath"
:
str
,
"generator"
:
ModuleType
,
"nruns"
:
int
,
"state"
:
str
,
"machine_name"
:
str
},
defaults
=
{
"machine_name"
:
socket
.
gethostname
(),
"nruns"
:
-
1
,
"generator"
:
"bashCoat"
})
parser
.
help
.
update
({
"nruns"
:
"Specify the number of runs to launch. This is useful when we want to launch only the first run from the stack."
,
"generator"
:
"Specify the launcher generator"
})
params
=
parser
.
parseBDParameters
(
argv
=
argv
)
mybase
=
BD
.
Base
(
**
params
)
if
(
not
"outpath"
in
params
):
print
(
"A directory where to create temp files should be provided. use --outpath "
)
sys
.
exit
(
-
1
)
mydir
=
os
.
path
.
join
(
params
[
"outpath"
],
"BD-"
+
params
[
"study"
]
+
"-runs"
)
if
not
os
.
path
.
exists
(
mydir
):
os
.
makedirs
(
mydir
)
os
.
chdir
(
mydir
)
run_constraints
=
[]
job_constraints
=
[]
runSelector
=
BD
.
RunSelector
(
mybase
)
if
(
"run_constraints"
in
params
):
run_constraints
=
params
[
"run_constraints"
]
def
item_matcher
(
name
,
item
):
return
item
.
lower
()
.
lstrip
()
.
startswith
(
name
)
if
not
any
([
item_matcher
(
"state"
,
item
)
for
item
in
run_constraints
]):
run_constraints
.
append
(
"state = CREATED"
)
if
not
any
([
item_matcher
(
"machine_name"
,
item
)
for
item
in
run_constraints
]):
run_constraints
.
append
(
"machine_name = {0}"
.
format
(
params
[
"machine_name"
]))
run_list
=
runSelector
.
selectRuns
(
run_constraints
,
params
)
if
(
params
[
"nruns"
]
>
0
):
run_list
=
[
run_list
[
i
]
for
i
in
range
(
0
,
min
(
params
[
"nruns"
],
len
(
run_list
)))]
if
(
len
(
run_list
)
==
0
):
print
"No runs to be launched"
for
r
,
j
in
run_list
:
print
(
"Dealing with job {0.id}, run {1.id}"
.
format
(
j
,
r
))
r
[
"run_path"
]
=
os
.
path
.
join
(
mydir
,
"run-"
+
str
(
r
.
id
))
j
.
update
()
if
not
os
.
path
.
exists
(
"run-"
+
str
(
r
.
id
)):
os
.
makedirs
(
"run-"
+
str
(
r
.
id
))
os
.
chdir
(
"run-"
+
str
(
r
.
id
))
conffiles
=
r
.
getConfigFiles
()
for
conf
in
conffiles
:
print
(
"create file "
+
conf
[
"filename"
])
f
=
open
(
conf
[
"filename"
],
'w'
)
f
.
write
(
conf
[
"file"
])
f
.
close
()
print
(
"launch in '"
+
mydir
+
"/"
+
"run-"
+
str
(
r
.
id
)
+
"/'"
)
mymod
=
params
[
"generator"
]
print
(
mymod
)
mymod
.
launch
(
r
,
params
)
os
.
chdir
(
"../"
)
if
(
params
[
"truerun"
]
==
True
):
mybase
.
commit
()
if
__name__
==
'__main__'
:
main
()
Event Timeline
Log In to Comment