Mark Garnett
Mark Garnett

Reputation: 319

how to get list of Auto-IVC component output names

I'm switching over to using the Auto-IVC component as opposed to the IndepVar component. I'd like to be able to get a list of the promoted output names of the Auto-IVC component, so I can then use them to go and pull the appropriate value out of a configuration file and set the values that way. This will get rid of some boilerplate.

p.model._auto_ivc.list_outputs()

returns an empty list. It seems that p.model__dict__ has this information encoded in it, but I don't know exactly what is going on there so I am wondering if there is an easier way to do it.

Upvotes: 0

Views: 68

Answers (1)

Bret Naylor
Bret Naylor

Reputation: 754

To avoid confusion from future readers, I assume you meant that you wanted the promoted input names for the variables connected to the auto_ivc outputs.

We don't have a built-in function to do this, but you could do it with a bit of code like this:

seen = set()
for n in p.model._inputs:
   src = p.model.get_source(n)
   if src.startswith('_auto_ivc.') and src not in seen:
       print(src, p.model._var_allprocs_abs2prom['input'][n])
       seen.add(src)

assuming 'p' is the name of your Problem instance.

The code above just prints each auto_ivc output name followed by the promoted input it's connected to.

Here's an example of the output when run on one of our simple test cases:

_auto_ivc.v0 par.x

Upvotes: 2

Related Questions