Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
reproductionTool
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
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
SMAC
Reproductibilité des recherches dans SMAC
reproductionTool
Commits
a7552066
Commit
a7552066
authored
3 years ago
by
AxelCarayon
Browse files
Options
Downloads
Patches
Plain Diff
First commit
parent
2059192b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
reprodExperiment.py
+138
-0
138 additions, 0 deletions
reprodExperiment.py
with
138 additions
and
0 deletions
reprodExperiment.py
0 → 100644
+
138
−
0
View file @
a7552066
import
os
import
git
import
subprocess
import
sys
from
git
import
repo
import
yaml
path
=
"
./
"
repository
=
None
inputFolder
=
None
inputFiles
=
[]
paramsFolder
=
None
commandsFile
=
None
experimentName
=
None
outputFolder
=
None
outputFiles
=
[]
def
isGitRepo
(
path
)
->
bool
:
try
:
git
.
Repo
(
path
)
return
True
except
git
.
exc
.
InvalidGitRepositoryError
:
return
False
def
init
(
pathInput
)
->
None
:
global
repository
,
path
,
experimentName
if
isGitRepo
(
pathInput
):
path
+=
pathInput
if
not
(
pathInput
[
len
(
pathInput
)
-
1
]
==
"
/
"
):
path
+=
"
/
"
repository
=
git
.
Repo
(
path
)
experimentName
=
repository
.
active_branch
.
name
os
.
chdir
(
path
)
else
:
raise
Exception
(
f
"
{
pathInput
}
is not a git repository
"
)
def
fileExists
(
fileName
)
->
bool
:
return
os
.
path
.
exists
(
fileName
)
def
folderExists
(
folderName
)
->
bool
:
return
os
.
path
.
isdir
(
folderName
)
def
searchForInputFolder
()
->
None
:
global
inputFolder
print
(
"
Searching for input folder...
"
)
if
folderExists
(
"
inputs
"
):
inputFolder
=
"
inputs
"
print
(
f
"
{
path
}{
inputFolder
}
found !
"
)
else
:
raise
Exception
(
f
"
{
path
}
/inputs folder does not exist
"
)
def
searchForOutputFolder
()
->
None
:
global
outputFolder
print
(
"
Searching for output folder...
"
)
if
folderExists
(
"
outputs
"
):
outputFolder
=
"
outputs
"
print
(
f
"
{
path
}{
outputFolder
}
found !
"
)
else
:
raise
Exception
(
f
"
{
path
}
/outputs folder does not exist
"
)
def
searchForParamsFolder
()
->
None
:
global
paramsFolder
if
folderExists
(
"
params
"
):
paramsFolder
=
"
params
"
else
:
raise
Exception
(
f
"
{
path
}
/params folder does not exist
"
)
def
askForCommandsFile
()
->
None
:
global
commandsFile
commandsFile
=
input
(
"
Enter the name of the commands file:
"
)
if
commandsFile
==
""
:
raise
Exception
(
"
No commands file given
"
)
if
not
fileExists
(
commandsFile
):
raise
Exception
(
f
"
{
commandsFile
}
file does not exist
"
)
def
runExperiment
()
->
None
:
print
(
"
Trying to run experiment
"
)
file
=
open
(
commandsFile
,
"
r
"
)
for
line
in
file
.
read
().
splitlines
():
print
(
f
"
running
{
line
}
...
"
)
process
=
subprocess
.
run
(
line
,
shell
=
True
)
process
.
check_returncode
()
print
(
"
done
"
)
def
scanInputFiles
()
->
None
:
for
file
in
os
.
listdir
(
inputFolder
):
inputFiles
.
append
(
file
)
def
scanOutputsGenerated
()
->
None
:
print
(
outputFolder
)
for
file
in
os
.
listdir
(
outputFolder
):
outputFiles
.
append
(
file
)
def
writeInYaml
()
->
None
:
with
open
(
"
experimentResume.yaml
"
,
"
r
"
)
as
yamlFile
:
cur_yaml
=
yaml
.
safe_load
(
yamlFile
)
cur_yaml
.
update
({
"
name
"
:
experimentName
})
cur_yaml
.
update
({
"
commands
"
:
commandsFile
})
cur_yaml
.
update
({
"
inputs
"
:
inputFiles
})
cur_yaml
.
update
({
"
outputs
"
:
outputFiles
})
print
(
cur_yaml
)
with
open
(
'
experimentResume.yaml
'
,
'
w
'
)
as
yamlFile
:
yaml
.
safe_dump
(
cur_yaml
,
yamlFile
)
def
branchExists
(
branchName
)
->
bool
:
return
branchName
in
repository
.
references
def
pushBranch
(
version
=
1
)
->
None
:
print
(
experimentName
)
while
(
branchExists
(
f
"
{
experimentName
}
Experiment
{
version
}
"
)):
version
+=
1
else
:
repository
.
git
.
checkout
(
'
-b
'
,
f
"
{
experimentName
}
Experiment
{
version
}
"
)
repository
.
git
.
add
(
all
=
True
)
repository
.
git
.
commit
(
m
=
f
"
{
experimentName
}
Experiment
{
version
}
"
)
repository
.
git
.
push
(
'
--set-upstream
'
,
repository
.
remote
().
name
,
f
"
{
experimentName
}
Experiment
{
version
}
"
)
repository
.
git
.
checkout
(
experimentName
)
if
(
__name__
==
"
__main__
"
):
if
(
len
(
sys
.
argv
)
<
2
):
raise
Exception
(
"
No experiment folder given
"
)
init
(
sys
.
argv
[
1
])
repository
.
active_branch
.
checkout
()
searchForInputFolder
()
scanInputFiles
()
searchForOutputFolder
()
searchForParamsFolder
()
askForCommandsFile
()
runExperiment
()
scanOutputsGenerated
()
writeInYaml
()
pushBranch
()
\ No newline at end of file
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