From 1e9fadc3fdb699ba0e2c895f04dfba520ec3a3b3 Mon Sep 17 00:00:00 2001 From: Amirpasha Mozaffari Date: Mon, 26 Jun 2023 17:06:05 +0200 Subject: [PATCH 1/5] initial yaml file and yaml reader script is created. --- sources/ece3-toy-model/example_input.yaml | 45 +++++++++++++++++++++++ sources/ece3-toy-model/read_in_yaml.py | 7 ++++ sources/ece3-toy-model/yaml_mn4.cmd | 43 ++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 sources/ece3-toy-model/example_input.yaml create mode 100644 sources/ece3-toy-model/read_in_yaml.py create mode 100644 sources/ece3-toy-model/yaml_mn4.cmd diff --git a/sources/ece3-toy-model/example_input.yaml b/sources/ece3-toy-model/example_input.yaml new file mode 100644 index 0000000..635c586 --- /dev/null +++ b/sources/ece3-toy-model/example_input.yaml @@ -0,0 +1,45 @@ +# The idea is to have a single YAML file that inlcudes key-value pair. All models will read the YAML file. +# If the key is contained, they will replace the default values with the value from the YAML files. +# IFS +--- +model_name: ifs_toy +# grid information +number_land_grid_cells : + t159 : 35718 # number of LAND grid cells at T159 resolution + t255 : 88838 # number of LAND grid cells at T255 resolution + t511 : 348528 # number of LAND grid cells at T511 resolution + +# simulation information +coupling_intervals : 2700 +run_length_sec : 86400 + +# OASIS infomration +oasis: + component: IFS_TOY + output_unit: IFS_toy.out_'+str(100+mype) + # Definition of the local partition + nx : L128_NX + +coupling: + out_fields : {} + out_vars : + - A_TauX_oce + - A_TauY_oce + - A_TauX_ice + - A_TauY_ice + - A_Qns_mix + - A_Qs_mix + - A_Evap_total + - A_Precip_liquid + - A_Precip_solid + - A_Qs_ice" + - A_Qns_ice + - A_dQns_dT + - A_Evap_ice + - A_Runoff + - A_Calving + + + + +... diff --git a/sources/ece3-toy-model/read_in_yaml.py b/sources/ece3-toy-model/read_in_yaml.py new file mode 100644 index 0000000..a4e2af5 --- /dev/null +++ b/sources/ece3-toy-model/read_in_yaml.py @@ -0,0 +1,7 @@ +import yaml +from yaml.loader import SafeLoader + +# Open the file and load the file +with open('example_input.yaml') as f: + data = yaml.load(f, Loader=SafeLoader) + print(data) diff --git a/sources/ece3-toy-model/yaml_mn4.cmd b/sources/ece3-toy-model/yaml_mn4.cmd new file mode 100644 index 0000000..fb8d3b2 --- /dev/null +++ b/sources/ece3-toy-model/yaml_mn4.cmd @@ -0,0 +1,43 @@ +#!/bin/bash + +# slurm specific options for Marenostrum4 +#SBATCH --qos=debug +#SBATCH -N 1 +#SBATCH -n 3 +#SBATCH -c 1 +#SBATCH -t 1:00:00 +#SBATCH --exclusive + +#load python and netcdf modules +export PYTHONPATH="" +module load python/3.6.1 +module load netcdf/4.2 + +#set -xuve + +## setup pyOasis environment +#export PYOASIS_ROOT=/gpfs/scratch/bsc32/bsc32051/git/python-amip-reader/sources/oasis3-mct/generated +#export LD_LIBRARY_PATH=${PYOASIS_ROOT}/lib:${LD_LIBRARY_PATH} +#export PYTHONPATH=${PYOASIS_ROOT}/python:${PYTHONPATH} +#export MPIRUN4PY="mpirun" + +## prepare rundir +#rundir=run/ +srcdir=`pwd` +#datadir=/gpfs/scratch/bsc32/bsc32051/git/python-amip-reader/tests/data/ece3-toy-model + +#rm -rf $rundir +#mkdir -p $rundir + +#for f in masks.nc grids.nc areas.nc rstas.nc rstos.nc; do +# cp -f $datadir/$f $rundir +#done +#cp -f $datadir/rmp* $rundir +#cp -f $srcdir/*.py $rundir +#cp -f $srcdir/namcouple $rundir + +#cd $rundir + +# run IFS+NEMO+runoff toy model +# mpirun -np 1 python3 $srcdir/IFS_toy.py : -np 1 python3 $srcdir/NEMO_toy.py : -np 1 python3 $srcdir/RUNOFF_toy.py +mpirun -np 1 python3 $srcdir/read_in_yaml.py \ No newline at end of file -- GitLab From d04f1005bd614fd70a96a52a6c949ccdcf1bcc24 Mon Sep 17 00:00:00 2001 From: Amirpasha Mozaffari Date: Tue, 27 Jun 2023 17:05:04 +0200 Subject: [PATCH 2/5] general YAML reading script, 3 example of YAML for ifs, nemo, runoff models --- ...mple_input.yaml => example_input_ifs.yaml} | 13 ++- .../ece3-toy-model/example_input_nemo.yaml | 37 +++++++++ .../ece3-toy-model/example_input_runoff.yaml | 30 +++++++ sources/ece3-toy-model/read_in_yaml.py | 82 ++++++++++++++++++- sources/ece3-toy-model/yaml_mn4.cmd | 14 ++-- 5 files changed, 162 insertions(+), 14 deletions(-) rename sources/ece3-toy-model/{example_input.yaml => example_input_ifs.yaml} (87%) create mode 100644 sources/ece3-toy-model/example_input_nemo.yaml create mode 100644 sources/ece3-toy-model/example_input_runoff.yaml diff --git a/sources/ece3-toy-model/example_input.yaml b/sources/ece3-toy-model/example_input_ifs.yaml similarity index 87% rename from sources/ece3-toy-model/example_input.yaml rename to sources/ece3-toy-model/example_input_ifs.yaml index 635c586..7ac5599 100644 --- a/sources/ece3-toy-model/example_input.yaml +++ b/sources/ece3-toy-model/example_input_ifs.yaml @@ -38,8 +38,13 @@ coupling: - A_Evap_ice - A_Runoff - A_Calving - - - - + + in_fields : {} + in_vars : + - A_SST + - A_Ice_temp + - A_Ice_albedo + - A_Ice_frac + - A_Ice_thickness + - A_Snow_thickness" ... diff --git a/sources/ece3-toy-model/example_input_nemo.yaml b/sources/ece3-toy-model/example_input_nemo.yaml new file mode 100644 index 0000000..615ee33 --- /dev/null +++ b/sources/ece3-toy-model/example_input_nemo.yaml @@ -0,0 +1,37 @@ +# The idea is to have a single YAML file that inlcudes key-value pair. All models will read the YAML file. +# If the key is contained, they will replace the default values with the value from the YAML files. +# IFS +--- +model_name: nemo_toy +# grid information + +# simulation information +coupling_intervals : 2700 +run_length_sec : 86400 + +# OASIS infomration +oasis: + component: NEMO_TOY + output_unit: NEMO_toy.out_'+str(100+mype) + # Definition of the local partition + nx : 362 * 292 + +coupling: + out_fields : {} + out_vars : + - O_SSTSST + - O_TepIce + - O_AlbIce + - OIceFrc + - OIceTck + - OSnwTck + + in_fields : {} + in_vars : + - O_OTaux1 + - O_OTauy1 + - O_ITaux1 + - O_ITauy1 + - O_OTaux2 + - O_OTauy2 +... diff --git a/sources/ece3-toy-model/example_input_runoff.yaml b/sources/ece3-toy-model/example_input_runoff.yaml new file mode 100644 index 0000000..83df6bd --- /dev/null +++ b/sources/ece3-toy-model/example_input_runoff.yaml @@ -0,0 +1,30 @@ +# The idea is to have a single YAML file that inlcudes key-value pair. All models will read the YAML file. +# If the key is contained, they will replace the default values with the value from the YAML files. +# IFS +--- +model_name: runoff_toy +# grid information + +# simulation information +coupling_intervals : 2700 +run_length_sec : 86400 + +# OASIS infomration +oasis: + component: RUNOFF_TOY + output_unit: RUNOFF_toy.out_'+str(100+mype) + # Definition of the local partition + nx : 512 * 256 + +coupling: + out_fields : {} + out_vars : + - R_Runoff_oce + - R_Calving_oce + + in_fields : {} + in_vars : + - R_Runoff_atm + - R_Calving_atm + +... diff --git a/sources/ece3-toy-model/read_in_yaml.py b/sources/ece3-toy-model/read_in_yaml.py index a4e2af5..7238dcd 100644 --- a/sources/ece3-toy-model/read_in_yaml.py +++ b/sources/ece3-toy-model/read_in_yaml.py @@ -1,7 +1,83 @@ import yaml from yaml.loader import SafeLoader +import f90nml +import pyoasis +from pyoasis import OASIS # pylint: disable=no-name-in-module +import numpy as np +import logging + + + +# to be placed in IFS_toy script +def read_yaml(read_in_data): + print("YAML file is read ... ") + + # TODO : make this section generalized + if model_name == "ifs_toy": + print("DEBUG: Toy ifs function is called") + number_land_grid_cells = read_in_data.get("number_land_grid_cells") + t159 = number_land_grid_cells.get("t159") + t255 = number_land_grid_cells.get("t255") + t511 = number_land_grid_cells.get("t511") + else: + t159 = "" + t255 = "" + t511 = "" + + # Read in Simulation information + coupling_intervals = read_in_data.get("coupling_intervals") + run_length_sec = read_in_data.get("run_length_sec") + + # Read in Oasis information + oasis = read_in_data.get("oasis") + oasis_component = oasis.get("component") + oasis_output_unit = oasis.get("output_unit") + oasis_nx = oasis.get("nx") + + # Read in Coupling infomration + coupling = read_in_data.get("coupling") + coupling_out_fields = coupling.get("out_fields") + coupling_out_vars = coupling.get("out_vars") + coupling_in_fields = coupling.get("in_fields") + coupling_in_vars = coupling.get("in_vars") + + #print(number_land_grid_cells) + # TODO : it is only for testing now. The next block will be gone. + try: + print(number_land_grid_cells) + except: + print("There is no valye for number of land grid cells") + + print(oasis) + print(coupling_out_fields) + print(coupling_in_vars) + + #return(t159,t255, t511, coupling_intervals, run_length_sec, oasis_component,oasis_output_unit, \ + # oasis_nx,coupling_out_fields, coupling_out_vars, coupling_in_fields, coupling_in_vars) + + +def build_toy_model(): + print("The build script will be here") + + + +if __name__ == '__main__': # Open the file and load the file -with open('example_input.yaml') as f: - data = yaml.load(f, Loader=SafeLoader) - print(data) + #with open('example_input_runoff.yaml') as f: + with open('example_input_nemo.yaml') as f: + #with open('example_input.yaml') as f: + read_in_data = yaml.load(f, Loader=SafeLoader) + model_name = read_in_data.get("model_name") + print(model_name) + f.close() + + # TODO should be initialized as function + #t159,t255, t511, coupling_intervals, run_length_sec, oasis_component,oasis_output_unit,oasis_nx,coupling_out_fields, coupling_out_vars, coupling_in_fields, coupling_in_vars = {} + + read_yaml(read_in_data) + build_toy_model()#t159,t255, t511, coupling_intervals, run_length_sec, oasis_component,oasis_output_unit, oasis_nx,coupling_out_fields, coupling_out_vars, coupling_in_fields, coupling_in_vars) + + exit() + + diff --git a/sources/ece3-toy-model/yaml_mn4.cmd b/sources/ece3-toy-model/yaml_mn4.cmd index fb8d3b2..a0c90d3 100644 --- a/sources/ece3-toy-model/yaml_mn4.cmd +++ b/sources/ece3-toy-model/yaml_mn4.cmd @@ -5,7 +5,7 @@ #SBATCH -N 1 #SBATCH -n 3 #SBATCH -c 1 -#SBATCH -t 1:00:00 +#SBATCH -t 00:05:00 #SBATCH --exclusive #load python and netcdf modules @@ -13,13 +13,13 @@ export PYTHONPATH="" module load python/3.6.1 module load netcdf/4.2 -#set -xuve +set -xuve -## setup pyOasis environment -#export PYOASIS_ROOT=/gpfs/scratch/bsc32/bsc32051/git/python-amip-reader/sources/oasis3-mct/generated -#export LD_LIBRARY_PATH=${PYOASIS_ROOT}/lib:${LD_LIBRARY_PATH} -#export PYTHONPATH=${PYOASIS_ROOT}/python:${PYTHONPATH} -#export MPIRUN4PY="mpirun" +# setup pyOasis environment +export PYOASIS_ROOT=/gpfs/scratch/bsc32/bsc32051/git/python-amip-reader/sources/oasis3-mct/generated +export LD_LIBRARY_PATH=${PYOASIS_ROOT}/lib:${LD_LIBRARY_PATH} +export PYTHONPATH=${PYOASIS_ROOT}/python:${PYTHONPATH} +export MPIRUN4PY="mpirun" ## prepare rundir #rundir=run/ -- GitLab From 4bed6e107bfa20e9e75f79106640877a25ff96fe Mon Sep 17 00:00:00 2001 From: Amirpasha Mozaffari Date: Wed, 28 Jun 2023 18:06:57 +0200 Subject: [PATCH 3/5] the toy model read the yamel file and works with oasis - only tested for ifs, todo: refactor, restructure in modules, logging and error handling --- sources/ece3-toy-model/example_input_ifs.yaml | 50 ----- .../ece3-toy-model/example_input_nemo.yaml | 37 ---- .../ece3-toy-model/example_input_runoff.yaml | 30 --- .../ece3-toy-model/ifs_toy_model_example.yaml | 44 +++++ sources/ece3-toy-model/launch_yaml_mn4.cmd | 47 +++++ .../nemo_toy_model_example.yaml | 31 +++ sources/ece3-toy-model/read_in_yaml.py | 83 --------- .../runoff_toy_model_example.yaml | 23 +++ sources/ece3-toy-model/toy_model.py | 176 ++++++++++++++++++ sources/ece3-toy-model/yaml_mn4.cmd | 22 +-- 10 files changed, 332 insertions(+), 211 deletions(-) delete mode 100644 sources/ece3-toy-model/example_input_ifs.yaml delete mode 100644 sources/ece3-toy-model/example_input_nemo.yaml delete mode 100644 sources/ece3-toy-model/example_input_runoff.yaml create mode 100644 sources/ece3-toy-model/ifs_toy_model_example.yaml create mode 100644 sources/ece3-toy-model/launch_yaml_mn4.cmd create mode 100644 sources/ece3-toy-model/nemo_toy_model_example.yaml delete mode 100644 sources/ece3-toy-model/read_in_yaml.py create mode 100644 sources/ece3-toy-model/runoff_toy_model_example.yaml create mode 100644 sources/ece3-toy-model/toy_model.py diff --git a/sources/ece3-toy-model/example_input_ifs.yaml b/sources/ece3-toy-model/example_input_ifs.yaml deleted file mode 100644 index 7ac5599..0000000 --- a/sources/ece3-toy-model/example_input_ifs.yaml +++ /dev/null @@ -1,50 +0,0 @@ -# The idea is to have a single YAML file that inlcudes key-value pair. All models will read the YAML file. -# If the key is contained, they will replace the default values with the value from the YAML files. -# IFS ---- -model_name: ifs_toy -# grid information -number_land_grid_cells : - t159 : 35718 # number of LAND grid cells at T159 resolution - t255 : 88838 # number of LAND grid cells at T255 resolution - t511 : 348528 # number of LAND grid cells at T511 resolution - -# simulation information -coupling_intervals : 2700 -run_length_sec : 86400 - -# OASIS infomration -oasis: - component: IFS_TOY - output_unit: IFS_toy.out_'+str(100+mype) - # Definition of the local partition - nx : L128_NX - -coupling: - out_fields : {} - out_vars : - - A_TauX_oce - - A_TauY_oce - - A_TauX_ice - - A_TauY_ice - - A_Qns_mix - - A_Qs_mix - - A_Evap_total - - A_Precip_liquid - - A_Precip_solid - - A_Qs_ice" - - A_Qns_ice - - A_dQns_dT - - A_Evap_ice - - A_Runoff - - A_Calving - - in_fields : {} - in_vars : - - A_SST - - A_Ice_temp - - A_Ice_albedo - - A_Ice_frac - - A_Ice_thickness - - A_Snow_thickness" -... diff --git a/sources/ece3-toy-model/example_input_nemo.yaml b/sources/ece3-toy-model/example_input_nemo.yaml deleted file mode 100644 index 615ee33..0000000 --- a/sources/ece3-toy-model/example_input_nemo.yaml +++ /dev/null @@ -1,37 +0,0 @@ -# The idea is to have a single YAML file that inlcudes key-value pair. All models will read the YAML file. -# If the key is contained, they will replace the default values with the value from the YAML files. -# IFS ---- -model_name: nemo_toy -# grid information - -# simulation information -coupling_intervals : 2700 -run_length_sec : 86400 - -# OASIS infomration -oasis: - component: NEMO_TOY - output_unit: NEMO_toy.out_'+str(100+mype) - # Definition of the local partition - nx : 362 * 292 - -coupling: - out_fields : {} - out_vars : - - O_SSTSST - - O_TepIce - - O_AlbIce - - OIceFrc - - OIceTck - - OSnwTck - - in_fields : {} - in_vars : - - O_OTaux1 - - O_OTauy1 - - O_ITaux1 - - O_ITauy1 - - O_OTaux2 - - O_OTauy2 -... diff --git a/sources/ece3-toy-model/example_input_runoff.yaml b/sources/ece3-toy-model/example_input_runoff.yaml deleted file mode 100644 index 83df6bd..0000000 --- a/sources/ece3-toy-model/example_input_runoff.yaml +++ /dev/null @@ -1,30 +0,0 @@ -# The idea is to have a single YAML file that inlcudes key-value pair. All models will read the YAML file. -# If the key is contained, they will replace the default values with the value from the YAML files. -# IFS ---- -model_name: runoff_toy -# grid information - -# simulation information -coupling_intervals : 2700 -run_length_sec : 86400 - -# OASIS infomration -oasis: - component: RUNOFF_TOY - output_unit: RUNOFF_toy.out_'+str(100+mype) - # Definition of the local partition - nx : 512 * 256 - -coupling: - out_fields : {} - out_vars : - - R_Runoff_oce - - R_Calving_oce - - in_fields : {} - in_vars : - - R_Runoff_atm - - R_Calving_atm - -... diff --git a/sources/ece3-toy-model/ifs_toy_model_example.yaml b/sources/ece3-toy-model/ifs_toy_model_example.yaml new file mode 100644 index 0000000..a90fb2f --- /dev/null +++ b/sources/ece3-toy-model/ifs_toy_model_example.yaml @@ -0,0 +1,44 @@ +# Copyright 2023 - Barcelona Supercomputing Center +# Author: Amirpasha Mozaffari +# TBD +--- + +model: + model_name: IFS_TOY + +simulation: + coupling_interval : 2700 + run_length_sec : 86400 + # Definition of the local partition grid cell + # L080_NX = 35718 # number of LAND grid cells at T159 resolution + # L128_NX = 88838 # number of LAND grid cells at T255 resolution + # L256_NX = 348528 # number of LAND grid cells at T511 resolution + nx : 88838 + + +coupling: + out_vars : + - A_TauX_oce + - A_TauY_oce + - A_TauX_ice + - A_TauY_ice + - A_Qns_mix + - A_Qs_mix + - A_Evap_total + - A_Precip_liquid + - A_Precip_solid + - A_Qs_ice + - A_Qns_ice + - A_dQns_dT + - A_Evap_ice + - A_Runoff + - A_Calving + + in_vars : + - A_SST + - A_Ice_temp + - A_Ice_albedo + - A_Ice_frac + - A_Ice_thickness + - A_Snow_thickness +... diff --git a/sources/ece3-toy-model/launch_yaml_mn4.cmd b/sources/ece3-toy-model/launch_yaml_mn4.cmd new file mode 100644 index 0000000..cf93908 --- /dev/null +++ b/sources/ece3-toy-model/launch_yaml_mn4.cmd @@ -0,0 +1,47 @@ +#!/bin/bash + +# slurm specific options for Marenostrum4 +#SBATCH --qos=debug +#SBATCH -N 1 +#SBATCH -n 3 +#SBATCH -c 1 +#SBATCH -t 1:00:00 +#SBATCH --exclusive + +#load python and netcdf modules +export PYTHONPATH="" +module load python/3.6.1 +module load netcdf/4.2 + +set -xuve + +# setup pyOasis environment +export PYOASIS_ROOT=/gpfs/scratch/bsc32/bsc32051/git/python-amip-reader/sources/oasis3-mct/generated +export LD_LIBRARY_PATH=${PYOASIS_ROOT}/lib:${LD_LIBRARY_PATH} +export PYTHONPATH=${PYOASIS_ROOT}/python:${PYTHONPATH} +export MPIRUN4PY="mpirun" + +# prepare rundir +rundir=run/ +#srcdir=`pwd` +srcdir=/gpfs/scratch/bsc32/bsc32013/ec_earth/amip/python-amip-reader/sources/ece3-toy-model +datadir=/gpfs/scratch/bsc32/bsc32051/git/python-amip-reader/tests/data/ece3-toy-model +apmdir=/gpfs/scratch/bsc32/bsc32013/ec_earth/amip/python-amip-reader/sources/ece3-toy-model + +rm -rf $rundir +mkdir -p $rundir + +for f in masks.nc grids.nc areas.nc rstas.nc rstos.nc; do + cp -f $datadir/$f $rundir +done +cp -f $datadir/rmp* $rundir +cp -f $srcdir/*.py $rundir +cp -f $srcdir/namcouple $rundir +cp -f $apmdir/*.py $rundir +cp -f $apmdir/*.yaml $rundir + + +cd $rundir + +# run IFS+NEMO+runoff toy model +mpirun -np 1 python3 $srcdir/toy_model.py : -np 1 python3 $srcdir/NEMO_toy.py : -np 1 python3 $srcdir/RUNOFF_toy.py diff --git a/sources/ece3-toy-model/nemo_toy_model_example.yaml b/sources/ece3-toy-model/nemo_toy_model_example.yaml new file mode 100644 index 0000000..4229f66 --- /dev/null +++ b/sources/ece3-toy-model/nemo_toy_model_example.yaml @@ -0,0 +1,31 @@ +# Copyright 2023 - Barcelona Supercomputing Center +# Author: Amirpasha Mozaffari +# TBD +--- + +model: + model_name: NEMO_TOY + +simulation: + coupling_interval : 2700 + run_length_sec : 86400 + nx : 362 * 292 + + +coupling: + out_vars : + - O_SSTSST + - O_TepIce + - O_AlbIce + - OIceFrc + - OIceTck + - OSnwTck + + in_vars : + - O_OTaux1 + - O_OTauy1 + - O_ITaux1 + - O_ITauy1 + - O_OTaux2 + - O_OTauy2 +... diff --git a/sources/ece3-toy-model/read_in_yaml.py b/sources/ece3-toy-model/read_in_yaml.py deleted file mode 100644 index 7238dcd..0000000 --- a/sources/ece3-toy-model/read_in_yaml.py +++ /dev/null @@ -1,83 +0,0 @@ -import yaml -from yaml.loader import SafeLoader - -import f90nml -import pyoasis -from pyoasis import OASIS # pylint: disable=no-name-in-module -import numpy as np -import logging - - - -# to be placed in IFS_toy script -def read_yaml(read_in_data): - print("YAML file is read ... ") - - # TODO : make this section generalized - if model_name == "ifs_toy": - print("DEBUG: Toy ifs function is called") - number_land_grid_cells = read_in_data.get("number_land_grid_cells") - t159 = number_land_grid_cells.get("t159") - t255 = number_land_grid_cells.get("t255") - t511 = number_land_grid_cells.get("t511") - else: - t159 = "" - t255 = "" - t511 = "" - - # Read in Simulation information - coupling_intervals = read_in_data.get("coupling_intervals") - run_length_sec = read_in_data.get("run_length_sec") - - # Read in Oasis information - oasis = read_in_data.get("oasis") - oasis_component = oasis.get("component") - oasis_output_unit = oasis.get("output_unit") - oasis_nx = oasis.get("nx") - - # Read in Coupling infomration - coupling = read_in_data.get("coupling") - coupling_out_fields = coupling.get("out_fields") - coupling_out_vars = coupling.get("out_vars") - coupling_in_fields = coupling.get("in_fields") - coupling_in_vars = coupling.get("in_vars") - - #print(number_land_grid_cells) - # TODO : it is only for testing now. The next block will be gone. - try: - print(number_land_grid_cells) - except: - print("There is no valye for number of land grid cells") - - print(oasis) - print(coupling_out_fields) - print(coupling_in_vars) - - #return(t159,t255, t511, coupling_intervals, run_length_sec, oasis_component,oasis_output_unit, \ - # oasis_nx,coupling_out_fields, coupling_out_vars, coupling_in_fields, coupling_in_vars) - - -def build_toy_model(): - print("The build script will be here") - - - -if __name__ == '__main__': -# Open the file and load the file - #with open('example_input_runoff.yaml') as f: - with open('example_input_nemo.yaml') as f: - #with open('example_input.yaml') as f: - read_in_data = yaml.load(f, Loader=SafeLoader) - model_name = read_in_data.get("model_name") - print(model_name) - f.close() - - # TODO should be initialized as function - #t159,t255, t511, coupling_intervals, run_length_sec, oasis_component,oasis_output_unit,oasis_nx,coupling_out_fields, coupling_out_vars, coupling_in_fields, coupling_in_vars = {} - - read_yaml(read_in_data) - build_toy_model()#t159,t255, t511, coupling_intervals, run_length_sec, oasis_component,oasis_output_unit, oasis_nx,coupling_out_fields, coupling_out_vars, coupling_in_fields, coupling_in_vars) - - exit() - - diff --git a/sources/ece3-toy-model/runoff_toy_model_example.yaml b/sources/ece3-toy-model/runoff_toy_model_example.yaml new file mode 100644 index 0000000..8991b9d --- /dev/null +++ b/sources/ece3-toy-model/runoff_toy_model_example.yaml @@ -0,0 +1,23 @@ +# Copyright 2023 - Barcelona Supercomputing Center +# Author: Amirpasha Mozaffari +# TBD +--- + +model: + model_name: RUNOFF_TOY + +simulation: + coupling_interval : 2700 + run_length_sec : 86400 + nx : 512 * 256 + + +coupling: + out_vars : + - R_Runoff_oce + - R_Calving_oce + + in_vars : + - R_Runoff_atm + - R_Calving_atm +... \ No newline at end of file diff --git a/sources/ece3-toy-model/toy_model.py b/sources/ece3-toy-model/toy_model.py new file mode 100644 index 0000000..3aae206 --- /dev/null +++ b/sources/ece3-toy-model/toy_model.py @@ -0,0 +1,176 @@ +import yaml +from yaml.loader import SafeLoader + +import f90nml +import pyoasis +from pyoasis import OASIS # pylint: disable=no-name-in-module +import numpy as np +import logging + + +# TODO a logger module to be called in in functions and classes + + +# to be placed in IFS_toy script +def read_yaml(read_in_data): + print("YAML file is read ... ") + # logging.info("YAML file is read ... ") + + # Read in Model information + model = read_in_data.get("model") + model_name = model.get("model_name") + + # logging.info("Model information are:" + str(model)) + + # TODO will pass as variable to the script + # Read in Simulation information + simulation = read_in_data.get("simulation") + simulation_coupling_interval = simulation.get("coupling_interval") + simulation_run_length_sec = simulation.get("run_length_sec") + simulation_nx = simulation.get("nx") + + # logging.info("Simulation information are:" + str(simulation)) + + # Read in Coupling infomration + coupling = read_in_data.get("coupling") + coupling_out_vars = coupling.get("out_vars") + coupling_in_vars = coupling.get("in_vars") + + + + + +if __name__ == '__main__': + + + +# Open the file and load the file + with open('ifs_toy_model_example.yaml') as f: + #with open('nemo_toy_model_example.yaml') as f: + #with open('runoff_toy_model_example.yaml') as f: + read_in_data = yaml.load(f, Loader=SafeLoader) + f.close() + +### Read in file + #read_yaml(read_in_data) + model = read_in_data.get("model") + model_name = model.get("model_name") + + # logging.info("Model information are:" + str(model)) + + # TODO will pass as variable to the script + # Read in Simulation information + simulation = read_in_data.get("simulation") + simulation_coupling_interval = simulation.get("coupling_interval") + simulation_run_length_sec = simulation.get("run_length_sec") + simulation_nx = simulation.get("nx") + + # logging.info("Simulation information are:" + str(simulation)) + + # Read in Coupling infomration + coupling = read_in_data.get("coupling") + coupling_out_vars = coupling.get("out_vars") + coupling_in_vars = coupling.get("in_vars") + +### Pass the values to original code + + # Init OASIS + comp = pyoasis.Component(model_name) + local_comm = comp.localcomm + # Get rank in local communicator + mype = comp.localcomm.rank + npes = comp.localcomm.size + + + # BUG : shouldnt it be the npes and not mpye (?) + mype_value = str(100+mype) + out_model = '{model_name}.out_{mype_value}'.format(model_name = model_name, mype_value = mype_value) + + + + logging.basicConfig(filename=out_model, format='%(message)s', level=logging.DEBUG) + logging.debug('-----------------------------------------------------------') + logging.info('I am {model_name} process with rank : {mype}'.format(model_name = model_name, + mype = mype)) + #logging.debug('I am IFS-toy process with rank : {}'.format(mype)) + logging.debug('in my local communicator gathering {} processes'.format(npes)) + logging.debug('----------------------------------------------------------') + + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # PARTITION DEFINITION + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + # Definition of the local partition + partition = pyoasis.SerialPartition(simulation_nx) + + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # DECLARATION OF THE COUPLING FIELDS + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + out_coupling_fields={} + + for v in coupling_out_vars: + out_coupling_fields[v] = pyoasis.Var(v, partition, OASIS.OUT) + logging.warning('var_id {}, added as OASIS_OUT var'.format(v)) + + + in_coupling_fields={} + + for v in coupling_in_vars: + in_coupling_fields[v] = pyoasis.Var(v, partition, OASIS.IN) + logging.info('var_id {}, added as OASIS_IN var'.format(v)) + + + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # TERMINATION OF DEFINITION PHASE + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + logging.debug('End of initialisation phase') + + comp.enddef() + + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # TIME STEP LOOP + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + logging.debug('Timestep, field min, mean and max value') + + field_data = pyoasis.asarray(np.full(simulation_nx, -1.0)) + + for itap_sec in range(0, simulation_run_length_sec, simulation_coupling_interval): + + logging.debug('ITAP_SEC: {} receiving fields'.format(itap_sec)) + logging.debug(str(in_coupling_fields.keys())) + for id, field in in_coupling_fields.items(): + field.get(itap_sec, field_data) + logging.debug('{} -> {:.3e} {:.3e} {:.3e}'.format( id, np.min(field_data), np.mean(field_data), np.max(field_data))) + logging.debug('--------------------------------------\n') + + logging.debug('ITAP_SEC: {} sending fields'.format(itap_sec)) + logging.debug(str(out_coupling_fields.keys())) + for id, field in out_coupling_fields.items(): + sigma=1 + mu=1 + # send dummy data (100 for runoff, random for other variables) + #TODO send dummy data read from oasis restart file + if id == "A_Runoff": + #field_data[:]=1.4658e-06 + field_data[:]=100 + else: + field_data[:]=sigma * np.random.randn(simulation_nx) + mu + field.put(itap_sec, field_data) + logging.debug('{} put -> {:.3e} {:.3e} {:.3e}'.format( id, np.min(field_data), np.mean(field_data), np.max(field_data))) + logging.debug('--------------------------------------\n') + + + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # TERMINATION + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + logging.debug('End of the program') + + # print(coupling_in_vars) + # print(in_coupling_vars) + # print(coupling_in_vars == in_coupling_vars) + print("NOTE for APM: It is finished!") + del comp + + + diff --git a/sources/ece3-toy-model/yaml_mn4.cmd b/sources/ece3-toy-model/yaml_mn4.cmd index a0c90d3..44b8752 100644 --- a/sources/ece3-toy-model/yaml_mn4.cmd +++ b/sources/ece3-toy-model/yaml_mn4.cmd @@ -22,22 +22,22 @@ export PYTHONPATH=${PYOASIS_ROOT}/python:${PYTHONPATH} export MPIRUN4PY="mpirun" ## prepare rundir -#rundir=run/ +rundir=run/ srcdir=`pwd` -#datadir=/gpfs/scratch/bsc32/bsc32051/git/python-amip-reader/tests/data/ece3-toy-model +datadir=/gpfs/scratch/bsc32/bsc32051/git/python-amip-reader/tests/data/ece3-toy-model -#rm -rf $rundir -#mkdir -p $rundir +rm -rf $rundir +mkdir -p $rundir -#for f in masks.nc grids.nc areas.nc rstas.nc rstos.nc; do -# cp -f $datadir/$f $rundir -#done -#cp -f $datadir/rmp* $rundir -#cp -f $srcdir/*.py $rundir -#cp -f $srcdir/namcouple $rundir +for f in masks.nc grids.nc areas.nc rstas.nc rstos.nc; do + cp -f $datadir/$f $rundir +done +cp -f $datadir/rmp* $rundir +cp -f $srcdir/*.py $rundir +cp -f $srcdir/namcouple $rundir #cd $rundir # run IFS+NEMO+runoff toy model # mpirun -np 1 python3 $srcdir/IFS_toy.py : -np 1 python3 $srcdir/NEMO_toy.py : -np 1 python3 $srcdir/RUNOFF_toy.py -mpirun -np 1 python3 $srcdir/read_in_yaml.py \ No newline at end of file +mpirun -np 1 python3 $srcdir/toy_model.py \ No newline at end of file -- GitLab From cb34252fe0827dcdbb54c1b29350ea1dd63cdd65 Mon Sep 17 00:00:00 2001 From: Amirpasha Mozaffari Date: Thu, 29 Jun 2023 17:05:35 +0200 Subject: [PATCH 4/5] toy model supports YAML file input for ifs, nemo, and runoff via argument parsing, while also addressing the formatting issue in the YAML input file. --- .../ece3-toy-model/ifs_toy_model_example.yaml | 32 ++------ sources/ece3-toy-model/launch_yaml_mn4.cmd | 2 +- .../nemo_toy_model_example.yaml | 25 ++---- .../runoff_toy_model_example.yaml | 12 ++- sources/ece3-toy-model/toy_model.py | 79 ++++++------------- 5 files changed, 45 insertions(+), 105 deletions(-) diff --git a/sources/ece3-toy-model/ifs_toy_model_example.yaml b/sources/ece3-toy-model/ifs_toy_model_example.yaml index a90fb2f..0c4c637 100644 --- a/sources/ece3-toy-model/ifs_toy_model_example.yaml +++ b/sources/ece3-toy-model/ifs_toy_model_example.yaml @@ -5,6 +5,7 @@ model: model_name: IFS_TOY + model_restart_file_path : /path/ simulation: coupling_interval : 2700 @@ -15,30 +16,9 @@ simulation: # L256_NX = 348528 # number of LAND grid cells at T511 resolution nx : 88838 - coupling: - out_vars : - - A_TauX_oce - - A_TauY_oce - - A_TauX_ice - - A_TauY_ice - - A_Qns_mix - - A_Qs_mix - - A_Evap_total - - A_Precip_liquid - - A_Precip_solid - - A_Qs_ice - - A_Qns_ice - - A_dQns_dT - - A_Evap_ice - - A_Runoff - - A_Calving - - in_vars : - - A_SST - - A_Ice_temp - - A_Ice_albedo - - A_Ice_frac - - A_Ice_thickness - - A_Snow_thickness -... + out_vars : [A_TauX_oce, A_TauY_oce, A_TauX_ice, A_TauY_ice, A_Qns_mix, A_Qs_mix, A_Evap_total, A_Precip_liquid, A_Precip_solid, A_Qs_ice, A_Qns_ice, A_dQns_dT, A_Evap_ice, A_Runoff, A_Calving] + + in_vars : [A_SST, A_Ice_temp, A_Ice_albedo, A_Ice_frac, A_Ice_thickness, A_Snow_thickness] + +... \ No newline at end of file diff --git a/sources/ece3-toy-model/launch_yaml_mn4.cmd b/sources/ece3-toy-model/launch_yaml_mn4.cmd index cf93908..1aefdba 100644 --- a/sources/ece3-toy-model/launch_yaml_mn4.cmd +++ b/sources/ece3-toy-model/launch_yaml_mn4.cmd @@ -44,4 +44,4 @@ cp -f $apmdir/*.yaml $rundir cd $rundir # run IFS+NEMO+runoff toy model -mpirun -np 1 python3 $srcdir/toy_model.py : -np 1 python3 $srcdir/NEMO_toy.py : -np 1 python3 $srcdir/RUNOFF_toy.py +mpirun -np 1 python3 $srcdir/toy_model.py --yaml_file_path /gpfs/scratch/bsc32/bsc32013/ec_earth/amip/python-amip-reader/sources/ece3-toy-model/ifs_toy_model_example.yaml : -np 1 python3 $srcdir/toy_model.py --yaml_file_path /gpfs/scratch/bsc32/bsc32013/ec_earth/amip/python-amip-reader/sources/ece3-toy-model/nemo_toy_model_example.yaml : -np 1 python3 $srcdir/toy_model.py --yaml_file_path /gpfs/scratch/bsc32/bsc32013/ec_earth/amip/python-amip-reader/sources/ece3-toy-model/runoff_toy_model_example.yaml diff --git a/sources/ece3-toy-model/nemo_toy_model_example.yaml b/sources/ece3-toy-model/nemo_toy_model_example.yaml index 4229f66..062ad91 100644 --- a/sources/ece3-toy-model/nemo_toy_model_example.yaml +++ b/sources/ece3-toy-model/nemo_toy_model_example.yaml @@ -5,27 +5,16 @@ model: model_name: NEMO_TOY + model_restart_file_path : /path/ simulation: coupling_interval : 2700 run_length_sec : 86400 - nx : 362 * 292 - + nx : 105704 coupling: - out_vars : - - O_SSTSST - - O_TepIce - - O_AlbIce - - OIceFrc - - OIceTck - - OSnwTck - - in_vars : - - O_OTaux1 - - O_OTauy1 - - O_ITaux1 - - O_ITauy1 - - O_OTaux2 - - O_OTauy2 -... + out_vars : [O_SSTSST, O_TepIce, O_AlbIce, OIceFrc, OIceTck, OSnwTck] + + in_vars : [O_OTaux1, O_OTauy1, O_ITaux1, O_ITauy1, O_OTaux2, O_OTauy2, O_ITaux2, O_ITauy2, O_QnsMix, O_QsrMix, OTotEvap, OTotRain, OTotSnow, O_QsrIce, O_QnsIce, O_dQnsdT, OIceEvap, O_Runoff, OCalving] + +... \ No newline at end of file diff --git a/sources/ece3-toy-model/runoff_toy_model_example.yaml b/sources/ece3-toy-model/runoff_toy_model_example.yaml index 8991b9d..a62a7f0 100644 --- a/sources/ece3-toy-model/runoff_toy_model_example.yaml +++ b/sources/ece3-toy-model/runoff_toy_model_example.yaml @@ -5,19 +5,17 @@ model: model_name: RUNOFF_TOY + model_restart_file_path : /path/ simulation: coupling_interval : 2700 run_length_sec : 86400 - nx : 512 * 256 + nx : 131072 coupling: - out_vars : - - R_Runoff_oce - - R_Calving_oce + out_vars : [R_Runoff_oce, R_Calving_oce] - in_vars : - - R_Runoff_atm - - R_Calving_atm + in_vars : [R_Runoff_atm, R_Calving_atm] + ... \ No newline at end of file diff --git a/sources/ece3-toy-model/toy_model.py b/sources/ece3-toy-model/toy_model.py index 3aae206..c763676 100644 --- a/sources/ece3-toy-model/toy_model.py +++ b/sources/ece3-toy-model/toy_model.py @@ -1,53 +1,35 @@ +#!/usr/bin/env python3 +# Copyright 2023 - Barcelona Supercomputing Center +# Author: Rodrigo Martín Posada (2021), updated by : Amirpasha Mozaffari (2023) +# TBD + import yaml from yaml.loader import SafeLoader +import logging +import argparse +import os import f90nml import pyoasis from pyoasis import OASIS # pylint: disable=no-name-in-module import numpy as np -import logging - - -# TODO a logger module to be called in in functions and classes - - -# to be placed in IFS_toy script -def read_yaml(read_in_data): - print("YAML file is read ... ") - # logging.info("YAML file is read ... ") - - # Read in Model information - model = read_in_data.get("model") - model_name = model.get("model_name") - - # logging.info("Model information are:" + str(model)) - - # TODO will pass as variable to the script - # Read in Simulation information - simulation = read_in_data.get("simulation") - simulation_coupling_interval = simulation.get("coupling_interval") - simulation_run_length_sec = simulation.get("run_length_sec") - simulation_nx = simulation.get("nx") - - # logging.info("Simulation information are:" + str(simulation)) - - # Read in Coupling infomration - coupling = read_in_data.get("coupling") - coupling_out_vars = coupling.get("out_vars") - coupling_in_vars = coupling.get("in_vars") - - - - if __name__ == '__main__': +### Read in passed on argument to main + current_path = os.getcwd() + parser=argparse.ArgumentParser() + parser.add_argument("--yaml_file_path",type=str,default="/path_TBD/") + args = parser.parse_args() + yamel_file_path = args.yaml_file_path + if os.path.isfile(yamel_file_path) == False: + print("YAML file does not exist. Aborted") + raise NameError("YAML file does not exist.") + # Open the file and load the file - with open('ifs_toy_model_example.yaml') as f: - #with open('nemo_toy_model_example.yaml') as f: - #with open('runoff_toy_model_example.yaml') as f: + with open(yamel_file_path) as f: read_in_data = yaml.load(f, Loader=SafeLoader) f.close() @@ -55,18 +37,15 @@ if __name__ == '__main__': #read_yaml(read_in_data) model = read_in_data.get("model") model_name = model.get("model_name") - - # logging.info("Model information are:" + str(model)) - - # TODO will pass as variable to the script + model_restart_file_path = model.get("model_restart_file_path") + + # TODO will pass as variable to the script : the arg function is already included. # Read in Simulation information simulation = read_in_data.get("simulation") simulation_coupling_interval = simulation.get("coupling_interval") simulation_run_length_sec = simulation.get("run_length_sec") simulation_nx = simulation.get("nx") - # logging.info("Simulation information are:" + str(simulation)) - # Read in Coupling infomration coupling = read_in_data.get("coupling") coupling_out_vars = coupling.get("out_vars") @@ -79,15 +58,12 @@ if __name__ == '__main__': local_comm = comp.localcomm # Get rank in local communicator mype = comp.localcomm.rank - npes = comp.localcomm.size - + npes = comp.localcomm.size # BUG : shouldnt it be the npes and not mpye (?) mype_value = str(100+mype) out_model = '{model_name}.out_{mype_value}'.format(model_name = model_name, mype_value = mype_value) - - logging.basicConfig(filename=out_model, format='%(message)s', level=logging.DEBUG) logging.debug('-----------------------------------------------------------') logging.info('I am {model_name} process with rank : {mype}'.format(model_name = model_name, @@ -152,7 +128,7 @@ if __name__ == '__main__': # send dummy data (100 for runoff, random for other variables) #TODO send dummy data read from oasis restart file if id == "A_Runoff": - #field_data[:]=1.4658e-06 + field_data[:]=1.4658e-06 field_data[:]=100 else: field_data[:]=sigma * np.random.randn(simulation_nx) + mu @@ -160,16 +136,13 @@ if __name__ == '__main__': logging.debug('{} put -> {:.3e} {:.3e} {:.3e}'.format( id, np.min(field_data), np.mean(field_data), np.max(field_data))) logging.debug('--------------------------------------\n') - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # TERMINATION # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ logging.debug('End of the program') - # print(coupling_in_vars) - # print(in_coupling_vars) - # print(coupling_in_vars == in_coupling_vars) - print("NOTE for APM: It is finished!") + print('Model {} is finished successfully.'.format(model_name)) + del comp -- GitLab From 28b8430f82e1cec07e6c00848ed9c825fb0a8845 Mon Sep 17 00:00:00 2001 From: Amirpasha Mozaffari Date: Fri, 30 Jun 2023 10:06:29 +0200 Subject: [PATCH 5/5] clean up of the repo, removing of deprecated files --- sources/ece3-toy-model/IFS_toy.py | 106 ------------------ sources/ece3-toy-model/NEMO_toy.py | 97 ---------------- sources/ece3-toy-model/RUNOFF_toy.py | 94 ---------------- ..._model_example.yaml => ifs_toy_model.yaml} | 2 +- sources/ece3-toy-model/launch-mn4.cmd | 42 ------- sources/ece3-toy-model/launch_yaml_mn4.cmd | 9 +- ...model_example.yaml => nemo_toy_model.yaml} | 3 +- ...del_example.yaml => runoff_toy_model.yaml} | 5 +- sources/ece3-toy-model/toy_model.py | 13 +-- sources/ece3-toy-model/yaml_mn4.cmd | 43 ------- 10 files changed, 12 insertions(+), 402 deletions(-) delete mode 100755 sources/ece3-toy-model/IFS_toy.py delete mode 100644 sources/ece3-toy-model/NEMO_toy.py delete mode 100644 sources/ece3-toy-model/RUNOFF_toy.py rename sources/ece3-toy-model/{ifs_toy_model_example.yaml => ifs_toy_model.yaml} (95%) delete mode 100644 sources/ece3-toy-model/launch-mn4.cmd rename sources/ece3-toy-model/{nemo_toy_model_example.yaml => nemo_toy_model.yaml} (92%) rename sources/ece3-toy-model/{runoff_toy_model_example.yaml => runoff_toy_model.yaml} (88%) delete mode 100644 sources/ece3-toy-model/yaml_mn4.cmd diff --git a/sources/ece3-toy-model/IFS_toy.py b/sources/ece3-toy-model/IFS_toy.py deleted file mode 100755 index 68c2384..0000000 --- a/sources/ece3-toy-model/IFS_toy.py +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2021 - Barcelona Supercomputing Center -# Author: Rodrigo Martín Posada -# MIT License - -import f90nml -import pyoasis -from pyoasis import OASIS # pylint: disable=no-name-in-module -import numpy as np -import logging - -L080_NX = 35718 # number of LAND grid cells at T159 resolution -L128_NX = 88838 # number of LAND grid cells at T255 resolution -L256_NX = 348528 # number of LAND grid cells at T511 resolution - - -if __name__ == '__main__': - - COUPLING_INTERVAL = 2700 - RUN_LENGTH_SEC = 86400 - - # Init OASIS - comp = pyoasis.Component("IFS_TOY") - local_comm = comp.localcomm - # Get rank in local communicator - mype = comp.localcomm.rank - npes = comp.localcomm.size - - # Unit for output messages - out_ifs = 'IFS_toy.out_'+str(100+mype) - logging.basicConfig(filename=out_ifs, format='%(message)s', level=logging.DEBUG) - logging.debug('-----------------------------------------------------------') - logging.debug('I am IFS-toy process with rank : {}'.format(mype)) - logging.debug('in my local communicator gathering {} processes'.format(npes)) - logging.debug('----------------------------------------------------------') - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # PARTITION DEFINITION - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - # Definition of the local partition - nx = L128_NX - partition = pyoasis.SerialPartition(nx) - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # DECLARATION OF THE COUPLING FIELDS - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - out_coupling_fields={} - out_coupling_vars=["A_TauX_oce","A_TauY_oce","A_TauX_ice","A_TauY_ice","A_Qns_mix","A_Qs_mix","A_Evap_total","A_Precip_liquid","A_Precip_solid","A_Qs_ice","A_Qns_ice","A_dQns_dT","A_Evap_ice","A_Runoff","A_Calving"] - for v in out_coupling_vars: - out_coupling_fields[v] = pyoasis.Var(v, partition, OASIS.OUT) - logging.debug('var_id {}, added as OASIS_OUT var'.format(v)) - - in_coupling_fields={} - in_coupling_vars=["A_SST","A_Ice_temp","A_Ice_albedo","A_Ice_frac","A_Ice_thickness","A_Snow_thickness"] - for v in in_coupling_vars: - in_coupling_fields[v] = pyoasis.Var(v, partition, OASIS.IN) - logging.debug('var_id {}, added as OASIS_IN var'.format(v)) - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # TERMINATION OF DEFINITION PHASE - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - logging.debug('End of initialisation phase') - - comp.enddef() - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # TIME STEP LOOP - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - logging.debug('Timestep, field min, mean and max value') - - field_data = pyoasis.asarray(np.full(nx, -1.0)) - - for itap_sec in range(0, RUN_LENGTH_SEC, COUPLING_INTERVAL): - - logging.debug('ITAP_SEC: {} receiving fields'.format(itap_sec)) - logging.debug(str(in_coupling_fields.keys())) - for id, field in in_coupling_fields.items(): - field.get(itap_sec, field_data) - logging.debug('{} -> {:.3e} {:.3e} {:.3e}'.format( id, np.min(field_data), np.mean(field_data), np.max(field_data))) - logging.debug('--------------------------------------\n') - - logging.debug('ITAP_SEC: {} sending fields'.format(itap_sec)) - logging.debug(str(out_coupling_fields.keys())) - for id, field in out_coupling_fields.items(): - sigma=1 - mu=1 - # send dummy data (100 for runoff, random for other variables) - #TODO send dummy data read from oasis restart file - if id == "A_Runoff": - #field_data[:]=1.4658e-06 - field_data[:]=100 - else: - field_data[:]=sigma * np.random.randn(nx) + mu - field.put(itap_sec, field_data) - logging.debug('{} put -> {:.3e} {:.3e} {:.3e}'.format( id, np.min(field_data), np.mean(field_data), np.max(field_data))) - logging.debug('--------------------------------------\n') - - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # TERMINATION - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - logging.debug('End of the program') - - del comp diff --git a/sources/ece3-toy-model/NEMO_toy.py b/sources/ece3-toy-model/NEMO_toy.py deleted file mode 100644 index 5ef3b79..0000000 --- a/sources/ece3-toy-model/NEMO_toy.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2021 - Barcelona Supercomputing Center -# Author: Rodrigo Martín Posada -# MIT License - -import f90nml -import pyoasis -from pyoasis import OASIS # pylint: disable=no-name-in-module -import numpy as np -import logging - -if __name__ == '__main__': - - COUPLING_INTERVAL = 2700 - RUN_LENGTH_SEC = 86400 - - # Init OASIS - comp = pyoasis.Component("NEMO_TOY") - local_comm = comp.localcomm - # Get rank in local communicator - mype = comp.localcomm.rank - npes = comp.localcomm.size - - # Unit for output messages - out_nemo = 'NEMO_toy.out_'+str(100+mype) - logging.basicConfig(filename=out_nemo, format='%(message)s', level=logging.DEBUG) - logging.debug('-----------------------------------------------------------') - logging.debug('I am NEMO-toy process with rank : {}'.format(mype)) - logging.debug('in my local communicator gathering {} processes'.format(npes)) - logging.debug('----------------------------------------------------------') - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # PARTITION DEFINITION - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - # Definition of the local partition - nx = 362 * 292 - partition = pyoasis.SerialPartition(nx) - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # DECLARATION OF THE COUPLING FIELDS - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - out_coupling_fields={} - out_coupling_vars=["O_SSTSST","O_TepIce","O_AlbIce","OIceFrc","OIceTck","OSnwTck"] - for v in out_coupling_vars: - out_coupling_fields[v] = pyoasis.Var(v, partition, OASIS.OUT) - logging.debug('var_id {}, added as OASIS_OUT var'.format(v)) - - in_coupling_fields={} - in_coupling_vars=["O_OTaux1","O_OTauy1","O_ITaux1","O_ITauy1","O_OTaux2","O_OTauy2","O_ITaux2","O_ITauy2","O_QnsMix","O_QsrMix","OTotEvap","OTotRain","OTotSnow","O_QsrIce","O_QnsIce","O_dQnsdT","OIceEvap","O_Runoff","OCalving"] - for v in in_coupling_vars: - in_coupling_fields[v] = pyoasis.Var(v, partition, OASIS.IN) - logging.debug('var_id {}, added as OASIS_IN var'.format(v)) - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # TERMINATION OF DEFINITION PHASE - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - logging.debug('End of initialisation phase') - - comp.enddef() - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # TIME STEP LOOP - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - logging.debug('Timestep, field min, mean and max value') - - field_data = pyoasis.asarray(np.full(nx, -1.0)) - - for itap_sec in range(0, RUN_LENGTH_SEC, COUPLING_INTERVAL): - - logging.debug('ITAP_SEC: {} receiving fields'.format(itap_sec)) - logging.debug(str(in_coupling_fields.keys())) - for v, field in in_coupling_fields.items(): - field.get(itap_sec, field_data) - logging.debug('{} -> {:.3e} {:.3e} {:.3e}'.format( v, np.min(field_data), np.mean(field_data), np.max(field_data))) - logging.debug('--------------------------------------\n') - - logging.debug('ITAP_SEC: {} sending fields'.format(itap_sec)) - logging.debug(str(out_coupling_fields.keys())) - for v, field in out_coupling_fields.items(): - sigma=1 - mu=1 - field_data[:]=sigma * np.random.randn(nx) + mu - field.put(itap_sec, field_data) - logging.debug('{} put -> {:.3e} {:.3e} {:.3e}'.format( v, np.min(field_data), np.mean(field_data), np.max(field_data))) - logging.debug('--------------------------------------\n') - - - - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # TERMINATION - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - logging.debug('End of the program') - - del comp diff --git a/sources/ece3-toy-model/RUNOFF_toy.py b/sources/ece3-toy-model/RUNOFF_toy.py deleted file mode 100644 index f6d78d5..0000000 --- a/sources/ece3-toy-model/RUNOFF_toy.py +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2021 - Barcelona Supercomputing Center -# Author: Rodrigo Martín Posada -# MIT License - -import f90nml -import pyoasis -from pyoasis import OASIS # pylint: disable=no-name-in-module -import numpy as np -import logging - -if __name__ == '__main__': - - COUPLING_INTERVAL = 2700 - RUN_LENGTH_SEC = 86400 - - # Init OASIS - comp = pyoasis.Component("RUNOFF_TOY") - local_comm = comp.localcomm - # Get rank in local communicator - mype = comp.localcomm.rank - npes = comp.localcomm.size - - # Unit for output messages - out_runoff = 'RUNOFF_toy.out_'+str(100+mype) - logging.basicConfig(filename=out_runoff, format='%(message)s', level=logging.DEBUG) - logging.debug('-----------------------------------------------------------') - logging.debug('I am RUNOFF-toy process with rank : {}'.format(mype)) - logging.debug('in my local communicator gathering {} processes'.format(npes)) - logging.debug('----------------------------------------------------------') - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # PARTITION DEFINITION - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - # Definition of the local partition - nx = 512*256 - partition = pyoasis.SerialPartition(nx) - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # DECLARATION OF THE COUPLING FIELDS - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - out_coupling_fields={} - out_coupling_vars=["R_Runoff_oce","R_Calving_oce"] - for v in out_coupling_vars: - out_coupling_fields[v] = pyoasis.Var(v, partition, OASIS.OUT) - logging.debug('var_id {}, added as OASIS_OUT var'.format(v)) - - in_coupling_fields={} - in_coupling_vars=["R_Runoff_atm", "R_Calving_atm"] - for v in in_coupling_vars: - in_coupling_fields[v] = pyoasis.Var(v, partition, OASIS.IN) - logging.debug('var_id {}, added as OASIS_IN var'.format(v)) - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # TERMINATION OF DEFINITION PHASE - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - logging.debug('End of initialisation phase') - - comp.enddef() - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # TIME STEP LOOP - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - logging.debug('Timestep, field min, mean and max value') - - field_data = pyoasis.asarray(np.full(nx, -1.0)) - - for itap_sec in range(0, RUN_LENGTH_SEC, COUPLING_INTERVAL): - - logging.debug('ITAP_SEC: {} receiving fields'.format(itap_sec)) - logging.debug(str(in_coupling_fields.keys())) - for id, field in in_coupling_fields.items(): - field.get(itap_sec, field_data) - logging.debug('{} -> {:.3e} {:.3e} {:.3e}'.format( id, np.min(field_data), np.mean(field_data), np.max(field_data))) - logging.debug('--------------------------------------\n') - - logging.debug('ITAP_SEC: {} sending fields'.format(itap_sec)) - logging.debug(str(out_coupling_fields.keys())) - for id, field in out_coupling_fields.items(): - sigma=1 - mu=1 - field_data[:]=sigma * np.random.randn(nx) + mu - field.put(itap_sec, field_data) - logging.debug('{} put -> {:.3e} {:.3e} {:.3e}'.format( id, np.min(field_data), np.mean(field_data), np.max(field_data))) - logging.debug('--------------------------------------\n') - - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - # TERMINATION - # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - logging.debug('End of the program') - - del comp diff --git a/sources/ece3-toy-model/ifs_toy_model_example.yaml b/sources/ece3-toy-model/ifs_toy_model.yaml similarity index 95% rename from sources/ece3-toy-model/ifs_toy_model_example.yaml rename to sources/ece3-toy-model/ifs_toy_model.yaml index 0c4c637..fcf56ff 100644 --- a/sources/ece3-toy-model/ifs_toy_model_example.yaml +++ b/sources/ece3-toy-model/ifs_toy_model.yaml @@ -5,7 +5,6 @@ model: model_name: IFS_TOY - model_restart_file_path : /path/ simulation: coupling_interval : 2700 @@ -20,5 +19,6 @@ coupling: out_vars : [A_TauX_oce, A_TauY_oce, A_TauX_ice, A_TauY_ice, A_Qns_mix, A_Qs_mix, A_Evap_total, A_Precip_liquid, A_Precip_solid, A_Qs_ice, A_Qns_ice, A_dQns_dT, A_Evap_ice, A_Runoff, A_Calving] in_vars : [A_SST, A_Ice_temp, A_Ice_albedo, A_Ice_frac, A_Ice_thickness, A_Snow_thickness] + restart_file : /path/ ... \ No newline at end of file diff --git a/sources/ece3-toy-model/launch-mn4.cmd b/sources/ece3-toy-model/launch-mn4.cmd deleted file mode 100644 index f45333a..0000000 --- a/sources/ece3-toy-model/launch-mn4.cmd +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -# slurm specific options for Marenostrum4 -#SBATCH --qos=debug -#SBATCH -N 1 -#SBATCH -n 3 -#SBATCH -c 1 -#SBATCH -t 1:00:00 -#SBATCH --exclusive - -#load python and netcdf modules -export PYTHONPATH="" -module load python/3.6.1 -module load netcdf/4.2 - -set -xuve - -# setup pyOasis environment -export PYOASIS_ROOT=/gpfs/scratch/bsc32/bsc32051/git/python-amip-reader/sources/oasis3-mct/generated -export LD_LIBRARY_PATH=${PYOASIS_ROOT}/lib:${LD_LIBRARY_PATH} -export PYTHONPATH=${PYOASIS_ROOT}/python:${PYTHONPATH} -export MPIRUN4PY="mpirun" - -# prepare rundir -rundir=run/ -srcdir=`pwd` -datadir=/gpfs/scratch/bsc32/bsc32051/git/python-amip-reader/tests/data/ece3-toy-model - -rm -rf $rundir -mkdir -p $rundir - -for f in masks.nc grids.nc areas.nc rstas.nc rstos.nc; do - cp -f $datadir/$f $rundir -done -cp -f $datadir/rmp* $rundir -cp -f $srcdir/*.py $rundir -cp -f $srcdir/namcouple $rundir - -cd $rundir - -# run IFS+NEMO+runoff toy model -mpirun -np 1 python3 $srcdir/IFS_toy.py : -np 1 python3 $srcdir/NEMO_toy.py : -np 1 python3 $srcdir/RUNOFF_toy.py diff --git a/sources/ece3-toy-model/launch_yaml_mn4.cmd b/sources/ece3-toy-model/launch_yaml_mn4.cmd index 1aefdba..764fe7e 100644 --- a/sources/ece3-toy-model/launch_yaml_mn4.cmd +++ b/sources/ece3-toy-model/launch_yaml_mn4.cmd @@ -23,10 +23,8 @@ export MPIRUN4PY="mpirun" # prepare rundir rundir=run/ -#srcdir=`pwd` -srcdir=/gpfs/scratch/bsc32/bsc32013/ec_earth/amip/python-amip-reader/sources/ece3-toy-model +srcdir=`pwd` datadir=/gpfs/scratch/bsc32/bsc32051/git/python-amip-reader/tests/data/ece3-toy-model -apmdir=/gpfs/scratch/bsc32/bsc32013/ec_earth/amip/python-amip-reader/sources/ece3-toy-model rm -rf $rundir mkdir -p $rundir @@ -37,11 +35,10 @@ done cp -f $datadir/rmp* $rundir cp -f $srcdir/*.py $rundir cp -f $srcdir/namcouple $rundir -cp -f $apmdir/*.py $rundir -cp -f $apmdir/*.yaml $rundir +cp -f $srcdir/*.yaml $rundir cd $rundir # run IFS+NEMO+runoff toy model -mpirun -np 1 python3 $srcdir/toy_model.py --yaml_file_path /gpfs/scratch/bsc32/bsc32013/ec_earth/amip/python-amip-reader/sources/ece3-toy-model/ifs_toy_model_example.yaml : -np 1 python3 $srcdir/toy_model.py --yaml_file_path /gpfs/scratch/bsc32/bsc32013/ec_earth/amip/python-amip-reader/sources/ece3-toy-model/nemo_toy_model_example.yaml : -np 1 python3 $srcdir/toy_model.py --yaml_file_path /gpfs/scratch/bsc32/bsc32013/ec_earth/amip/python-amip-reader/sources/ece3-toy-model/runoff_toy_model_example.yaml +mpirun -np 1 python3 $srcdir/toy_model.py --yaml_file_path ifs_toy_model.yaml : -np 1 python3 $srcdir/toy_model.py --yaml_file_path nemo_toy_model.yaml : -np 1 python3 $srcdir/toy_model.py --yaml_file_path runoff_toy_model.yaml diff --git a/sources/ece3-toy-model/nemo_toy_model_example.yaml b/sources/ece3-toy-model/nemo_toy_model.yaml similarity index 92% rename from sources/ece3-toy-model/nemo_toy_model_example.yaml rename to sources/ece3-toy-model/nemo_toy_model.yaml index 062ad91..22aa850 100644 --- a/sources/ece3-toy-model/nemo_toy_model_example.yaml +++ b/sources/ece3-toy-model/nemo_toy_model.yaml @@ -5,7 +5,6 @@ model: model_name: NEMO_TOY - model_restart_file_path : /path/ simulation: coupling_interval : 2700 @@ -14,7 +13,7 @@ simulation: coupling: out_vars : [O_SSTSST, O_TepIce, O_AlbIce, OIceFrc, OIceTck, OSnwTck] - in_vars : [O_OTaux1, O_OTauy1, O_ITaux1, O_ITauy1, O_OTaux2, O_OTauy2, O_ITaux2, O_ITauy2, O_QnsMix, O_QsrMix, OTotEvap, OTotRain, OTotSnow, O_QsrIce, O_QnsIce, O_dQnsdT, OIceEvap, O_Runoff, OCalving] + restart_file : /path/ ... \ No newline at end of file diff --git a/sources/ece3-toy-model/runoff_toy_model_example.yaml b/sources/ece3-toy-model/runoff_toy_model.yaml similarity index 88% rename from sources/ece3-toy-model/runoff_toy_model_example.yaml rename to sources/ece3-toy-model/runoff_toy_model.yaml index a62a7f0..308d160 100644 --- a/sources/ece3-toy-model/runoff_toy_model_example.yaml +++ b/sources/ece3-toy-model/runoff_toy_model.yaml @@ -5,17 +5,16 @@ model: model_name: RUNOFF_TOY - model_restart_file_path : /path/ - + simulation: coupling_interval : 2700 run_length_sec : 86400 nx : 131072 - coupling: out_vars : [R_Runoff_oce, R_Calving_oce] in_vars : [R_Runoff_atm, R_Calving_atm] + restart_file : /path/ ... \ No newline at end of file diff --git a/sources/ece3-toy-model/toy_model.py b/sources/ece3-toy-model/toy_model.py index c763676..5eada78 100644 --- a/sources/ece3-toy-model/toy_model.py +++ b/sources/ece3-toy-model/toy_model.py @@ -16,19 +16,17 @@ import numpy as np if __name__ == '__main__': -### Read in passed on argument to main +### Read in YAML file current_path = os.getcwd() parser=argparse.ArgumentParser() - parser.add_argument("--yaml_file_path",type=str,default="/path_TBD/") + parser.add_argument("--yaml_file_path",type=str) args = parser.parse_args() - yamel_file_path = args.yaml_file_path - + yamel_file_path = os.path.join(current_path,args.yaml_file_path) if os.path.isfile(yamel_file_path) == False: print("YAML file does not exist. Aborted") raise NameError("YAML file does not exist.") - -# Open the file and load the file + # Open the file and load the file with open(yamel_file_path) as f: read_in_data = yaml.load(f, Loader=SafeLoader) f.close() @@ -37,9 +35,7 @@ if __name__ == '__main__': #read_yaml(read_in_data) model = read_in_data.get("model") model_name = model.get("model_name") - model_restart_file_path = model.get("model_restart_file_path") - # TODO will pass as variable to the script : the arg function is already included. # Read in Simulation information simulation = read_in_data.get("simulation") simulation_coupling_interval = simulation.get("coupling_interval") @@ -50,6 +46,7 @@ if __name__ == '__main__': coupling = read_in_data.get("coupling") coupling_out_vars = coupling.get("out_vars") coupling_in_vars = coupling.get("in_vars") + restart_file = coupling.get("restart_file") ### Pass the values to original code diff --git a/sources/ece3-toy-model/yaml_mn4.cmd b/sources/ece3-toy-model/yaml_mn4.cmd deleted file mode 100644 index 44b8752..0000000 --- a/sources/ece3-toy-model/yaml_mn4.cmd +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -# slurm specific options for Marenostrum4 -#SBATCH --qos=debug -#SBATCH -N 1 -#SBATCH -n 3 -#SBATCH -c 1 -#SBATCH -t 00:05:00 -#SBATCH --exclusive - -#load python and netcdf modules -export PYTHONPATH="" -module load python/3.6.1 -module load netcdf/4.2 - -set -xuve - -# setup pyOasis environment -export PYOASIS_ROOT=/gpfs/scratch/bsc32/bsc32051/git/python-amip-reader/sources/oasis3-mct/generated -export LD_LIBRARY_PATH=${PYOASIS_ROOT}/lib:${LD_LIBRARY_PATH} -export PYTHONPATH=${PYOASIS_ROOT}/python:${PYTHONPATH} -export MPIRUN4PY="mpirun" - -## prepare rundir -rundir=run/ -srcdir=`pwd` -datadir=/gpfs/scratch/bsc32/bsc32051/git/python-amip-reader/tests/data/ece3-toy-model - -rm -rf $rundir -mkdir -p $rundir - -for f in masks.nc grids.nc areas.nc rstas.nc rstos.nc; do - cp -f $datadir/$f $rundir -done -cp -f $datadir/rmp* $rundir -cp -f $srcdir/*.py $rundir -cp -f $srcdir/namcouple $rundir - -#cd $rundir - -# run IFS+NEMO+runoff toy model -# mpirun -np 1 python3 $srcdir/IFS_toy.py : -np 1 python3 $srcdir/NEMO_toy.py : -np 1 python3 $srcdir/RUNOFF_toy.py -mpirun -np 1 python3 $srcdir/toy_model.py \ No newline at end of file -- GitLab