Chris
Chris

Reputation: 57

How to re-run problem with different model in for loop?

I'm doing a design study that requires me to run many optimization problems on different models. My issue is that any optimization after the first fails. For example, I run study 1 first and the problem converges. Then I run studies 2, 3, 4, etc and the problems fail. However, if I start by running study 2 first, the problem converges. Then I can run studies 1, 3, 4, etc and the problems fail. It seems someone has had a similar problem in the past and I've done as described in the previous post: Replaceing Component in OpenMDAO Group. Psuedo-code for my problem is provided below:

for i in range(N):
    p = om.Problem()
    add_subsystem(Model i)
    add driver and solvers
    add constraints
    add design variables
    add objective
    p.setup()
    set initial guesses
    run driver and save data
    p.cleanup()
    del p

As you can see, I cleanup, delete, and re-instantiate the problem at every iteration of the for loop. However, all optimizations after the first fail. Do you know why this process would fail? Is there anyway to correct it?

Also, to be clear, every model is uniquely structured with different variables, so I cannot simply change specific parameter values and just re-run the driver.

Upvotes: 1

Views: 141

Answers (1)

Justin Gray
Justin Gray

Reputation: 5710

You have not given much detail, but if your pseudocode is a good match to your model then the problem is not related to OpenMDAO itself. No state is shared between multiple problem instances. The behavior you are seeing is stateful though.

So something in one of your components or groups must be storing state somehow. Either writing something to a file that gets read by the next case, storing values in a global variable of some kind, or calling out to a compiled library that is stateful in some way.

Without more details on your model or an example case of some kind its hard to be more specific.

Upvotes: 0

Related Questions