Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Driver desvar debug_print should print unflattened value. #927

Merged
merged 3 commits into from May 14, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions openmdao/core/driver.py
Expand Up @@ -1051,6 +1051,12 @@ def _pre_run_model_debug_print(self):
if not MPI or MPI.COMM_WORLD.rank == 0:
print("Design Vars")
if desvar_vals:

# Print desvars in non_flattened state.
meta = self._problem.model._var_allprocs_abs2meta
for name in desvar_vals:
shape = meta[name]['shape']
desvar_vals[name] = desvar_vals[name].reshape(shape)
pprint.pprint(desvar_vals)
else:
print("None")
Expand Down
33 changes: 33 additions & 0 deletions openmdao/core/tests/test_driver.py
Expand Up @@ -383,5 +383,38 @@ def test_debug_print_response_physical(self):
self.assertEqual(output[3], "{'con.c': array([ 1.])}")
self.assertEqual(output[6], "{'comp.f_xy': array([ 7622.])}")

def test_debug_desvar_shape(self):
# Desvar should always be printed un-flattened.

prob = Problem()
model = prob.model

model.add_subsystem('p', IndepVarComp('x', val=np.array([[1.0, 3, 4], [7, 2, 5]])))

model.add_design_var('p.x', np.array([[1.0, 3, 4], [7, 2, 5]]))
prob.driver.options['debug_print'] = ['desvars']

prob.setup()

stdout = sys.stdout
strout = StringIO()
sys.stdout = strout

try:
# formatting has changed in numpy 1.14 and beyond.
if LooseVersion(np.__version__) >= LooseVersion("1.14"):
with printoptions(precision=2, legacy="1.13"):
prob.run_driver()
else:
with printoptions(precision=2):
prob.run_driver()
finally:
sys.stdout = stdout

output = strout.getvalue().split('\n')

self.assertEqual(output[3], "{'p.x': array([[ 1., 3., 4.],")
self.assertEqual(output[4], ' [ 7., 2., 5.]])}')

if __name__ == "__main__":
unittest.main()