/
test_jacobian.py
633 lines (474 loc) · 22 KB
/
test_jacobian.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
""" Test the Jacobian objects."""
import itertools
import unittest
from parameterized import parameterized
from six import assertRaisesRegex
from six.moves import range
import numpy as np
from scipy.sparse import coo_matrix, csr_matrix
from openmdao.api import IndepVarComp, Group, Problem, \
ExplicitComponent, ImplicitComponent, ExecComp, \
NewtonSolver, ScipyIterativeSolver, \
DenseJacobian, CSRJacobian, CSCJacobian, COOJacobian
from openmdao.devtools.testutil import assert_rel_error
from openmdao.test_suite.components.paraboloid import Paraboloid
from openmdao.test_suite.components.sellar import SellarDis1withDerivatives, \
SellarDis2withDerivatives
class MyExplicitComp(ExplicitComponent):
def __init__(self, jac_type):
super(MyExplicitComp, self).__init__()
self._jac_type = jac_type
def setup(self):
self.add_input('x', val=np.zeros(2))
self.add_input('y', val=np.zeros(2))
self.add_output('f', val=np.zeros(2))
val = self._jac_type(np.array([[1., 1.], [1., 1.]]))
if isinstance(val, list):
self.declare_partials('f', ['x','y'], rows=val[1], cols=val[2], val=val[0])
else:
self.declare_partials('f', ['x','y'], val=val)
def compute(self, inputs, outputs):
x = inputs['x']
y = inputs['y']
outputs['f'][0] = (x[0]-3.0)**2 + x[0]*x[1] + (x[1]+4.0)**2 - 3.0 + \
y[0]*17. - y[0]*y[1] + 2.*y[1]
outputs['f'][1] = outputs['f'][0]*3.0
def compute_partials(self, inputs, partials):
x = inputs['x']
y = inputs['y']
jac1 = self._jac_type(np.array([
[2.0*x[0] - 6.0 + x[1], 2.0*x[1] + 8.0 + x[0]],
[(2.0*x[0] - 6.0 + x[1])*3., (2.0*x[1] + 8.0 + x[0])*3.]
]))
if isinstance(jac1, list):
jac1 = jac1[0]
partials['f', 'x'] = jac1
jac2 = self._jac_type(np.array([
[17.-y[1], 2.-y[0]],
[(17.-y[1])*3., (2.-y[0])*3.]
]))
if isinstance(jac2, list):
jac2 = jac2[0]
partials['f', 'y'] = jac2
class MyExplicitComp2(ExplicitComponent):
def __init__(self, jac_type):
super(MyExplicitComp2, self).__init__()
self._jac_type = jac_type
def setup(self):
self.add_input('w', val=np.zeros(3))
self.add_input('z', val=0.0)
self.add_output('f', val=0.0)
val = self._jac_type(np.array([[7.]]))
if isinstance(val, list):
self.declare_partials('f', 'z', rows=val[1], cols=val[2], val=val[0])
else:
self.declare_partials('f', 'z', val=val)
val = self._jac_type(np.array([[1., 1., 1.]]))
if isinstance(val, list):
self.declare_partials('f', 'w', rows=val[1], cols=val[2], val=val[0])
else:
self.declare_partials('f', 'w', val=val)
def compute(self, inputs, outputs):
w = inputs['w']
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, partials):
w = inputs['w']
z = inputs['z']
jac = self._jac_type(np.array([[
2.0*w[0] - 10.0,
2.0*w[1] + 2.0,
6.
]]))
if isinstance(jac, list):
jac = jac[0]
partials['f', 'w'] = jac
class ExplicitSetItemComp(ExplicitComponent):
def __init__(self, dtype, value, shape, constructor):
self._dtype = dtype
self._shape = shape
self._value = value
self._constructor = constructor
super(ExplicitSetItemComp, self).__init__()
def setup(self):
if self._shape == 'scalar':
in_val = 1
out_val = 1
elif self._shape == '1D_array':
in_val = np.array([1])
out_val = np.array([1, 2, 3, 4, 5])
elif self._shape == '2D_array':
in_val = np.array([1, 2, 3])
out_val = np.array([1, 2, 3])
if self._dtype == 'int':
scale = 1
elif self._dtype == 'float':
scale = 1.
elif self._dtype == 'complex':
scale = 1j
self.add_input('in', val=in_val*scale)
self.add_output('out', val=out_val*scale)
def compute_partials(self, inputs, partials):
partials['out', 'in'] = self._constructor(self._value)
def arr2list(arr):
"""Convert a numpy array to a 'sparse' list."""
data = []
rows = []
cols = []
for row in range(arr.shape[0]):
for col in range(arr.shape[1]):
rows.append(row)
cols.append(col)
data.append(arr[row, col])
return [np.array(data), np.array(rows), np.array(cols)]
def arr2revlist(arr):
"""Convert a numpy array to a 'sparse' list in reverse order."""
lst = arr2list(arr)
return [lst[0][::-1], lst[1][::-1], lst[2][::-1]]
def inverted_coo(arr):
"""Convert an ordered coo matrix into one with columns in reverse order
so we can test unsorted coo matrices.
"""
shape = arr.shape
arr = coo_matrix(arr)
return coo_matrix((arr.data[::-1], (arr.row[::-1], arr.col[::-1])), shape=shape)
def inverted_csr(arr):
"""Convert an ordered coo matrix into a csr with columns in reverse order
so we can test unsorted csr matrices.
"""
return inverted_coo(arr).tocsr()
def _test_func_name(func, num, param):
args = []
for p in param.args:
try:
arg = p.__name__
except:
arg = str(p)
args.append(arg)
return 'test_jacobian_src_indices_' + '_'.join(args)
class TestJacobian(unittest.TestCase):
@parameterized.expand(itertools.product(
[DenseJacobian, CSRJacobian, CSCJacobian, COOJacobian],
[np.array, coo_matrix, csr_matrix, inverted_coo, inverted_csr, arr2list, arr2revlist],
[False, True], # not nested, nested
[0, 1], # extra calls to linearize
), testcase_func_name=_test_func_name
)
def test_src_indices(self, jacobian_class, comp_jac_class, nested, lincalls):
self._setup_model(jacobian_class, comp_jac_class, nested, lincalls)
# if we multiply our jacobian (at x,y = ones) by our work vec of 1's,
# we get fwd_check
fwd_check = np.array([1.0, 1.0, 1.0, 1.0, 1.0, -24., -74., -8.])
# if we multiply our jacobian's transpose by our work vec of 1's,
# we get rev_check
rev_check = np.array([-35., -5., 9., -63., -3., 1., -6., 1.])
self._check_fwd(self.prob, fwd_check)
# to catch issues with constant subjacobians, repeatedly call linearize
for i in range(lincalls):
self.prob.model.run_linearize()
self._check_fwd(self.prob, fwd_check)
self._check_rev(self.prob, rev_check)
def _setup_model(self, jac_class, comp_jac_class, nested, lincalls):
self.prob = prob = Problem(model=Group())
if nested:
top = prob.model.add_subsystem('G1', Group())
else:
top = prob.model
indep = top.add_subsystem('indep', IndepVarComp())
indep.add_output('a', val=np.ones(3))
indep.add_output('b', val=np.ones(2))
top.add_subsystem('C1', MyExplicitComp(comp_jac_class))
top.add_subsystem('C2', MyExplicitComp2(comp_jac_class))
top.connect('indep.a', 'C1.x', src_indices=[2,0])
top.connect('indep.b', 'C1.y')
top.connect('indep.a', 'C2.w', src_indices=[0,2,1])
top.connect('C1.f', 'C2.z', src_indices=[1])
top.jacobian = jac_class()
top.nonlinear_solver = NewtonSolver()
top.nonlinear_solver.linear_solver = ScipyIterativeSolver(maxiter=100)
top.linear_solver = ScipyIterativeSolver(
maxiter=200, atol=1e-10, rtol=1e-10)
prob.set_solver_print(level=0)
prob.setup(check=False)
prob.run_model()
def _check_fwd(self, prob, check_vec):
d_inputs, d_outputs, d_residuals = prob.model.get_linear_vectors()
work = d_outputs._clone()
work.set_const(1.0)
# fwd apply_linear test
d_outputs.set_const(1.0)
prob.model.run_apply_linear(['linear'], 'fwd')
d_residuals.set_data(d_residuals.get_data() - check_vec)
self.assertAlmostEqual(d_residuals.get_norm(), 0)
# fwd solve_linear test
d_outputs.set_const(0.0)
d_residuals.set_data(check_vec)
prob.model.run_solve_linear(['linear'], 'fwd')
d_outputs -= work
self.assertAlmostEqual(d_outputs.get_norm(), 0, delta=1e-6)
def _check_rev(self, prob, check_vec):
d_inputs, d_outputs, d_residuals = prob.model.get_linear_vectors()
work = d_outputs._clone()
work.set_const(1.0)
# rev apply_linear test
d_residuals.set_const(1.0)
prob.model.run_apply_linear(['linear'], 'rev')
d_outputs.set_data(d_outputs.get_data() - check_vec)
self.assertAlmostEqual(d_outputs.get_norm(), 0)
# rev solve_linear test
d_residuals.set_const(0.0)
d_outputs.set_data(check_vec)
prob.model.run_solve_linear(['linear'], 'rev')
d_residuals -= work
self.assertAlmostEqual(d_residuals.get_norm(), 0, delta=1e-6)
dtypes = [
('int', 1),
('float', 2.1),
# ('complex', 3.2 + 1.1j), # TODO: enable when Vectors support complex entries.
]
shapes = [
('scalar', lambda x: x, (1, 1)),
('1D_array', lambda x: np.array([x + i for i in range(5)]), (5, 1)),
('2D_array', lambda x: np.array([[x + i + 2 * j for i in range(3)] for j in range(3)]),
(3, 3))
]
@parameterized.expand(itertools.product(dtypes, shapes), testcase_func_name=
lambda f, n, p: '_'.join(['test_jacobian_set_item', p.args[0][0], p.args[1][0]]))
def test_jacobian_set_item(self, dtypes, shapes):
shape, constructor, expected_shape = shapes
dtype, value = dtypes
prob = Problem(model=Group())
comp = ExplicitSetItemComp(dtype, value, shape, constructor)
prob.model.add_subsystem('C1', comp)
prob.setup(check=False)
prob.set_solver_print(level=0)
prob.run_model()
prob.model.run_apply_nonlinear()
prob.model.run_linearize()
expected = constructor(value)
with prob.model._subsystems_allprocs[0].jacobian_context() as J:
jac_out = J['out', 'in'] * -1
self.assertEqual(len(jac_out.shape), 2)
expected_dtype = np.promote_types(dtype, float)
self.assertEqual(jac_out.dtype, expected_dtype)
assert_rel_error(self, jac_out, np.atleast_2d(expected).reshape(expected_shape), 1e-15)
def test_component_assembled_jac(self):
prob = Problem()
model = prob.model = Group()
model.add_subsystem('px', IndepVarComp('x', 1.0), promotes=['x'])
model.add_subsystem('pz', IndepVarComp('z', np.array([5.0, 2.0])), promotes=['z'])
model.add_subsystem('d1', SellarDis1withDerivatives(), promotes=['x', 'z', 'y1', 'y2'])
model.add_subsystem('d2', SellarDis2withDerivatives(), promotes=['z', 'y1', 'y2'])
model.add_subsystem('obj_cmp', ExecComp('obj = x**2 + z[1] + y1 + exp(-y2)',
z=np.array([0.0, 0.0]), x=0.0),
promotes=['obj', 'x', 'z', 'y1', 'y2'])
model.add_subsystem('con_cmp1', ExecComp('con1 = 3.16 - y1'), promotes=['con1', 'y1'])
model.add_subsystem('con_cmp2', ExecComp('con2 = y2 - 24.0'), promotes=['con2', 'y2'])
model.nonlinear_solver = NewtonSolver()
model.linear_solver = ScipyIterativeSolver()
d1 = prob.model.get_subsystem('d1')
d1.jacobian = DenseJacobian()
prob.set_solver_print(level=0)
prob.setup(check=False)
prob.run_model()
assert_rel_error(self, prob['y1'], 25.58830273, .00001)
assert_rel_error(self, prob['y2'], 12.05848819, .00001)
def test_assembled_jac_bad_key(self):
# this test fails if AssembledJacobian._update sets in_start with 'output' instead of 'input'
prob = Problem()
prob.model = Group()
prob.model.add_subsystem('indep', IndepVarComp('x', 1.0))
prob.model.add_subsystem('C1', ExecComp('c=a*2.0+b'))
c2 = prob.model.add_subsystem('C2', ExecComp('d=a*2.0+b+c'))
c3 = prob.model.add_subsystem('C3', ExecComp('ee=a*2.0'))
prob.model.nonlinear_solver = NewtonSolver()
c3.jacobian = DenseJacobian()
prob.model.connect('indep.x', 'C1.a')
prob.model.connect('indep.x', 'C2.a')
prob.model.connect('C1.c', 'C2.b')
prob.model.connect('C2.d', 'C3.a')
prob.set_solver_print(level=0)
prob.setup(check=False)
prob.run_model()
assert_rel_error(self, prob['C3.ee'], 8.0, 0000.1)
def test_jacobian_changed_group(self):
prob = Problem()
model = prob.model = Group()
model.add_subsystem('px', IndepVarComp('x', 1.0), promotes=['x'])
model.add_subsystem('pz', IndepVarComp('z', np.array([5.0, 2.0])), promotes=['z'])
model.add_subsystem('d1', SellarDis1withDerivatives(), promotes=['x', 'z', 'y1', 'y2'])
model.add_subsystem('d2', SellarDis2withDerivatives(), promotes=['z', 'y1', 'y2'])
model.add_subsystem('obj_cmp', ExecComp('obj = x**2 + z[1] + y1 + exp(-y2)',
z=np.array([0.0, 0.0]), x=0.0),
promotes=['obj', 'x', 'z', 'y1', 'y2'])
model.add_subsystem('con_cmp1', ExecComp('con1 = 3.16 - y1'), promotes=['con1', 'y1'])
model.add_subsystem('con_cmp2', ExecComp('con2 = y2 - 24.0'), promotes=['con2', 'y2'])
model.nonlinear_solver = NewtonSolver()
model.linear_solver = ScipyIterativeSolver()
prob.model.jacobian = DenseJacobian()
prob.setup(check=False)
prob.model.jacobian = DenseJacobian()
msg = ": jacobian has changed and setup was not called."
with assertRaisesRegex(self, Exception, msg):
prob.run_model()
def test_jacobian_changed_component(self):
prob = Problem()
model = prob.model = Group()
model.add_subsystem('px', IndepVarComp('x', 1.0), promotes=['x'])
model.add_subsystem('pz', IndepVarComp('z', np.array([5.0, 2.0])), promotes=['z'])
model.add_subsystem('d1', SellarDis1withDerivatives(), promotes=['x', 'z', 'y1', 'y2'])
model.add_subsystem('d2', SellarDis2withDerivatives(), promotes=['z', 'y1', 'y2'])
model.add_subsystem('obj_cmp', ExecComp('obj = x**2 + z[1] + y1 + exp(-y2)',
z=np.array([0.0, 0.0]), x=0.0),
promotes=['obj', 'x', 'z', 'y1', 'y2'])
model.add_subsystem('con_cmp1', ExecComp('con1 = 3.16 - y1'), promotes=['con1', 'y1'])
model.add_subsystem('con_cmp2', ExecComp('con2 = y2 - 24.0'), promotes=['con2', 'y2'])
model.nonlinear_solver = NewtonSolver()
model.linear_solver = ScipyIterativeSolver()
prob.setup(check=False)
d1 = prob.model.get_subsystem('d1')
d1.jacobian = DenseJacobian()
msg = "d1: jacobian has changed and setup was not called."
with assertRaisesRegex(self, Exception, msg):
prob.run_model()
def test_assembled_jacobian_submat_indexing(self):
prob = Problem()
indeps = prob.model.add_subsystem('indeps', IndepVarComp())
indeps.add_output('x', 1.0)
indeps.add_output('y', 5.0)
indeps.add_output('z', 9.0)
G1 = prob.model.add_subsystem('G1', Group())
G1.add_subsystem('C1', ExecComp('y=2.0*x*x'))
G1.add_subsystem('C2', ExecComp('y=3.0*x*x'))
prob.model.nonlinear_solver = NewtonSolver()
G1.jacobian = DenseJacobian()
# before the fix, we got bad offsets into the _ext_mtx matrix.
# to get entries in _ext_mtx, there must be at least one connection
# to an input in the system that owns the AssembledJacobian, from
# a source that is outside of that system. In this case, the 'indeps'
# system is outside of the 'G1' group which owns the AssembledJacobian.
prob.model.connect('indeps.y', 'G1.C1.x')
prob.model.connect('indeps.z', 'G1.C2.x')
prob.setup(check=False)
prob.run_model()
assert_rel_error(self, prob['G1.C1.y'], 50.0)
assert_rel_error(self, prob['G1.C2.y'], 243.0)
def test_declare_partial_reference(self):
# Test for a bug where declare partial is given an array reference
# that compute also uses and could get corrupted
class Comp(ExplicitComponent):
def setup(self):
self.add_input('x', val=1.0, shape=2)
self.add_output('y', val=1.0, shape=2)
self.val = 2 * np.ones(2)
self.rows = np.arange(2)
self.cols = np.arange(2)
self.declare_partials(
'y', 'x', val=self.val, rows=self.rows, cols=self.cols)
def compute(self, inputs, outputs):
outputs['y'][:] = 0.
np.add.at(
outputs['y'], self.rows,
self.val * inputs['x'][self.cols])
prob = Problem(model=Comp())
prob.setup()
prob.run_model()
assert_rel_error(self, prob['y'], 2 * np.ones(2))
def test_sparse_jac_with_subsolver_error(self):
prob = Problem()
indeps = prob.model.add_subsystem('indeps', IndepVarComp('x', 1.0))
G1 = prob.model.add_subsystem('G1', Group())
G1.add_subsystem('C1', ExecComp('y=2.0*x'))
G1.add_subsystem('C2', ExecComp('y=3.0*x'))
G1.nonlinear_solver = NewtonSolver()
prob.model.jacobian = CSRJacobian()
prob.model.connect('indeps.x', 'G1.C1.x')
prob.model.connect('indeps.x', 'G1.C2.x')
with self.assertRaises(Exception) as context:
prob.setup(check=False)
self.assertEqual(str(context.exception),
"System 'G1' has a solver of type 'NewtonSolver'but a sparse "
"AssembledJacobian has been set in a higher level system.")
def test_assembled_jacobian_unsupported_cases(self):
class ParaboloidApply(ImplicitComponent):
def setup(self):
self.add_input('x', val=0.0)
self.add_input('y', val=0.0)
self.add_output('f_xy', val=0.0)
def linearize(self, inputs, outputs, jacobian):
return
def apply_linear(self, inputs, outputs, d_inputs, d_outputs, d_residuals,
mode):
d_residuals['x'] += (np.exp(outputs['x']) - 2*inputs['a']**2 * outputs['x'])*d_outputs['x']
d_residuals['x'] += (-2 * inputs['a'] * outputs['x']**2)*d_inputs['a']
# One level deep
prob = Problem()
model = prob.model = Group()
model.add_subsystem('p1', IndepVarComp('x', val=1.0))
model.add_subsystem('p2', IndepVarComp('y', val=1.0))
model.add_subsystem('comp', ParaboloidApply())
model.connect('p1.x', 'comp.x')
model.connect('p2.y', 'comp.y')
model.jacobian = DenseJacobian()
msg = "AssembledJacobian not supported if any subcomponent is matrix-free."
with assertRaisesRegex(self, Exception, msg):
prob.setup()
# Nested
prob = Problem()
model = prob.model = Group()
sub = model.add_subsystem('sub', Group())
model.add_subsystem('p1', IndepVarComp('x', val=1.0))
model.add_subsystem('p2', IndepVarComp('y', val=1.0))
sub.add_subsystem('comp', ParaboloidApply())
model.connect('p1.x', 'sub.comp.x')
model.connect('p2.y', 'sub.comp.y')
model.jacobian = DenseJacobian()
msg = "AssembledJacobian not supported if any subcomponent is matrix-free."
with assertRaisesRegex(self, Exception, msg):
prob.setup()
# Try a component that is derived from a matrix-free one
class FurtherDerived(ParaboloidApply):
def do_nothing(self):
pass
prob = Problem()
model = prob.model = Group()
model.add_subsystem('p1', IndepVarComp('x', val=1.0))
model.add_subsystem('p2', IndepVarComp('y', val=1.0))
model.add_subsystem('comp', FurtherDerived())
model.connect('p1.x', 'comp.x')
model.connect('p2.y', 'comp.y')
model.jacobian = DenseJacobian()
msg = "AssembledJacobian not supported if any subcomponent is matrix-free."
with assertRaisesRegex(self, Exception, msg):
prob.setup()
# Make sure regular comps don't give an error.
prob = Problem()
model = prob.model = Group()
model.add_subsystem('p1', IndepVarComp('x', val=1.0))
model.add_subsystem('p2', IndepVarComp('y', val=1.0))
model.add_subsystem('comp', Paraboloid())
model.connect('p1.x', 'comp.x')
model.connect('p2.y', 'comp.y')
model.jacobian = DenseJacobian()
prob.setup()
class ParaboloidJacVec(Paraboloid):
def linearize(self, inputs, outputs, jacobian):
return
def compute_jacvec_product(self, inputs, outputs, d_inputs, d_outputs, d_residuals,
mode):
d_residuals['x'] += (np.exp(outputs['x']) - 2*inputs['a']**2 * outputs['x'])*d_outputs['x']
d_residuals['x'] += (-2 * inputs['a'] * outputs['x']**2)*d_inputs['a']
# One level deep
prob = Problem()
model = prob.model = Group()
model.add_subsystem('p1', IndepVarComp('x', val=1.0))
model.add_subsystem('p2', IndepVarComp('y', val=1.0))
model.add_subsystem('comp', ParaboloidJacVec())
model.connect('p1.x', 'comp.x')
model.connect('p2.y', 'comp.y')
model.jacobian = DenseJacobian()
msg = "AssembledJacobian not supported if any subcomponent is matrix-free."
with assertRaisesRegex(self, Exception, msg):
prob.setup()
if __name__ == '__main__':
unittest.main()