Skip to content

Commit

Permalink
new file: edge_queScript_gen.py
Browse files Browse the repository at this point in the history
	modified:   edgeconfig.py
	modified:   ../tests/test_edgerun_mpi.py
	new file:   ../tests/test_edgerun_submit.py
  • Loading branch information
mengmengzhang2019 committed Jan 12, 2024
1 parent 7ef00af commit 2a9941b
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 7 deletions.
19 changes: 16 additions & 3 deletions ceasiompy/EdgeRun/edgerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,26 @@ def run_edge_multi(wkdir, input_que_script_path , nb_proc=2):
"""

if not wkdir.exists():
raise OSError(f"The working directory : {wkdir} does not exit!")
raise OSError(f"The working directory : {wkdir} does not exist!")

case_dir_name = (
f"Case{str(case_nb).zfill(2)}_alt{alt}_mach{round(mach, 2)}"
f"_aoa{round(aoa, 1)}_aos{round(aos, 1)}"
)

case_dir_path = Path(wkdir, case_dir_name)
if not case_dir_path.exists():
case_dir_path.mkdir()
output_path = Path(case_dir_path, AINP_CFD_NAME)

case_dir_list = [dir for dir in wkdir.iterdir() if "Case" in dir.name]
if not case_dir_list:
raise OSError(f"No Case directory has been found in the working directory: {wkdir}")


for config_dir in sorted(case_dir_list):
current_dir = Path(case_dir_path, config_dir)

config_cfd = [c for c in config_dir.iterdir() if c.name == AINP_CFD_NAME]

if not config_cfd:
Expand All @@ -78,9 +91,9 @@ def run_edge_multi(wkdir, input_que_script_path , nb_proc=2):
raise ValueError(f"More than one '{AINP_CFD_NAME}' file in this directory!")

# run / submit edge commands
edge_scripts_instance = EdgeScripts(config_dir, input_que_script_path, AINP_CFD_NAME)
edge_scripts_instance = EdgeScripts(current_dir, input_que_script_path, AINP_CFD_NAME)
edge_scripts_instance.submit_preprocessor_script()
#edge_scripts_instance.submit_solver_script(nb_proc)
edge_scripts_instance.submit_solver_script(nb_proc)

# =================================================================================================
# MAIN
Expand Down
63 changes: 63 additions & 0 deletions ceasiompy/EdgeRun/func/edge_queScript_gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
CEASIOMpy: Conceptual Aircraft Design Software
Developed for Airinnova AB, Stockholm, Sweden
Functions to generate queuing script for Edge: queue_preprocessor.script and queue_edgesolver.script
Python version: >=3.8
| Author : Mengmeng Zhang
| Creation: 2024-01-05
"""

# =================================================================================================
# IMPORTS
# =================================================================================================

import os
from pathlib import Path

from pathlib import Path



class EdgeScripts:
def __init__(self, dir_path, jobname, input_que_script_path, edge_input_file):
self.jobname = jobname
self.dir_path = dir_path
self.input_que_script_path = input_que_script_path
self.Edge_dir = '/pdc/software/22.06/other/m-edge/3.2/gnu/bin/'
self.EdgeInputFile = edge_input_file
#self.GridDir = 'grid'
#os.chdir(os.path.join(caseDir, self.GridDir))

def submit_preprocessor_script(self,dir_path):
preprocessor = os.path.join(self.Edge_dir, 'preprocessor')
QueScript = f'queue_preprocessor.script'
Submitcommand = 'sbatch'
os.chdir(dir_path)
with open(self.input_que_script_path, 'r') as template_file, open(QueScript, 'w') as que_script:
for line in template_file:
if '-J jobname' in line:
line = line.replace('-J jobname', f'-J {self.jobname}prepro')
que_script.write(line)
que_script.write(f'{preprocessor} {self.EdgeInputFile} > edge_preprocessor.log 2>&1\n')
print(f'{preprocessor} {self.EdgeInputFile} > edge_preprocessor.log 2>&1\n')
os.system(f'{Submitcommand} {que_script}')

def submit_solver_script(self, dir_path, nb_proc):
run_solver = os.path.join(self.Edge_dir, 'edge_mpi_run')
QueScript = f'queue_edgesolver.script'
Submitcommand = 'sbatch'
os.chdir(dir_path)
with open(self.input_que_script_path, 'r') as template_file, open(QueScript, 'w') as que_script:
for line in template_file:
if '-J jobname' in line:
line = line.replace('-J jobname', f'-J {self.jobname}solver')
que_script.write(line)
que_script.write(f'{run_solver} {self.EdgeInputFile} {nb_proc} > edge_run.log 2>&1\n')
os.system(f'{Submitcommand} {que_script}')



12 changes: 9 additions & 3 deletions ceasiompy/EdgeRun/func/edgeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@
get_value_or_default,
)
from cpacspy.cpacspy import CPACS

from ceasiompy.EdgeRun.func.edgeutils import get_edge_queScript_template
from ceasiompy.EdgeRun.func.edge_queScript_gen import EdgeScripts
# import cpacs

log = get_logger()

MODULE_DIR = Path(__file__).parent


input_que_script_path = get_edge_queScript_template()
# =================================================================================================
# CLASSES
# =================================================================================================
Expand Down Expand Up @@ -271,7 +272,12 @@ def generate_edge_cfd_ainp(cpacs_path, cpacs_out_path, wkdir):
)

# cfg.write_file(config_output_path, overwrite=True)

# create and submit the edge-run scripts
# run / submit edge commands
jobname = case_dir_name
edge_scripts_instance = EdgeScripts(jobname,case_dir_path, input_que_script_path, AINP_CFD_NAME)
edge_scripts_instance.submit_preprocessor_script(case_dir_path)
edge_scripts_instance.submit_solver_script(case_dir_path,NPART)
cpacs.save_cpacs(cpacs_out_path, overwrite=True)

# =================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion ceasiompy/EdgeRun/tests/test_edgerun_mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_run_edge_cfd(self):
os.makedirs(wkdir)

generate_edge_cfd_ainp(cpacs_in_path, cpacs_out_path, wkdir)
run_edge_multi(wkdir,input_que_script_path )
#run_edge_multi(wkdir,input_que_script_path )


# =================================================================================================
Expand Down
50 changes: 50 additions & 0 deletions ceasiompy/EdgeRun/tests/test_edgerun_submit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
CEASIOMpy: Conceptual Aircraft Design Software
Developed by Airinnova AB, Stockholm, Sweden
Test functions of 'ceasiompy/EdgeRun/func/edgeconfig.py'
Python version: >=3.8
| Author : Mengmeng Zhang
| Creation: 2024-01-05
"""

# =================================================================================================
# IMPORTS
# =================================================================================================

import unittest

import sys
from pathlib import Path

# Add the ceasiompy module to the PYTHONPATH
# ceasiompy_path = Path("/home/mengmeng/Documents/CEASIOMpy23/CEASIOMpy/ceasiompy")
# sys.path.append(str(ceasiompy_path))

# Now you can import and use the ceasiompy module
# import ceasiompy
from ceasiompy.EdgeRun.func.edgeconfig import generate_edge_cfd_ainp
import os
from ceasiompy.EdgeRun.edgerun import run_edge_multi
from ceasiompy.utils.commonxpath import EDGE_NB_CPU_XPATH
from ceasiompy.EdgeRun.func.edgeutils import get_edge_queScript_template
# from ceasiompy.utils.create_ainpfile import CreateAinp

MODULE_DIR = Path(__file__).parent
input_que_script_path = get_edge_queScript_template()

# cpacs_in_path = Path(MODULE_DIR / "ToolInput" / "ToolInput.xml")
cpacs_in_path = Path('/home/mengmeng/Documents/CEASIOMpy23/CEASIOMpy/WKDIR/labARstraight_toolInput.xml')
cpacs_out_path = MODULE_DIR / "ToolOutput.xml"
wkdir = MODULE_DIR / "Results/Edge"


if not os.path.exists(wkdir):
os.makedirs(wkdir)

generate_edge_cfd_ainp(cpacs_in_path, cpacs_out_path, wkdir)

0 comments on commit 2a9941b

Please sign in to comment.