OpenMDAO
OpenMDAO copied to clipboard
Inputs report generation has reshape error for test_distribcomp.py:TestGroupMPI.test_promote_distrib test
Description
The test_distribcomp.py:TestGroupMPI.test_promote_distrib test passes because when running testflo, reports are not generated.
But when the code from that test is run as a script outside of testflo, reports are generated and you get this error.
File ~/Documents/OpenMDAO/dev/I3060-mod-reports/openmdao/visualization/inputs_report/inputs_report.py:160, in _run_inputs_report(prob, report_filename)
157 def _run_inputs_report(prob, report_filename='inputs.html'):
159 path = str(pathlib.Path(prob.get_reports_dir()).joinpath(report_filename))
--> 160 inputs_report(prob, display=False, outfile=path,
161 title=f'Inputs Report for {prob._name}', tablefmt='tabulator')
File ~/Documents/OpenMDAO/dev/I3060-mod-reports/openmdao/visualization/inputs_report/inputs_report.py:106, in inputs_report(prob, outfile, display, precision, title, tablefmt)
104 src = connections[target]
105 sprom = model._var_allprocs_abs2prom['output'][src]
--> 106 val = model.get_val(target, get_remote=True, from_src=not src.startswith('_auto_ivc.'))
107 smeta = model._var_allprocs_abs2meta['output'][src]
108 src_is_ivc = 'openmdao:indep_var' in smeta['tags']
File ~/Documents/OpenMDAO/dev/I3060-mod-reports/openmdao/core/system.py:5145, in System.get_val(self, name, units, indices, get_remote, rank, vec_name, kind, flat, from_src)
5142 else:
5143 # src is outside of this system so get the value from the model
5144 caller = self._problem_meta['model_ref']()
-> 5145 return caller._get_input_from_src(name, abs_names, conns, units=simp_units,
5146 indices=indices, get_remote=get_remote, rank=rank,
5147 vec_name='nonlinear', flat=flat, scope_sys=self)
5148 else:
5149 val = self._abs_get_val(abs_names[0], get_remote, rank, vec_name, kind, flat)
File ~/Documents/OpenMDAO/dev/I3060-mod-reports/openmdao/core/system.py:5628, in System._get_input_from_src(self, name, abs_ins, conns, units, indices, get_remote, rank, vec_name, flat, scope_sys)
5626 val.shape = abs2meta_all_ins[abs_name]['global_shape']
5627 elif not flat and val.size > 0 and vshape is not None:
-> 5628 val.shape = vshape
5629 elif vshape is not None:
5630 val = val.reshape(vshape)
ValueError: cannot reshape array of size 3 into shape (2,)
Example
import openmdao.api as om
import numpy as np
from openmdao.utils.mpi import MPI
class MyComp(om.ExplicitComponent):
def initialize(self):
self.options.declare('size', types=int, default=1,
desc="Size of input vector x.")
def setup(self):
self.add_input('x', np.ones(self.options['size']))
self.add_output('y', 1.0)
def compute(self, inputs, outputs):
outputs['y'] = np.sum(inputs['x'])*2.0
p = om.Problem()
p.model.add_subsystem('indep', om.IndepVarComp('x', np.arange(5, dtype=float)),
promotes_outputs=['x'])
# decide what parts of the array we want based on our rank
if MPI.COMM_WORLD.rank == 0:
idxs = [0, 1, 2]
else:
# use [3, -1] here rather than [3, 4] just to show that we
# can use negative indices.
idxs = [3, -1]
p.model.add_subsystem('C1', MyComp(size=len(idxs)))
p.model.promotes('C1', inputs=['x'], src_indices=idxs)
p.setup()
p.set_val('x', np.arange(5, dtype=float))
p.run_model()
OpenMDAO Version
3.29.1-dev
Relevant environment information
No response