Skip to content

Commit

Permalink
Merge pull request #323 from Kenneth-T-Moore/ken2
Browse files Browse the repository at this point in the history
API change, remove outputs from compute_partials
  • Loading branch information
naylor-b committed Aug 8, 2017
2 parents 844b715 + 7d8ca80 commit 7e10c67
Show file tree
Hide file tree
Showing 26 changed files with 63 additions and 75 deletions.
7 changes: 2 additions & 5 deletions openmdao/components/exec_comp.py
Expand Up @@ -232,7 +232,7 @@ def compute(self, inputs, outputs):
for expr in self._codes:
exec(expr, _expr_dict, _IODict(outputs, inputs))

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
"""
Use complex step method to update the given Jacobian.
Expand All @@ -241,9 +241,6 @@ def compute_partials(self, inputs, outputs, partials):
inputs : `VecWrapper`
`VecWrapper` containing parameters. (p)
outputs : `VecWrapper`
`VecWrapper` containing outputs and states. (u)
partials : `Jacobian`
Contains sub-jacobians.
"""
Expand Down Expand Up @@ -273,7 +270,7 @@ def compute_partials(self, inputs, outputs, partials):
else:
pwrap[param][idx] += step

uwrap = _TmpDict(outputs, return_complex=True)
uwrap = _TmpDict(self._outputs, return_complex=True)

# solve with complex param value
self._residuals.set_const(0.0)
Expand Down
4 changes: 1 addition & 3 deletions openmdao/components/meta_model.py
Expand Up @@ -312,16 +312,14 @@ def _vec_to_array2d(self, vec):

return arr

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
"""
Compute sub-jacobian parts. The model is assumed to be in an unscaled state.
Parameters
----------
inputs : Vector
unscaled, dimensional input variables read via inputs[key]
outputs : Vector
unscaled, dimensional output variables read via outputs[key]
partials : Jacobian
sub-jac components written to partials[output_name, input_name]
"""
Expand Down
6 changes: 2 additions & 4 deletions openmdao/core/explicitcomponent.py
Expand Up @@ -296,7 +296,7 @@ def _linearize(self, do_nl=False, do_ln=False):
# negate constant subjacs (and others that will get overwritten)
# back to normal
self._negate_jac()
self.compute_partials(self._inputs, self._outputs, J)
self.compute_partials(self._inputs, J)

# re-negate the jacobian
self._negate_jac()
Expand All @@ -322,16 +322,14 @@ def compute(self, inputs, outputs):
"""
pass

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
"""
Compute sub-jacobian parts. The model is assumed to be in an unscaled state.
Parameters
----------
inputs : Vector
unscaled, dimensional input variables read via inputs[key]
outputs : Vector
unscaled, dimensional output variables read via outputs[key]
partials : Jacobian
sub-jac components written to partials[output_name, input_name]
"""
Expand Down
4 changes: 2 additions & 2 deletions openmdao/core/tests/test_approx_derivs.py
Expand Up @@ -153,7 +153,7 @@ def test_arrray_comp(self):

class DoubleArrayFD(DoubleArrayComp):

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
"""
Override deriv calculation.
"""
Expand Down Expand Up @@ -493,7 +493,7 @@ def test_arrray_comp(self, vec_class):

class DoubleArrayFD(DoubleArrayComp):

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
"""
Override deriv calculation.
"""
Expand Down
14 changes: 7 additions & 7 deletions openmdao/core/tests/test_check_derivs.py
Expand Up @@ -27,7 +27,7 @@ def compute(self, inputs, outputs):
""" Doesn't do much. """
outputs['y'] = 3.0*inputs['x1'] + 4.0*inputs['x2']

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
"""Intentionally incorrect derivative."""
J = partials
J['y', 'x1'] = np.array([4.0])
Expand Down Expand Up @@ -74,7 +74,7 @@ def compute(self, inputs, outputs):
""" Doesn't do much. """
outputs['y'] = 3.0*inputs['x1'] + 4.0*inputs['x2']

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
"""Intentionally incorrect derivative."""
J = partials
J['y', 'x1'] = np.array([4.0])
Expand Down Expand Up @@ -117,7 +117,7 @@ def compute(self, inputs, outputs):
""" Doesn't do much. """
outputs['y'] = 3.0*inputs['x1'] + 4.0*inputs['x2']

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
"""Intentionally incorrect derivative."""
J = partials
J['y', 'x1'] = np.array([4.0])
Expand Down Expand Up @@ -153,7 +153,7 @@ def compute(self, inputs, outputs):
""" Doesn't do much. """
outputs['y'] = 3.0*inputs['x1'] + 4.0*inputs['x2']

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
"""Intentionally incorrect derivative."""
J = partials
J['y', 'x1'] = np.array([4.0])
Expand Down Expand Up @@ -193,7 +193,7 @@ def compute(self, inputs, outputs):
""" Doesn't do much. """
outputs['y'] = 3.0*inputs['x1'] + 4.0*inputs['x2']

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
"""Intentionally incorrect derivative."""
J = partials
J['y', 'x1'] = np.array([4.0])
Expand Down Expand Up @@ -231,7 +231,7 @@ def compute(self, inputs, outputs):
""" Doesn't do much. """
outputs['y'] = 3.0*inputs['x1'] + 4.0*inputs['x2']

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
"""Intentionally left out derivative."""
J = partials
J['y', 'x1'] = np.array([3.0])
Expand Down Expand Up @@ -317,7 +317,7 @@ def setup(self):

self.run_count = 0

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
partials['flow:T', 'T'] = 1.
partials['flow:P', 'P'] = 1.

Expand Down
2 changes: 1 addition & 1 deletion openmdao/core/tests/test_expl_comp.py
Expand Up @@ -27,7 +27,7 @@ def compute(self, inputs, outputs):

class RectanglePartial(RectangleComp):

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
partials['area', 'length'] = inputs['width']
partials['area', 'width'] = inputs['length']

Expand Down
2 changes: 1 addition & 1 deletion openmdao/core/tests/test_matmat.py
Expand Up @@ -224,7 +224,7 @@ def compute(self, inputs, outputs):
outputs['f_arclength'] = np.sqrt(1 + inputs['yp_lgl']**2)


def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
partials['f_arclength', 'yp_lgl'] = inputs['yp_lgl'] / np.sqrt(1 + inputs['yp_lgl']**2)


Expand Down
2 changes: 1 addition & 1 deletion openmdao/core/tests/test_parallel_groups.py
Expand Up @@ -211,7 +211,7 @@ def setup(self):
def compute(self, inputs, outputs):
outputs['y'] = inputs['x'] * self.mult

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
partials['y', 'x'] = numpy.array([self.mult])

prob = Problem()
Expand Down
4 changes: 2 additions & 2 deletions openmdao/core/tests/test_reconf.py
Expand Up @@ -26,7 +26,7 @@ def setup(self):
def compute(self, inputs, outputs):
outputs['y'] = 2 * inputs['x']

def compute_partials(self, inputs, outputs, jacobian):
def compute_partials(self, inputs, jacobian):
jacobian['y', 'x'] = 2 * np.ones((self.size, 1))


Expand All @@ -39,7 +39,7 @@ def setup(self):
def compute(self, inputs, outputs):
outputs['z'] = 3 * inputs['x']

def compute_partials(self, inputs, outputs, jacobian):
def compute_partials(self, inputs, jacobian):
jacobian['z', 'x'] = 3.0


Expand Down
4 changes: 2 additions & 2 deletions openmdao/core/tests/test_reconf_dynamic.py
Expand Up @@ -28,7 +28,7 @@ def setup(self):
def compute(self, inputs, outputs):
outputs['y'] = 2 * inputs['x']

def compute_partials(self, inputs, outputs, jacobian):
def compute_partials(self, inputs, jacobian):
jacobian['y', 'x'] = 2 * np.ones((self.size, 1))


Expand All @@ -47,7 +47,7 @@ def setup(self):
def compute(self, inputs, outputs):
outputs['z'] = 3 * inputs['x']

def compute_partials(self, inputs, outputs, jacobian):
def compute_partials(self, inputs, jacobian):
jacobian['z', 'x'] = 3.0


Expand Down
2 changes: 1 addition & 1 deletion openmdao/core/tests/test_scaling.py
Expand Up @@ -343,7 +343,7 @@ def setup(self):
def compute(self, inputs, outputs):
outputs['y'] = 2.0*(inputs['x'] + 1.0)

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
"""
Jacobian for Sellar discipline 1.
"""
Expand Down
3 changes: 1 addition & 2 deletions openmdao/docs/features/building_components/explicitcomp.rst
Expand Up @@ -31,10 +31,9 @@ The implementation of each method will be illustrated using a simple explicit co
.. embed-code::
openmdao.core.tests.test_expl_comp.RectangleComp.compute

- :code:`compute_partials(inputs, outputs, partials)` :
- :code:`compute_partials(inputs, partials)` :

[Optional] Compute the :code:`partials` (partial derivatives) given the :code:`inputs`.
The :code:`outputs` are also provided for convenience.

.. embed-code::
openmdao.core.tests.test_expl_comp.RectanglePartial.compute_partials
Expand Down
8 changes: 2 additions & 6 deletions openmdao/docs/style_guide/sphinx_decorators.rst
Expand Up @@ -29,16 +29,14 @@ and a method that looks like this and has the decorator applied to it:
::

@mydecorator
def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
"""
Compute sub-jacobian parts / factorization.

Parameters
----------
inputs : Vector
unscaled, dimensional input variables read via inputs[key]
outputs : Vector
unscaled, dimensional output variables read via outputs[key]
partials : Jacobian
sub-jac components written to partials[output_name, input_name]
"""
Expand All @@ -57,16 +55,14 @@ But if we add the call signature of the method to the docstring as the first lin
::

@mydecorator
def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
"""
Compute sub-jacobian parts / factorization.

Parameters
----------
inputs : Vector
unscaled, dimensional input variables read via inputs[key]
outputs : Vector
unscaled, dimensional output variables read via outputs[key]
partials : Jacobian
sub-jac components written to partials[output_name, input_name]
"""
Expand Down
2 changes: 1 addition & 1 deletion openmdao/drivers/tests/test_pyoptsparse_driver.py
Expand Up @@ -59,7 +59,7 @@ def compute(self, inputs, outputs):
outputs['f_xy'] = (x-3.0)**2 + x*y + (y+4.0)**2 - 3.0
self.eval_iter_count += 1

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
""" Jacobian for our paraboloid."""

if self.grad_iter_count == self.grad_fail_at:
Expand Down
6 changes: 3 additions & 3 deletions openmdao/jacobians/tests/test_jacobian.py
Expand Up @@ -43,7 +43,7 @@ def compute(self, inputs, outputs):
y[0]*17. - y[0]*y[1] + 2.*y[1]
outputs['f'][1] = outputs['f'][0]*3.0

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
x = inputs['x']
y = inputs['y']
jac1 = self._jac_type(np.array([
Expand Down Expand Up @@ -94,7 +94,7 @@ def compute(self, inputs, outputs):
z = inputs['z']
outputs['f'] = (w[0]-5.0)**2 + (w[1]+1.0)**2 + w[2]*6. + z*7.

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
w = inputs['w']
z = inputs['z']
jac = self._jac_type(np.array([[
Expand Down Expand Up @@ -137,7 +137,7 @@ def setup(self):
self.add_input('in', val=in_val*scale)
self.add_output('out', val=out_val*scale)

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
partials['out', 'in'] = self._constructor(self._value)


Expand Down
18 changes: 9 additions & 9 deletions openmdao/jacobians/tests/test_jacobian_features.py
Expand Up @@ -31,7 +31,7 @@ def compute(self, inputs, outputs):
+ np.outer(np.ones(2), inputs['y2'])
+ inputs['x']*np.eye(2))

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
partials['f', 'x'] = 1.
partials['f', 'z'] = np.ones((1, 4))

Expand Down Expand Up @@ -102,7 +102,7 @@ def compute(self, inputs, outputs):
outputs['f'] = np.sum(inputs['z']) + inputs['x']
outputs['g'] = np.outer(inputs['y1'] + inputs['y3'], inputs['y2']) + inputs['x'] * np.eye(2)

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
pass


Expand All @@ -119,7 +119,7 @@ def setup(self):

self.approx_partials('*', '*', **self.kwargs)

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
pass


Expand All @@ -137,7 +137,7 @@ def setup(self):
self.approx_partials('g', 'x', **self.kwargs)
self.approx_partials('g', 'y2', **self.kwargs)

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
partials['f', 'x'] = 1.
partials['f', 'z'] = np.ones((1, 4))

Expand All @@ -157,7 +157,7 @@ def setup(self):

self.declare_partials(**self.partial_kwargs)

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
pass


Expand Down Expand Up @@ -403,7 +403,7 @@ def setup(self):
self.add_output('z', shape=(3,))
self.add_input('x', shape=(3,), units='degF')

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
partials['y', 'x'] = self.A
partials['z', 'x'] = self.A

Expand Down Expand Up @@ -464,7 +464,7 @@ def setup(self):

self.declare_partials(of='f', wrt='x', rows=[0,1,1,1], cols=[0,1,2,3])

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
pd = partials['f', 'x']

# Corresponds to the (0, 0) entry
Expand Down Expand Up @@ -503,7 +503,7 @@ def setup(self):

self.declare_partials(of='f', wrt='x', rows=[0, 1, 1, 1], cols=[0, 1, 2, 3])

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
# Corresponds to the [(0,0), (1,1), (1,2), (1,3)] entries.
partials['f', 'x'] = [1., 2., 3., 4.]

Expand Down Expand Up @@ -534,7 +534,7 @@ def setup(self):
val=[1. , 2., 3., 4.])
self.declare_partials(of='f', wrt='y', val=sp.sparse.eye(2, format='csc'))

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
pass

model = Group()
Expand Down
2 changes: 1 addition & 1 deletion openmdao/solvers/linesearch/tests/test_backtracking.py
Expand Up @@ -152,7 +152,7 @@ def compute(self, inputs, outputs):

outputs['f_xy'] = (x-3.0)**2 + x*y + (y+4.0)**2 - 3.0

def compute_partials(self, inputs, outputs, partials):
def compute_partials(self, inputs, partials):
""" Jacobian for our paraboloid."""
x = inputs['x']
y = inputs['y']
Expand Down

0 comments on commit 7e10c67

Please sign in to comment.