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

HParam object not used in worker script #29

Open
maxwnewcomer opened this issue Jul 18, 2022 · 0 comments
Open

HParam object not used in worker script #29

maxwnewcomer opened this issue Jul 18, 2022 · 0 comments
Assignees

Comments

@maxwnewcomer
Copy link
Owner

Convert following code to use the new HParam object for future MF6 compatibility

def inputHp2nwt(inputHp, cwd):
"""
Takes Hyperopt Hyperparameter format and reformats it as a .nwt file. This .nwt file
overwrites the local .nwt file and will thus be used by MODFLOW
inputHp - hyperopt hyperparams
cwd - working directory of project
creates *.nwt file
returns path to *.nwt file
"""
# keep track of which NWTNUM the machine is on
with open(os.path.join(cwd, 'nwts', 'nwtnum.txt'), 'r+') as f:
NWTNUM = int(f.read())
f.seek(0)
f.truncate()
f.write(str(NWTNUM+1))
# Write the standard first line of the .nwt file
with open(os.path.join(cwd, 'nwts', ('nwt_{}.nwt'.format(NWTNUM))), 'w') as file:
file.write(('{} {} {} {} {} {} {} {} CONTINUE {} {} {} {} {} {} {} {}'.format(inputHp[1],
inputHp[2],
int(inputHp[3]),
inputHp[4],
inputHp[0]['linmeth'],
inputHp[5],
inputHp[6],
inputHp[7],
inputHp[8],
inputHp[9],
inputHp[10],
inputHp[11],
inputHp[12],
int(inputHp[13]),
inputHp[14],
inputHp[15])) + '\n')
# depending on the linmeth setting, change the formatting of the rest of the file
if inputHp[0]['linmeth'] == 1:
with open(os.path.join(cwd, 'nwts', ('nwt_{}.nwt'.format(NWTNUM))), 'a') as file:
file.write(('{} {} {} {} {}'.format(int(inputHp[0]['maxitinner']),
inputHp[0]['ilumethod'],
int(inputHp[0]['levfill']),
inputHp[0]['stoptol'],
int(inputHp[0]['msdr']))))
elif inputHp[0]['linmeth'] == 2:
with open(os.path.join(cwd, 'nwts', ('nwt_{}.nwt'.format(NWTNUM))), 'a') as file:
file.write(('{} {} {} {} {} {} {} {} {} {}'.format(inputHp[0]['iacl'],
inputHp[0]['norder'],
int(inputHp[0]['level']),
int(inputHp[0]['north']),
inputHp[0]['iredsys'],
inputHp[0]['rrctols'],
inputHp[0]['idroptol'],
inputHp[0]['epsrn'],
inputHp[0]['hclosexmd'],
int(inputHp[0]['mxiterxmd']))))
return os.path.join(cwd, 'nwts', ('nwt_{}.nwt'.format(NWTNUM)))

@maxwnewcomer maxwnewcomer self-assigned this Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant