Coder Social home page Coder Social logo

maxwnewcomer / nwtopt Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 63.42 MB

NWTOPT is a hyperparameter optimization and tuning system for steady-state and transient models ran by MODFLOW-NWT

License: Creative Commons Zero v1.0 Universal

Python 96.65% Shell 3.35%

nwtopt's People

Contributors

boomchrisvanden avatar hwreeves-usgs avatar maxwnewcomer avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nwtopt's Issues

nwtopt master script

currently the user has to run a series of command to get NWTOPT up and running. This is not the intended functionality of NWTOPT and the master NWTOPT.py script needs to be fixed and reworked.

no condor log folder in master directory

HTCondor allows for logging, but the folder specified in nwtopt.sub doesn't exist, thus no logging occurs. Simple fix. Should look like this:

  • ./logs/errors
  • ./logs/outputs
  • ./logs/condor_logs

Setup Script

Would like to create a setup script that automatically does the following with verbose output describing whats happening:
<env_name> should be a prompt for user input

conda env create -n <env_name> -f conda_requirements.yml
conda activate <env_name>
conda pack -n <env_name> -o nwtenv.tgz
mkdir mongodb/db
mkdir logs
mkdir logs/condor_logs; mkdir logs/errors; mkdir logs/outputs

named: setup.sh

timeout isn't working as intended

Currently the timeout functionality isn't working and is actually actively ruining runs, possible relation to issue #4 with reading in the run.sh file, possibly not

Windows project files to linux

Flag in NWTOPT.py that will initially automatically convert windows files paths in project folder to linux file paths:

  • .\ -> ``
  • \ -> /

Probably elegant solution with os.path module, issue dependent on #21 to be closed first

Tired of going through project files and manually Ctrl-f finding replacing... :(

HParam object not used in worker script

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)))

missing run.sh?

I tried starting NWTOPT using the command lines you sent. Seems like things start up but then hang.
I'm getting an error in the logfile:

INFO (hyperopt.mongoexp): job exception: [Errno 2] No such file or directory: 'run.sh'

Do I need to copy run.sh to my project directory? I have it in the main NWTOPT directory.

Also, I changed the port so I wouldn't clash with other runs (to 27020) in the command lines and nwtopt.sub.

I didn't run nwtopt.sh manually anywhere, just

mongodb/bin/mongod --dbpath mongodb/db --bind_ip 130.11.177.99 --port 27020
 
condor_submit nwtopt.sub
 
cd NWT_SUBMIT/NWTOPT_FILES; python optimize_NWT.py --ip 130.11.177.99 --port 27020 --key badger_19F --trials 3000

Am I missing something?

MODFLOW-6 support

Would love to have an extension to NWTOPT for modflow-6. Mike already has the beginnings, but would be great to get this done after getting the main nwtopt stuff done.

set IPRNWT to consistent value

The IPRNWT parameter just sets printing of iteration information so it probably should be consistently set to 0 or 1.

Setting it to 0 gives a slightly faster overall time because MODFLOW-NWT doesn't have to write out all
the iteration information; but its nice to have it set to 1 for checking model performance. Maybe the time difference between the same set of parameters with IPRNWT 0 or 1 is not that important; but it should be something.

I suggest setting it to 0 for NWTOPT, users can easily flip it to 1 if they want to look at where the model
is getting bogged down. You are not saving the list files in NWTOPT, so setting the flag to 1 would not
be helpful in the optimization.

HWR

Purge IPs

Purge historic ips from git history, then recreate file, then create precommit hook that will change .sub file to be generic

redundant code

This part of the objective function is redudant:

# get necessary file names and paths
for file in os.listdir(cwd):
if file.endswith('.nam'):
namefile = file
elif file.endswith('.list') or file.endswith('.lst'):
listfile = file
elif file.endswith('.nwt'):
initnwt = file
foundList, foundNWT = False, False

Multistep loss function

I remember @hwreeves-USGS, @rjhunt-usgs, and I had a conversation on a different loss function that would incorporate MB throughout each step, but I'm forgetting what the suggestion for change was. Would either of you be able to clarify what that idea was? It was something like an averaging of per-step MB I think...

timeout units

Looks like the example run.sh script says to enter timeout value in minutes but the code is converting to seconds.....just need to choose :)

should mass_balance be absolute value?

Max,
Looking at objective.py, after it finds mass_balance around line 85, should it be made strictly positive?

mass_balance = np.abs(mass_balance)?

I guess you can't do it in the try statement because it will throw an error for characters in the line.

It must not be a big deal or you'd be getting strange results, but just in case it seems like making sure the mass balance error used in the loss function is positive would be a good idea.

HWR

OOP Switch

Currently the codebase is messy, confusing, uses globals, and overall a little gross. Planning on creating an object orientated approach in the solution to this issue.

improve documentation

documentation leaves out file structure information and non-condor run execution instructions. These should be added before a "formal" release of the software.

update documentation on directories

The user needs to add mongodb/db and logs/condor_logs, logs/outputs, and logs/errors

NWTOPT worked after adding these - fixing the earlier issues.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.