I'm a little bit confused about how to specify FD step sizes on the individual design variables. In the old OpenMDAO it was possible to specify the step size when adding the desvar. In the new version add_desvar does not have this argument, so I tried to set it on the IndepVarComp's fd_options, which didn't work either. It is not so intuitive to me that I have to set it on the downstream component. But in case I had to do it this way, how would I set it on each individual param at setup time? I'm probably missing something, but could you please let me know how to to it on the below example where I'm trying to set the step size of prob.root.sub.p1
with force_fd
on the whole problem.
from openmdao.api import Component, Group, Problem, IndepVarComp
class MyComp(Component):
def __init__(self):
super(MyComp, self).__init__()
# Params
self.add_param('x1', 3.0, step_size = 1e-2)
self.add_param('x2', 3.0)
# Unknowns
self.add_output('y', 5.5)
def solve_nonlinear(self, params, unknowns, resids):
""" Doesn't do much. """
unknowns['y'] = 7.0*params['x1']**2 + 7.0*params['x2']**2
prob = Problem()
prob.root = Group()
sub = prob.root.add('sub', Group())
comp = prob.root.add('comp', MyComp())
p1 = sub.add('p1', IndepVarComp([('x1', 3.0), ('x2', 3.0)]))
# this has no effect
prob.root.sub.p1.fd_options['step_size'] = 1.0e-1
prob.root.connect('sub.p1.x1', 'comp.x1')
prob.root.connect('sub.p1.x2', 'comp.x2')
prob.root.fd_options['force_fd'] = True
prob.setup(check=False)
prob.run()
J = prob.calc_gradient(['sub.p1.x1', 'sub.p1.x2'], ['comp.y'], return_format='dict')
print J
If I print mydict in System.fd_jacobian
and the step size I see:
('mydict', {'shape': 1, 'step_size': 0.01, 'pathname': 'comp.x1', 'val': 3.0, 'promoted_name': 'comp.x1', 'top_promoted_name': 'comp.x1', 'size': 1})
('FD', 'comp.x1', 0.01)
('mydict', {'val': 3.0, 'promoted_name': 'comp.x2', 'shape': 1, 'pathname': 'comp.x2', 'top_promoted_name': 'comp.x2', 'size': 1})
('FD', 'comp.x2', 1e-06)
{'comp.y': {'sub.p1.x1': array([[ 42.07]]), 'sub.p1.x2': array([[ 42.000007]])}}
Thanks!