Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102861283
kperp_scan.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, Feb 24, 23:13
Size
3 KB
Mime Type
text/x-python
Expires
Wed, Feb 26, 23:13 (2 d)
Engine
blob
Format
Raw Data
Handle
24444019
Attached To
rCOSOLVER COSOlver
kperp_scan.py
View Options
#!/usr/bin/env python
# generates GK collision matrices for different kperp
import
os
import
sys
import
f90nml
import
numpy
as
np
# To create directory, if doesn't exist
def
mkdir_p
(
dir
):
'''make a directory (dir) if it doesn't exist'''
if
not
os
.
path
.
exists
(
dir
):
print
(
'Create '
,
dir
)
os
.
mkdir
(
dir
)
# directories
cwd_directory
=
os
.
getcwd
()
scandir_name
=
'gk.sugama'
scandir_path
=
os
.
path
.
join
(
cwd_directory
,
scandir_name
)
# Where to find the exec
exec_path
=
"/marconi/home/userexternal/bfrei000/cosolver/bin/CO"
exec_name
=
'CO'
# Read input namelist
input_file
=
os
.
path
.
join
(
cwd_directory
,
"fort.90"
)
with
open
(
input_file
)
as
fh
:
inputs
=
f90nml
.
read
(
fh
)
# Define kperp scan
coordkperp
=
np
.
linspace
(
0.1
,
10
,
4
)
# Define job name
job_name
=
'gk.sugama'
# Define jobfile name
job_file_name
=
'job.submit.cmd'
if
len
(
sys
.
argv
)
==
2
:
scan_mode
=
sys
.
argv
[
1
]
else
:
print
(
'You need to specified the thing to do (e.g. python scanscritpt (create/run)'
)
if
scan_mode
==
'create'
:
print
(
'Create scan:'
)
# Make top level directories
mkdir_p
(
scandir_path
)
# Flush out paramscan
with
open
(
os
.
path
.
join
(
scandir_path
,
'kperp.log'
)
,
'w'
)
as
fh
:
for
kperp
in
coordkperp
:
fh
.
write
(
"
%s
\n
"
%
kperp
)
for
ikperp
,
kperp
in
enumerate
(
coordkperp
):
job_directory
=
os
.
path
.
join
(
scandir_path
,
"scanfiles_"
+
"{0:05d}"
.
format
(
ikperp
))
mkdir_p
(
job_directory
)
# Create symbolic link to exec
os
.
system
(
"ln -s "
+
exec_path
+
" "
+
os
.
path
.
join
(
job_directory
,
exec_name
))
# Update kperp
inputs
[
'model_par'
][
'kperp'
]
=
kperp
# Flush out the input parameters in job_directory
inputs
.
write
(
os
.
path
.
join
(
job_directory
,
"fort.90"
),
'w'
)
# copy T4.in file
os
.
system
(
"cp T4.in "
+
os
.
path
.
join
(
job_directory
,
"T4.in"
)
)
# Create submit slurm script in job_directory
job_file_path
=
os
.
path
.
join
(
job_directory
,
job_file_name
)
with
open
(
job_file_path
,
'w'
)
as
fh
:
fh
.
writelines
(
"#!/bin/bash
\n
"
)
fh
.
writelines
(
"#SBATCH -J "
+
job_name
+
"
\n
"
)
fh
.
writelines
(
"#SBATCH --nodes=1
\n
"
)
fh
.
writelines
(
"#SBATCH --ntasks-per-node=6
\n
"
)
fh
.
writelines
(
"#SBATCH --time=01:00:00
\n
"
)
fh
.
writelines
(
"#SBATCH --error=
%x
.%j.err
\n
"
)
fh
.
writelines
(
"#SBATCH --output=
%x
.%j.out
\n
"
)
fh
.
writelines
(
"#SBATCH --account=FUA35_TSVVT421
\n
"
)
fh
.
writelines
(
"#SBATCH --partition=skl_fua_dbg
\n
"
)
fh
.
writelines
(
"#SBATCH --mail-type=ALL
\n
"
)
fh
.
writelines
(
"#SBATCH --mail-user=baptiste.frei@epfl.ch
\n
"
)
# sum of <nprocs_ei> <nprocs_ie> <nprocs_self> must be equal to <ntasks-per-node x nodes>
fh
.
writelines
(
"srun ./CO 2 2 2
\n
"
)
elif
scan_mode
==
'run'
:
print
(
'Run scan:'
)
for
ikperp
,
kperp
in
enumerate
(
coordkperp
):
job_directory
=
os
.
path
.
join
(
scandir_path
,
"scanfiles_"
+
"{0:05d}"
.
format
(
ikperp
))
job_file_path
=
os
.
path
.
join
(
job_directory
,
job_file_name
)
print
(
'Submit job '
+
job_file_path
)
os
.
system
(
'cd '
+
job_directory
+
'; sbatch '
+
job_file_name
)
else
:
print
(
'Cannot recognize scanmode'
)
Event Timeline
Log In to Comment