Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mkexp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esmenv
mkexp
Commits
b76711fb
Commit
b76711fb
authored
1 year ago
by
Karl-Hermann Wieners
Browse files
Options
Downloads
Patches
Plain Diff
Tools: let getexp handle script dir and missing dirs
parent
38f1979a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
expconfig.py
+7
-0
7 additions, 0 deletions
expconfig.py
getexp
+13
-10
13 additions, 10 deletions
getexp
mkexp
+14
-27
14 additions, 27 deletions
mkexp
with
34 additions
and
37 deletions
expconfig.py
+
7
−
0
View file @
b76711fb
...
...
@@ -587,6 +587,13 @@ class ExpConfig(ConfigObj):
self
.
experiment_id
=
pre_config
[
ExpConfig
.
id_name
]
self
.
experiment_kind
=
re
.
sub
(
r
'
-\w+$
'
,
''
,
experiment_type
)
dir_names
=
[
'
DATA_DIR
'
,
'
WORK_DIR
'
]
cfg_dir_names
=
pre_config
.
get
(
'
EXP_DIR_NAMES
'
,
[])
if
not
isinstance
(
cfg_dir_names
,
(
list
,
tuple
)):
cfg_dir_names
=
[
cfg_dir_names
]
dir_names
.
extend
(
d
for
d
in
cfg_dir_names
if
d
not
in
dir_names
)
self
.
exp_dir_names
=
[
d
for
d
in
dir_names
if
d
in
pre_config
]
# Re-read merged config with interpolation set.
# This works around incomprehensible inheritance of interpolation with
# merge. Make sure that all values are interpolated
...
...
This diff is collapsed.
Click to expand it.
getexp
+
13
−
10
View file @
b76711fb
...
...
@@ -97,6 +97,14 @@ try:
except
ExpConfigError
as
error
:
die
(
error
.
message
,
status
=
2
)
exp_dir_names
=
[]
if
'
MODEL_DIR
'
in
config
:
exp_dir_names
.
append
(
'
MODEL_DIR
'
)
if
'
SCRIPT_DIR
'
not
in
config
:
config
[
'
SCRIPT_DIR
'
]
=
config
.
experiment_id
exp_dir_names
.
append
(
'
SCRIPT_DIR
'
)
exp_dir_names
.
extend
(
config
.
exp_dir_names
)
if
args
.
readme
:
print
(
config
[
'
EXP_DESCRIPTION
'
])
elif
args
.
key
:
...
...
@@ -122,14 +130,9 @@ elif args.verbose == 1:
value
=
u
'"
{0}
"'
.
format
(
u
'"
"'
.
join
(
value
))
print
(
u
"
{0}=
'
{1}
'"
.
format
(
key
,
value
.
replace
(
"'"
,
'"'
)))
else
:
print
(
"
EXP_ID=
'
{0}
'"
.
format
(
config
.
experiment_id
))
print
(
"
MODEL_DIR=
'
{0}
'"
.
format
(
config
[
'
MODEL_DIR
'
]))
print
(
"
SCRIPT_DIR=
'
{0}
'"
.
format
(
config
[
'
SCRIPT_DIR
'
]))
print
(
"
WORK_DIR=
'
{0}
'"
.
format
(
config
[
'
WORK_DIR
'
]))
print
(
"
DATA_DIR=
'
{0}
'"
.
format
(
config
[
'
DATA_DIR
'
]))
if
not
(
os
.
path
.
isdir
(
config
[
'
MODEL_DIR
'
])
and
os
.
path
.
isdir
(
config
[
'
SCRIPT_DIR
'
])
and
os
.
path
.
isdir
(
config
[
'
WORK_DIR
'
])
and
os
.
path
.
isdir
(
config
[
'
DATA_DIR
'
])):
print
(
f
"
EXP_ID=
'
{
config
.
experiment_id
}
'"
)
for
exp_dir_name
in
exp_dir_names
:
print
(
f
"
{
exp_dir_name
}
=
'
{
config
[
exp_dir_name
]
}
'"
)
if
not
all
(
os
.
path
.
isdir
(
config
[
d
])
for
d
in
exp_dir_names
):
info
(
"
data for experiment
'
{0}
'
does not exist
"
.
format
(
config
.
experiment_id
))
This diff is collapsed.
Click to expand it.
mkexp
+
14
−
27
View file @
b76711fb
...
...
@@ -423,13 +423,6 @@ except ExpConfigError as error:
def
cut_dir_variable
(
directory
):
return
re
.
sub
(
os
.
sep
+
r
'
[^
'
+
os
.
sep
+
r
'
$]*\$\{\w+\}.*$
'
,
''
,
directory
)
def
list1
(
x
,
keep_empty
=
False
):
if
isinstance
(
x
,
(
list
,
tuple
,
Iterator
)):
return
x
if
not
keep_empty
and
x
==
''
:
return
[]
return
[
x
]
# Create directory for scripts if it doesn't exist
script_dir
=
config
.
get
(
'
SCRIPT_DIR
'
,
config
.
experiment_id
)
print
(
f
"
Script directory:
'
{
script_dir
}
'"
)
...
...
@@ -446,26 +439,20 @@ else:
os
.
makedirs
(
backup_dir
)
# Create directories for experiment if they don't exist
exp_dir_names
=
[
'
DATA_DIR
'
,
'
WORK_DIR
'
]
exp_dir_names
.
extend
(
name
for
name
in
list1
(
config
.
get
(
'
EXP_DIR_NAMES
'
,
[]))
if
name
not
in
exp_dir_names
)
for
exp_dir_name
in
exp_dir_names
:
try
:
exp_dir
=
config
[
exp_dir_name
]
exp_cut
=
cut_dir_variable
(
exp_dir
)
name
=
exp_dir_name
.
lower
().
removesuffix
(
'
_dir
'
)
Name
=
name
.
capitalize
()
exists
=
os
.
path
.
isdir
(
exp_cut
)
print
(
f
"
{
Name
}
directory:
'
{
exp_dir
}
'"
+
(
"
(already exists)
"
if
exists
else
"
(not created)
"
if
not
args
.
make_dirs
else
""
))
if
not
exists
and
args
.
make_dirs
:
if
exp_dir
!=
exp_cut
:
feedback
.
warning
(
"
only considering non-variable part
"
"
of directory
"
)
os
.
makedirs
(
exp_cut
)
except
KeyError
:
pass
for
exp_dir_name
in
config
.
exp_dir_names
:
exp_dir
=
config
[
exp_dir_name
]
exp_cut
=
cut_dir_variable
(
exp_dir
)
name
=
exp_dir_name
.
lower
().
removesuffix
(
'
_dir
'
)
Name
=
name
.
capitalize
()
exists
=
os
.
path
.
isdir
(
exp_cut
)
print
(
f
"
{
Name
}
directory:
'
{
exp_dir
}
'"
+
(
"
(already exists)
"
if
exists
else
"
(not created)
"
if
not
args
.
make_dirs
else
""
))
if
not
exists
and
args
.
make_dirs
:
if
exp_dir
!=
exp_cut
:
feedback
.
warning
(
"
only considering non-variable part
"
"
of directory
"
)
os
.
makedirs
(
exp_cut
)
# Create config dump for reference
...
...
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