Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RDStackingProject
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
Yifan Wang
RDStackingProject
Commits
575cbeb1
Commit
575cbeb1
authored
3 years ago
by
Francisco Jimenez Forteza
Browse files
Options
Downloads
Patches
Plain Diff
Run in one click
parent
42056318
No related branches found
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
code_new/Sumit/Run_Setup.ipynb
+168
-0
168 additions, 0 deletions
code_new/Sumit/Run_Setup.ipynb
with
168 additions
and
0 deletions
code_new/Sumit/Run_Setup.ipynb
0 → 100644
+
168
−
0
View file @
575cbeb1
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"id": "complimentary-direction",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"b''"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\"\"\"\n",
"Created by Sumit Kumar on 2020-03-08 && modified by Xisco on 2021-04\n",
"Last modified:\n",
"\"\"\"\n",
"\n",
"import os, sys, numpy, glob, argparse\n",
"from datetime import date\n",
"import subprocess\n",
"from subprocess import call\n",
"import re\n",
"\n",
"today = date.today()\n",
"date = today.strftime(\"%Y%m%d\")\n",
"\n",
"runname='run_0_mock'\n",
"nmax = 0\n",
"config_file ='config_n0_to_1_mock.ini'\n",
"\n",
"######\n",
"times = '(0 0.2 0.4 0.8 1.2 2 2.5 5 7.5 10 12 15 18 20)'\n",
"accounting_group = 'cbc.test.pe_ringdown'\n",
"cpus=8\n",
"npoints = 2000\n",
"req_memory=\"16GB\"\n",
"not_user='frjifo@aei.mpg.de'\n",
"pythonfile='/work/francisco.jimenez/sio/git/rdstackingproject/code_new/RD_Fits.py'\n",
"pythonscript='/work/francisco.jimenez/venv/bin/python'\n",
"#######################################################\n",
"\n",
"pwd = os.getcwd()\n",
"run_dir = '%s/%s'%(pwd,runname)\n",
"logs_dir = '%s/logs'%run_dir\n",
"\n",
"os.system('mkdir -p %s'%logs_dir)\n",
"os.system('cp %s %s/'%(config_file,run_dir))\n",
"\n",
"###########################################################################\n",
"# Creating Condor submit file\n",
"###########################################################################\n",
"filename1 = '%s/%s'%(run_dir,'condor_submit')\n",
"text_file1 = open(filename1 + \".sub\", \"w\")\n",
"text_file1.write(\"universe = vanilla\\n\")\n",
"text_file1.write(\"getenv = true\\n\")\n",
"text_file1.write(\"# run script -- make sure that condor has execute permission for this file (chmod a+x script.py)\\n\")\n",
"text_file1.write(\"executable = \"'%s/%s'%(run_dir,runname+'.sh \\n'))\n",
"text_file1.write(\"# file to dump stdout (this directory should exist)\\n\")\n",
"text_file1.write(\"output = %s/%s-$(Process).out\\n\"%(logs_dir,runname))\n",
"text_file1.write(\"# file to dump stderr\\n\")\n",
"text_file1.write(\"error = %s/%s-$(Process).err\\n\"%(logs_dir,runname))\n",
"text_file1.write(\"# condor logs\\n\")\n",
"text_file1.write(\"log = %s/%s-$(Process).log\\n\"%(logs_dir,runname))\n",
"text_file1.write(\"initialdir = %s \\n\"%run_dir)\n",
"text_file1.write(\"notify_user =\"+not_user+' \\n')\n",
"text_file1.write(\"notification = Complete\\n\")\n",
"text_file1.write('''arguments = \"-processid $(Process)\" \\n''')\n",
"text_file1.write(\"request_memory = \"+str(req_memory)+\"\\n\")\n",
"text_file1.write(\"request_cpus = \"+str(cpus)+\"\\n\") \n",
"text_file1.write(\"on_exit_remove = (ExitBySignal == False) || ((ExitBySignal == True) && (ExitSignal != 11))\\n\")\n",
"text_file1.write(\"accounting_group = %s\\n\"%accounting_group)\n",
"text_file1.write(\"queue 1\\n\")\n",
"text_file1.write(\"\\n\")\n",
"text_file1.close()\n",
"\n",
"###########################################################\n",
"# Creating python executable file\n",
"############################################################\n",
"filename2 = run_dir+'/'+runname+'.sh'\n",
"text_file2 = open(filename2, \"w\") \n",
"text_file2.write(\"#! /bin/bash \\n\")\n",
"text_file2.write(\"\\n\")\n",
"text_file2.write(\"times=\"+times+\"\\n\")\n",
"text_file2.write(\"config_file=\"+config_file+\"\\n\")\n",
"text_file2.write(\"pythonfile=\"+pythonfile+\"\\n\")\n",
"text_file2.write(\"pythonscript=\"+pythonscript+\"\\n\")\n",
"text_file2.write(\"\\n\")\n",
"text_file2.write(\"for i in ${times[@]}; do\\n\")\n",
"text_file2.write(\" awk -v a=\\\"$i\\\" '/^tshift/ && $3 != \\\"supplied\\\" { $3=a } { print }' $config_file > tmp && mv tmp $config_file\\n\")\n",
"text_file2.write(\" $pythonscript $pythonfile -c $config_file \\n\")\n",
"text_file2.write(\"done\\n\")\n",
"text_file2.write(\"awk -v a=\\\"0\\\" '/^tshift/ && $3 != \\\"supplied\\\" { $3=a } { print }' $config_file > tmp && mv tmp $config_file \\n\")\n",
"text_file2.write(\"\\n\")\n",
"text_file2.close()\n",
"os.system('chmod u+x %s'%filename2)\n",
"\n",
"os.system('cp '+runname+'.sh %s/'%run_dir)\n",
"os.system('chmod u+x ./'+runname+'.sh')\n",
"os.system('cd '+run_dir)\n",
"\n",
"###########################################################\n",
"# Checking the configuration file and adding some important replacements\n",
"############################################################\n",
"\n",
"filename3 = '%s/%s'%(run_dir,config_file)\n",
"# change the number of cores\n",
"bashCommand = \"awk -v a=\"+str(cpus)+\" '/^nb_cores/ && $3 != \\\"supplied\\\" { $3=a } { print }' \"+str(config_file)+\" > tmp && mv tmp \"+str(config_file);\n",
"subprocess.call(bashCommand,shell=True)\n",
"\n",
"filename3 = '%s/%s'%(run_dir,config_file)\n",
"# change the number of nmax\n",
"bashCommand = \"awk -v a=\"+str(nmax)+\" '/^nmax/ && $3 != \\\"supplied\\\" { $3=a } { print }' \"+str(config_file)+\" > tmp && mv tmp \"+str(config_file);\n",
"subprocess.call(bashCommand,shell=True)\n",
"\n",
"filename3 = '%s/%s'%(run_dir,config_file)\n",
"# change the number of nmax\n",
"bashCommand = \"awk -v a=\"+str(npoints)+\" '/^npoints/ && $3 != \\\"supplied\\\" { $3=a } { print }' \"+str(config_file)+\" > tmp && mv tmp \"+str(config_file);\n",
"subprocess.call(bashCommand,shell=True)\n",
"\n",
"###########################################################\n",
"# Submit the job\n",
"############################################################\n",
"filename4 = '%s/%s'%(run_dir,'condor_submit.sub')\n",
"bashCommand = ['condor_submit', str(filename4)]\n",
"process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE,stderr=subprocess.PIPE);\n",
"output,error = process.communicate()\n",
"error"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "collect-bearing",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
%% Cell type:code id:complimentary-direction tags:
```
python
"""
Created by Sumit Kumar on 2020-03-08 && modified by Xisco on 2021-04
Last modified:
"""
import
os
,
sys
,
numpy
,
glob
,
argparse
from
datetime
import
date
import
subprocess
from
subprocess
import
call
import
re
today
=
date
.
today
()
date
=
today
.
strftime
(
"
%Y%m%d
"
)
runname
=
'
run_0_mock
'
nmax
=
0
config_file
=
'
config_n0_to_1_mock.ini
'
######
times
=
'
(0 0.2 0.4 0.8 1.2 2 2.5 5 7.5 10 12 15 18 20)
'
accounting_group
=
'
cbc.test.pe_ringdown
'
cpus
=
8
npoints
=
2000
req_memory
=
"
16GB
"
not_user
=
'
frjifo@aei.mpg.de
'
pythonfile
=
'
/work/francisco.jimenez/sio/git/rdstackingproject/code_new/RD_Fits.py
'
pythonscript
=
'
/work/francisco.jimenez/venv/bin/python
'
#######################################################
pwd
=
os
.
getcwd
()
run_dir
=
'
%s/%s
'
%
(
pwd
,
runname
)
logs_dir
=
'
%s/logs
'
%
run_dir
os
.
system
(
'
mkdir -p %s
'
%
logs_dir
)
os
.
system
(
'
cp %s %s/
'
%
(
config_file
,
run_dir
))
###########################################################################
# Creating Condor submit file
###########################################################################
filename1
=
'
%s/%s
'
%
(
run_dir
,
'
condor_submit
'
)
text_file1
=
open
(
filename1
+
"
.sub
"
,
"
w
"
)
text_file1
.
write
(
"
universe = vanilla
\n
"
)
text_file1
.
write
(
"
getenv = true
\n
"
)
text_file1
.
write
(
"
# run script -- make sure that condor has execute permission for this file (chmod a+x script.py)
\n
"
)
text_file1
.
write
(
"
executable =
"'
%s/%s
'
%
(
run_dir
,
runname
+
'
.sh
\n
'
))
text_file1
.
write
(
"
# file to dump stdout (this directory should exist)
\n
"
)
text_file1
.
write
(
"
output = %s/%s-$(Process).out
\n
"
%
(
logs_dir
,
runname
))
text_file1
.
write
(
"
# file to dump stderr
\n
"
)
text_file1
.
write
(
"
error = %s/%s-$(Process).err
\n
"
%
(
logs_dir
,
runname
))
text_file1
.
write
(
"
# condor logs
\n
"
)
text_file1
.
write
(
"
log = %s/%s-$(Process).log
\n
"
%
(
logs_dir
,
runname
))
text_file1
.
write
(
"
initialdir = %s
\n
"
%
run_dir
)
text_file1
.
write
(
"
notify_user =
"
+
not_user
+
'
\n
'
)
text_file1
.
write
(
"
notification = Complete
\n
"
)
text_file1
.
write
(
'''
arguments =
"
-processid $(Process)
"
\n
'''
)
text_file1
.
write
(
"
request_memory =
"
+
str
(
req_memory
)
+
"
\n
"
)
text_file1
.
write
(
"
request_cpus =
"
+
str
(
cpus
)
+
"
\n
"
)
text_file1
.
write
(
"
on_exit_remove = (ExitBySignal == False) || ((ExitBySignal == True) && (ExitSignal != 11))
\n
"
)
text_file1
.
write
(
"
accounting_group = %s
\n
"
%
accounting_group
)
text_file1
.
write
(
"
queue 1
\n
"
)
text_file1
.
write
(
"
\n
"
)
text_file1
.
close
()
###########################################################
# Creating python executable file
############################################################
filename2
=
run_dir
+
'
/
'
+
runname
+
'
.sh
'
text_file2
=
open
(
filename2
,
"
w
"
)
text_file2
.
write
(
"
#! /bin/bash
\n
"
)
text_file2
.
write
(
"
\n
"
)
text_file2
.
write
(
"
times=
"
+
times
+
"
\n
"
)
text_file2
.
write
(
"
config_file=
"
+
config_file
+
"
\n
"
)
text_file2
.
write
(
"
pythonfile=
"
+
pythonfile
+
"
\n
"
)
text_file2
.
write
(
"
pythonscript=
"
+
pythonscript
+
"
\n
"
)
text_file2
.
write
(
"
\n
"
)
text_file2
.
write
(
"
for i in ${times[@]}; do
\n
"
)
text_file2
.
write
(
"
awk -v a=
\"
$i
\"
'
/^tshift/ && $3 !=
\"
supplied
\"
{ $3=a } { print }
'
$config_file > tmp && mv tmp $config_file
\n
"
)
text_file2
.
write
(
"
$pythonscript $pythonfile -c $config_file
\n
"
)
text_file2
.
write
(
"
done
\n
"
)
text_file2
.
write
(
"
awk -v a=
\"
0
\"
'
/^tshift/ && $3 !=
\"
supplied
\"
{ $3=a } { print }
'
$config_file > tmp && mv tmp $config_file
\n
"
)
text_file2
.
write
(
"
\n
"
)
text_file2
.
close
()
os
.
system
(
'
chmod u+x %s
'
%
filename2
)
os
.
system
(
'
cp
'
+
runname
+
'
.sh %s/
'
%
run_dir
)
os
.
system
(
'
chmod u+x ./
'
+
runname
+
'
.sh
'
)
os
.
system
(
'
cd
'
+
run_dir
)
###########################################################
# Checking the configuration file and adding some important replacements
############################################################
filename3
=
'
%s/%s
'
%
(
run_dir
,
config_file
)
# change the number of cores
bashCommand
=
"
awk -v a=
"
+
str
(
cpus
)
+
"
'
/^nb_cores/ && $3 !=
\"
supplied
\"
{ $3=a } { print }
'
"
+
str
(
config_file
)
+
"
> tmp && mv tmp
"
+
str
(
config_file
);
subprocess
.
call
(
bashCommand
,
shell
=
True
)
filename3
=
'
%s/%s
'
%
(
run_dir
,
config_file
)
# change the number of nmax
bashCommand
=
"
awk -v a=
"
+
str
(
nmax
)
+
"
'
/^nmax/ && $3 !=
\"
supplied
\"
{ $3=a } { print }
'
"
+
str
(
config_file
)
+
"
> tmp && mv tmp
"
+
str
(
config_file
);
subprocess
.
call
(
bashCommand
,
shell
=
True
)
filename3
=
'
%s/%s
'
%
(
run_dir
,
config_file
)
# change the number of nmax
bashCommand
=
"
awk -v a=
"
+
str
(
npoints
)
+
"
'
/^npoints/ && $3 !=
\"
supplied
\"
{ $3=a } { print }
'
"
+
str
(
config_file
)
+
"
> tmp && mv tmp
"
+
str
(
config_file
);
subprocess
.
call
(
bashCommand
,
shell
=
True
)
###########################################################
# Submit the job
############################################################
filename4
=
'
%s/%s
'
%
(
run_dir
,
'
condor_submit.sub
'
)
bashCommand
=
[
'
condor_submit
'
,
str
(
filename4
)]
process
=
subprocess
.
Popen
(
bashCommand
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
);
output
,
error
=
process
.
communicate
()
error
```
%% Output
b''
%% Cell type:code id:collect-bearing tags:
```
python
```
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