csdms / dakotathon

A Python API and BMI for the Dakota iterative systems analysis toolkit
MIT License
13 stars 8 forks source link

Performing optimization using Dakotathon? #78

Closed johnjasa closed 4 years ago

johnjasa commented 4 years ago

We're interested in optimizing a Python model using Dakota for wind turbine design at NREL. I see that most of Dakotathon's capabilities center around parameter studies or UQ.

Do you know of any forks or branches that include optimization capability through Dakota? If not, could you comment on how much effort you think it would take to implement that in our own fork of Dakotathon?

Thanks! Please let me know if I should post this question elsewhere.

gregtucker commented 4 years ago

Thanks for your question @johnjasa. The creator of Dakotathon, Mark Piper (@mdpiper), is on vacation this week, and hopefully can respond next week. In the meantime, Katy Barnhart (@kbarnhart) and I used Dakota for optimization and sensitivity analysis in a recent modeling-oriented project with models and metric-evaluation scripts. Specifically, the optimization routines in Dakota we used were Efficient Global Optimization (EGO) and NL2SOL. I'm actually not sure to what extent Katy wove those methods into Dakotathon; I've tagged her here in hopes she may be able to shed light on this question.

kbarnhart commented 4 years ago

@johnjasa I'm not entirely up on what @mdpiper has put into Dakotathon at present. I don't think the python wrapper includes optimization capabilities. (pressed enter too fast more coming).

kbarnhart commented 4 years ago

My recollection is that Dakotathon provides a python wrapper that creates the Dakota flat text input file and provides built-in functions that then execute that file. Given your needs I'd recommend creating a Dakota input file and just running Dakota from the command line. In my own use, since I wanted to use Dakota methods that both were and were not supported by Dakotathon, I've found it relatively easy to specify the Dakota input file by hand. Dakota provides a GUI, which I'm under the impression that people really like. I, however, have never used it, so can't speak based on personal experience.

I created some materials for a clinic (https://github.com/kbarnhart/calibration_with_dakota_clinic/) in which I use a simple python model and a few different Dakota optimization methods. It may provide a useful template for you as it has example input files, example drivers, and example template folders. If you have questions about it, feel free to make an issue in that repo.

mdpiper commented 4 years ago

Hi @johnjasa! (And thank you @gregtucker and @kbarnhart for responding while I was away.)

Which Dakota optimization method are you interested in? Given my past work, I think it would be straightforward to add a new Dakota method to Dakotathon. The problem is I have a pair of events in July and August that will prevent me from spending much time on this now. If you wish to try this yourself, it'll require:

  1. the addition of a new Method class (in Python) that describes the Dakota optimization method you wish to use,
  2. a templated version of your model's configuration file(s) (Dakota modifies this on each iteration), and
  3. a new plugin class (in Python) that describes how to call your model (see, e.g., hydrotrend.py).

As @kbarnhart mentioned, it may be better to use Dakota directly. But please let me know if you'd like to pursue a solution through Dakotathon, and I'd be happy to work with you!

johnjasa commented 4 years ago

Thank you all for your fantastic help and explanations!

@kbarnhart, your clinic repo has been very helpful and has answered quite a lot of my questions. The tutorial is very digestible.

@mdpiper, thanks for spelling out exactly what's needed within Dakotathon. This list, coupled with the well-commented and structured nature of the code, makes the effort seem doable. We're interested in constructing the optimization setup to easily use a few different methods, including npsol_sqp, optpp_q_newton, and dot_mmfd. We're still in the exploratory phase of a new project, so we're not certain the breadth of optimization methods to include yet.

I'll plan to implement the optimization wrapper this month and will assess how reasonable it is for our project. For more context, we're aiming to use Dakota to optimize wind turbines modeled in WISDEM. These models are built using the OpenMDAO framework, which already interfaces with a few different Python-based optimization packages. Our goal is to have the Dakota optimization problems have the same entry points as other methods so the user doesn't have to worry about input/output files, hence our desire to use Dakotathon to wrap the problem.

I won't hesitate to reach out if I encounter a roadblock or have something useful to contribute. I really appreciate your support! I'll close this for now.