Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
exp-runner
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
Christopher Spinrath
exp-runner
Commits
161f6547
Commit
161f6547
authored
1 month ago
by
Christopher Spinrath
Browse files
Options
Downloads
Patches
Plain Diff
Use structlog
parent
5d4e5248
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+2
-2
2 additions, 2 deletions
README.md
run-exp.py
+35
-17
35 additions, 17 deletions
run-exp.py
with
37 additions
and
19 deletions
README.md
+
2
−
2
View file @
161f6547
## Dependencies
## Dependencies
The runner script requires the Python packages
`PyYaml`
and
`click`
.
The runner script requires the Python packages
`PyYaml`
,
`structlog`
,
and
`click`
.
On Debian they can be install via the package manager as follows.
On Debian they can be install via the package manager as follows.
```
```
# apt install python3-yaml python3-click
# apt install python3-yaml
python3-structlog
python3-click
```
```
This diff is collapsed.
Click to expand it.
run-exp.py
+
35
−
17
View file @
161f6547
#!/usr/bin/env python3
#!/usr/bin/env python3
import
itertools
import
json
import
pathlib
import
pathlib
import
subprocess
import
subprocess
from
abc
import
ABC
,
abstractmethod
from
abc
import
ABC
,
abstractmethod
import
click
import
click
import
structlog
import
yaml
import
yaml
logger
=
structlog
.
get_logger
()
class
Variable
(
ABC
):
class
Variable
(
ABC
):
def
__init__
(
self
,
name
):
def
__init__
(
self
,
name
):
self
.
_name
=
name
self
.
_name
=
name
...
@@ -87,7 +91,19 @@ class Task:
...
@@ -87,7 +91,19 @@ class Task:
def
work_dir
(
self
):
def
work_dir
(
self
):
return
self
.
_work_dir
return
self
.
_work_dir
def
__repr__
(
self
):
return
json
.
dumps
({
'
name
'
:
self
.
_name
,
'
work-dir
'
:
str
(
self
.
_work_dir
),
'
base-command
'
:
self
.
_base_command
,
'
parameters
'
:
self
.
_parameters
,
'
timeout
'
:
self
.
_timeout
,
})
def
run
(
self
,
variables
,
global_timeout
,
dry_run
):
def
run
(
self
,
variables
,
global_timeout
,
dry_run
):
log
=
logger
.
bind
(
task
=
self
,
variables
=
variables
)
log
.
info
(
"
Preparing task
"
)
if
dry_run
:
if
dry_run
:
args
=
[
"
echo
"
]
args
=
[
"
echo
"
]
else
:
else
:
...
@@ -115,6 +131,7 @@ class Task:
...
@@ -115,6 +131,7 @@ class Task:
args
.
append
(
p
[
"
value
"
].
format
(
**
variables
))
args
.
append
(
p
[
"
value
"
].
format
(
**
variables
))
log
=
log
.
bind
(
args
=
args
)
# print()
# print()
# print(f"pushd {self._work_dir}")
# print(f"pushd {self._work_dir}")
# print(" ".join(args))
# print(" ".join(args))
...
@@ -125,6 +142,9 @@ class Task:
...
@@ -125,6 +142,9 @@ class Task:
elif
global_timeout
is
not
None
:
elif
global_timeout
is
not
None
:
timeout
=
global_timeout
timeout
=
global_timeout
log
=
log
.
bind
(
timeout
=
timeout
)
log
.
info
(
"
Running task
"
)
try
:
try
:
subprocess
.
run
(
subprocess
.
run
(
"
"
.
join
(
args
),
"
"
.
join
(
args
),
...
@@ -135,9 +155,7 @@ class Task:
...
@@ -135,9 +155,7 @@ class Task:
return
False
return
False
except
subprocess
.
TimeoutExpired
:
except
subprocess
.
TimeoutExpired
:
print
()
log
.
error
(
"
Task timed out!
"
)
print
(
"
Task timed out!
"
)
print
()
return
True
return
True
...
@@ -185,6 +203,14 @@ class Config:
...
@@ -185,6 +203,14 @@ class Config:
def
tasks
(
self
):
def
tasks
(
self
):
return
self
.
_tasks
return
self
.
_tasks
def
__repr__
(
self
):
return
json
.
dumps
({
'
name
'
:
self
.
_name
,
'
repetitions
'
:
self
.
_repetitions
,
'
variables
'
:
[
repr
(
v
)
for
v
in
self
.
_variables
],
'
tasks
'
:
[
repr
(
t
)
for
t
in
self
.
_tasks
],
})
@staticmethod
@staticmethod
def
parse_var_definition
(
name
,
value_config
):
def
parse_var_definition
(
name
,
value_config
):
if
isinstance
(
value_config
,
list
):
if
isinstance
(
value_config
,
list
):
...
@@ -235,11 +261,10 @@ class Config:
...
@@ -235,11 +261,10 @@ class Config:
def
main
(
config_file
,
global_timeout
,
dry_run
):
def
main
(
config_file
,
global_timeout
,
dry_run
):
c
=
Config
.
from_file
(
config_file
)
c
=
Config
.
from_file
(
config_file
)
print
(
f
"
> Running experiment
\"
{
c
.
name
}
\"
"
)
logger
.
info
(
print
(
f
"
> with
{
len
(
c
.
variables
)
}
variables
"
)
f
"
Running experiment
\"
{
c
.
name
}
\"
"
,
print
(
f
"
> and
{
len
(
c
.
tasks
)
}
tasks
"
)
config
=
c
,
print
(
f
"
> and
{
c
.
repetitions
}
repetitions
"
)
)
print
()
# we precompute all variable values to be able to abort early in case of a problem,
# we precompute all variable values to be able to abort early in case of a problem,
# for instance, if a file does not exist
# for instance, if a file does not exist
...
@@ -259,19 +284,12 @@ def main(config_file, global_timeout, dry_run):
...
@@ -259,19 +284,12 @@ def main(config_file, global_timeout, dry_run):
variable_maps
=
updated_variable_maps
variable_maps
=
updated_variable_maps
for
variables
in
variable_maps
:
for
variables
in
variable_maps
:
print
()
print
(
"
Running tasks with variable map:
"
)
print
(
variables
)
print
()
for
rep
in
range
(
c
.
repetitions
):
for
rep
in
range
(
c
.
repetitions
):
print
(
f
"
Repetition
{
rep
}
"
)
#
print(f"Repetition {rep}")
timed_out
=
False
timed_out
=
False
for
task
in
c
.
tasks
:
for
task
in
c
.
tasks
:
print
(
f
"
Running task
{
task
.
name
}
"
)
timed_out
=
task
.
run
(
variables
,
global_timeout
,
dry_run
)
timed_out
=
task
.
run
(
variables
,
global_timeout
,
dry_run
)
print
()
if
timed_out
:
# repetitions are useless if tasks time out
if
timed_out
:
# repetitions are useless if tasks time out
break
break
...
...
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