This commit is contained in:
guanjihuan 2024-10-22 00:30:50 +08:00
parent 741f8ae5c1
commit 6b9bb8afaa
4 changed files with 60 additions and 5 deletions

View File

@ -1,7 +1,7 @@
[metadata] [metadata]
# replace with your username: # replace with your username:
name = guan name = guan
version = 0.1.119 version = 0.1.120
author = guanjihuan author = guanjihuan
author_email = guanjihuan@163.com author_email = guanjihuan@163.com
description = An open source python package description = An open source python package

View File

@ -1,6 +1,6 @@
Metadata-Version: 2.1 Metadata-Version: 2.1
Name: guan Name: guan
Version: 0.1.119 Version: 0.1.120
Summary: An open source python package Summary: An open source python package
Home-page: https://py.guanjihuan.com Home-page: https://py.guanjihuan.com
Author: guanjihuan Author: guanjihuan

View File

@ -55,8 +55,8 @@ def preprocess_for_parallel_calculations(parameter_array_all, task_num=1, task_i
parameter_array = parameter_array_all[task_index*num_parameter:num_all] parameter_array = parameter_array_all[task_index*num_parameter:num_all]
return parameter_array return parameter_array
# 创建一个sh文件用于提交任务 # 创建一个sh文件用于提交任务PBS
def make_sh_file(sh_filename='a', command_line='python a.py', cpu_num=1, task_name='task', cd_dir=0): def make_sh_file_for_qsub(sh_filename='a', command_line='python a.py', cpu_num=1, task_name='task', cd_dir=0):
sh_content = \ sh_content = \
'#!/bin/sh\n' \ '#!/bin/sh\n' \
+'#PBS -N '+task_name+'\n' \ +'#PBS -N '+task_name+'\n' \
@ -67,7 +67,20 @@ def make_sh_file(sh_filename='a', command_line='python a.py', cpu_num=1, task_na
with open(sh_filename+'.sh', 'w') as f: with open(sh_filename+'.sh', 'w') as f:
f.write(sh_content) f.write(sh_content)
# 复制.py和.sh文件然后提交任务实现半手动并行 # 创建一个sh文件用于提交任务LSF
def make_sh_file_for_bsub(sh_filename='a', command_line='python a.py', cpu_num=1, task_name='task', queue_name='score', cd_dir=0):
sh_content = \
'#!/bin/sh\n' \
+'#BSUB -J '+task_name+'\n' \
+'#BSUB -q '+queue_name+'\n' \
+'#BSUB -n '+str(cpu_num)+'\n'
if cd_dir==1:
sh_content += 'cd $PBS_O_WORKDIR\n'
sh_content += command_line
with open(sh_filename+'.sh', 'w') as f:
f.write(sh_content)
# 复制.py和.sh文件然后提交任务实现半手动并行PBS
def copy_py_sh_file_and_qsub_task(parameter_array, py_filename='a', old_str_in_py='parameter=0', new_str_in_py='parameter=', sh_filename='a', qsub_task_name='task'): def copy_py_sh_file_and_qsub_task(parameter_array, py_filename='a', old_str_in_py='parameter=0', new_str_in_py='parameter=', sh_filename='a', qsub_task_name='task'):
import os import os
parameter_str_array = [] parameter_str_array = []
@ -104,6 +117,43 @@ def copy_py_sh_file_and_qsub_task(parameter_array, py_filename='a', old_str_in_p
# qsub task # qsub task
os.system('qsub '+new_file) os.system('qsub '+new_file)
# 复制.py和.sh文件然后提交任务实现半手动并行LSF
def copy_py_sh_file_and_bsub_task(parameter_array, py_filename='a', old_str_in_py='parameter=0', new_str_in_py='parameter=', sh_filename='a', bsub_task_name='task'):
import os
parameter_str_array = []
for i0 in parameter_array:
parameter_str_array.append(str(i0))
index = 0
for parameter_str in parameter_str_array:
index += 1
# copy python file
old_file = py_filename+'.py'
new_file = py_filename+'_'+str(index)+'.py'
os.system('cp '+old_file+' '+new_file)
with open(new_file, 'r') as f:
content = f.read()
old_str = old_str_in_py
new_str = new_str_in_py+parameter_str
content = content.replace(old_str, new_str)
with open(py_filename+'_'+str(index)+'.py', 'w') as f:
f.write(content)
# copy sh file
old_file = sh_filename+'.sh'
new_file = sh_filename+'_'+str(index)+'.sh'
os.system('cp '+old_file+' '+new_file)
with open(new_file, 'r') as f:
content = f.read()
old_str = 'python '+py_filename+'.py'
new_str = 'python '+py_filename+'_'+str(index)+'.py'
content = content.replace(old_str, new_str)
old_str = bsub_task_name
new_str = bsub_task_name+'_'+str(index)
content = content.replace(old_str, new_str)
with open(sh_filename+'_'+str(index)+'.sh', 'w') as f:
f.write(content)
# bsub task
os.system('bsub < '+new_file)
# 自动先后运行程序 # 自动先后运行程序
def run_programs_sequentially(program_files=['./a.py', './b.py'], execute='python ', show_time=0): def run_programs_sequentially(program_files=['./a.py', './b.py'], execute='python ', show_time=0):
import os import os

View File

@ -1,5 +1,10 @@
# Module: deprecated # Module: deprecated
def make_sh_file(sh_filename='a', command_line='python a.py', cpu_num=1, task_name='task', cd_dir=0):
import guan
print('Warning: The current function name has been deprecated, which will be deleted in the future version. Please change it into guan.make_sh_file_for_qsub().')
guan.make_sh_file_for_qsub(sh_filename=sh_filename, command_line=command_line, cpu_num=cpu_num, task_name=task_name, cd_dir=cd_dir)
def plot_without_starting_fig(plt, fig, ax, x_array, y_array, xlabel='x', ylabel='y', title='', fontsize=20, style='', y_min=None, y_max=None, linewidth=None, markersize=None, color=None, fontfamily='Times New Roman'): def plot_without_starting_fig(plt, fig, ax, x_array, y_array, xlabel='x', ylabel='y', title='', fontsize=20, style='', y_min=None, y_max=None, linewidth=None, markersize=None, color=None, fontfamily='Times New Roman'):
import guan import guan
print('Warning: The current function name has been deprecated, which will be deleted in the future version. Please change it into guan.plot_without_starting_fig_ax().') print('Warning: The current function name has been deprecated, which will be deleted in the future version. Please change it into guan.plot_without_starting_fig_ax().')