Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from master/slave lingo #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions geophys_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def process_tem(self,pp_x,pp_y,err=0.8,data_min=0.0):
- data_i <= 0
- err <= error_i

See master Thesis by Jacobsen
See main Thesis by Jacobsen
"""


Expand Down Expand Up @@ -918,7 +918,7 @@ def voxel_setup(self,pp_x,pp_y,nite1=50,sharp=0,nite2=40):
# shutil.rmtree(path_tem_data)
# os.mkdir(path_tem_data)
# except shutil.Error as e:
# print 'Error in copy2slave:'
# print 'Error in copy2subordinate:'
# print('Directory not copied. Error: %s' % e)
# print 'folder does not excist!!! '
#
Expand Down
64 changes: 32 additions & 32 deletions inversion_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,12 @@ def batch_gw_model(self,mf_nam,pp_x,pp_y,grid=1,pp_file_name=[],run_fac2real=Tru
print 'done'

#==============================================================================
def copy2slaves(self,pp_x,pp_y,run_allmodels='on',tmp_numb=''):
def copy2subordinates(self,pp_x,pp_y,run_allmodels='on',tmp_numb=''):
#==============================================================================
"""
Creates n slave dir.
Creates n subordinate dir.

Make n new slave subdirectories and copy pest and model files to folder
Make n new subordinate subdirectories and copy pest and model files to folder

Parameters
----------
Expand All @@ -373,24 +373,24 @@ def copy2slaves(self,pp_x,pp_y,run_allmodels='on',tmp_numb=''):
pp_y : List(int)
python list - node positions of pilot points in row direction
run_allmodel : str
run batch file "allmodels" before copying files into slave dir
run batch file "allmodels" before copying files into subordinate dir
tmp_nump : int


"""
import errno

print 'copy2slave:'
print 'copy2subordinate:'

cwd = os.getcwd()
path ='C:/temp/HYTEB'+str(tmp_numb)

for i in range(self.load.n_slaves):
for i in range(self.load.n_subordinates):
try:
shutil.rmtree(path+str(tmp_numb))
except:
# ishutil.Error as e:
print 'copy2slaves: folder does not excist!!! '
print 'copy2subordinates: folder does not excist!!! '

# --- delete temporay geophys files ---
for i in pp_y:
Expand Down Expand Up @@ -420,40 +420,40 @@ def copy2slaves(self,pp_x,pp_y,run_allmodels='on',tmp_numb=''):
subprocess.call('gw_model.bat')

print 'done'
# --- copy work folde to slave# and move folders back into work folder
for i in range(self.load.n_slaves):
# --- copy work folde to subordinate# and move folders back into work folder
for i in range(self.load.n_subordinates):
# --- copy to dir ---
print str(i+1)+'/'+str(self.load.n_slaves)
print str(i+1)+'/'+str(self.load.n_subordinates)
try:
shutil.copytree(cwd,path+'/slave'+str(i+1))
shutil.copytree(cwd,path+'/subordinate'+str(i+1))
# --- Directories are the same
except shutil.Error as e:
print 'Error in copy2slave:'
print 'Error in copy2subordinate:'
print('Directory not copied. Error: %s' % e)
# --- Directories already exist, delete and try copy again
except OSError as e:
try:
shutil.rmtree(path+'/slave'+str(i+1))
shutil.rmtree(path+'/subordinate'+str(i+1))
except shutil.Error as e:
print 'Error in copy2slave:'
print 'Error in copy2subordinate:'
print('Directory not copied. Error: %s' % e)
try:
shutil.copytree(cwd,path+'/slave'+str(i+1))
shutil.copytree(cwd,path+'/subordinate'+str(i+1))
except shutil.Error as e:
print 'Error in copy2slave:'
print 'Error in copy2subordinate:'
print('Directory not copied. Error: %s' % e)
# --- Directories already exist, delete and try copy again
except OSError as e:
print 'Error in copy2slaves:'
print 'Error in copy2subordinates:'
print('Directory not copied. Error: %s' % e)


for i in range(self.load.n_slaves):
for i in range(self.load.n_subordinates):
try:
shutil.move(path+'/slave'+str(i+1),cwd)
shutil.move(path+'/subordinate'+str(i+1),cwd)
# --- Directories are the same
except shutil.Error as e:
print 'Error in copy2slave:'
print 'Error in copy2subordinate:'
print('Directory not MOVED. Error: %s' % e)
break
except OSError as e:
Expand All @@ -462,13 +462,13 @@ def copy2slaves(self,pp_x,pp_y,run_allmodels='on',tmp_numb=''):
break

else:
print 'Error in copy2slave:'
print 'Error in copy2subordinate:'
print "\nBE CAREFUL! Directory %s already exists." % path



#==============================================================================
def delete_files(self,del_slave='off',
def delete_files(self,del_subordinate='off',
ext_PEST =('.1','.2','.3','.4','.5','.6','.7','.9','.bat','.jac','.jco','.jst','.mtt','.par','.prf','.pst','.rec','.rmr','rei','.res','.rst','.stp','.svd','.sen','.seo','.sen'),
ext_modflow=('.inf','.spc','.pth','.mpt','.mpn','.nam','.hds','.cbb','.ddn','.glo','.lst','.bas','.dis','.dis','.lpf','.rch','.wel','.oc','.gmg','.riv'),
ext_other = ('.emm','.emo','.err','.dat','.ite','.log','.ref','.tpl','.ins','.ite','.fwr','.tem','.mod','.pts','.dat','.in','.smp','.obs','.vtk','.voo')):
Expand All @@ -478,8 +478,8 @@ def delete_files(self,del_slave='off',

Parameters
----------
del_slave : str
delete PEST slave folders
del_subordinate : str
delete PEST subordinate folders
ext_PEST : tuple(str)
tuple with dtype of PEST file(s) to delete
ext_modflow : tuple(str)
Expand All @@ -493,15 +493,15 @@ def delete_files(self,del_slave='off',
print 'delete_fiels:'
cwd = os.getcwd()

# --- deleting foldes with slaves ---
if del_slave == 'on':
print ' deleting all slaves'
# --- deleting foldes with subordinates ---
if del_subordinate == 'on':
print ' deleting all subordinates'
for i in range(100):
shutil.rmtree(cwd+'\\'+'slave'+str(i+1),ignore_errors=True)
if del_slave == 'off':
print ' no slaves are deleted'
if del_slave != 'on' and del_slave != 'off':
print ' wrong input for del_slave!'
shutil.rmtree(cwd+'\\'+'subordinate'+str(i+1),ignore_errors=True)
if del_subordinate == 'off':
print ' no subordinates are deleted'
if del_subordinate != 'on' and del_subordinate != 'off':
print ' wrong input for del_subordinate!'


# --- delete files with extensions ---
Expand Down
12 changes: 6 additions & 6 deletions load_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def ini_inversion(self,inversion_file):
self.parametrization = int(ini[10])
self.tied_res = str(ini[11])
self.model_path = str(ini[12])
self.n_slaves = int(ini[13])
self.n_subordinates = int(ini[13])
self.PEST_name = str(ini[14])
self.IP_addr = str(ini[15])
self.IP_port = int(ini[16])
Expand Down Expand Up @@ -826,22 +826,22 @@ class write_file:
def batch_beopest(self,addr,load):
#==============================================================================
"""
Writes BATCH-script for running beoPEST on n-slaves (machines)
Writes BATCH-script for running beoPEST on n-subordinates (machines)

Parameters
----------
addr : str
IP adress of "slave"-machine
IP adress of "subordinate"-machine
load : obj
Object holding all initilized values read from ini files

"""
fid1 = open('run_beopest.bat','w')
fid1.write('\n')
fid1.write('REM Start n slaves'+'\n')
fid1.write('REM Start n subordinates'+'\n')
fid1.write('\n')
fid1.write('for /L %%i in (1,1,'+str(load.n_slaves)+') do ('+'\n')
fid1.write(' cd slave%%i'+'\n')
fid1.write('for /L %%i in (1,1,'+str(load.n_subordinates)+') do ('+'\n')
fid1.write(' cd subordinate%%i'+'\n')
fid1.write(' start beopest64.exe '+load.PEST_name+'.pst /h '+str(addr)+':'+str(load.IP_port)+'>> beopest_output.dat'+'\n')
fid1.write(' cd..'+'\n')
fid1.write(')'+'\n')
Expand Down
8 changes: 4 additions & 4 deletions main_HYTEB_joint_inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
# --- run HYTEB analysis for multiple realizations ---
for i in realization:

# --- delete all "old input/out put files and PEST slaves ---
invs.delete_files(del_slave='on')
# --- delete all "old input/out put files and PEST subordinates ---
invs.delete_files(del_subordinate='on')

# --- copy reference system from folder(see ini-files) to work directory ---
invs.model2folder(i)
Expand Down Expand Up @@ -154,8 +154,8 @@
# --- make PEST control file ---
invs.PEST_inversion(pp_x,pp_y,x_valley,y_valley,n_pp_valley,n_tem_data=n_tem_data)

# --- generating slave for paralization ---
invs.copy2slaves(pp_x,pp_y,tmp_numb=i)
# --- generating subordinate for paralization ---
invs.copy2subordinates(pp_x,pp_y,tmp_numb=i)

# --- run joint inversion with BeoPEST ---
invs.batch_beopest(run_inversion='on')
Expand Down