fast-aircraft-design / FAST-OAD

FAST-OAD: An open source framework for rapid Overall Aircraft Design
GNU General Public License v3.0
47 stars 25 forks source link

Run system can fail when using shape_by_conn and copy shape in some inputs #432

Closed florentLutz closed 1 year ago

florentLutz commented 2 years ago

Describe the bug There can be an issue with the run_system function when giving in argument a group which contains components that have inputs which copy the shape of a different input

To Reproduce The following code provides with a simple example of how to make the error happen : test_copy_shape.zip

Expected behavior The expected behaviour would be that there are no None shape which would prevent OpenMDAO from crashing.

Error message

FAILED        [100%]
test_copy_shape.py:132 (test_shape_by_conn_fast_oad_run_system)
def test_shape_by_conn_fast_oad_run_system():

        ivc = om.IndepVarComp()
        ivc.add_output("data:foo", val=np.array([1.0, 2.0, 3.0]))
        ivc.add_output("data:bar", val=np.array([4.0, 5.0, 6.0]))
        ivc.add_output("baz", val=np.array([0.1, 0.2, 0.3]))

>       p = run_system(WingLoads(), ivc)

test_copy_shape.py:140: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\..\Anaconda3\envs\FAST_OAD_bug_replication\lib\site-packages\fastoad\_utils\testing.py:40: in run_system
    problem.setup(mode=setup_mode)
..\..\Anaconda3\envs\FAST_OAD_bug_replication\lib\site-packages\openmdao\core\problem.py:971: in setup
    model._setup(model_comm, mode, self._metadata)
..\..\Anaconda3\envs\FAST_OAD_bug_replication\lib\site-packages\openmdao\core\system.py:856: in _setup
    self._setup_var_sizes()
..\..\Anaconda3\envs\FAST_OAD_bug_replication\lib\site-packages\openmdao\core\group.py:1366: in _setup_var_sizes
    subsys._setup_var_sizes()
..\..\Anaconda3\envs\FAST_OAD_bug_replication\lib\site-packages\openmdao\core\group.py:1366: in _setup_var_sizes
    subsys._setup_var_sizes()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <test_copy_shape.StructuralLoads object at 0x0000013C45983B50>

    def _setup_var_sizes(self):
        """
        Compute the arrays of variable sizes for all variables/procs on this system.
        """
        iproc = self.comm.rank
        abs2idx = self._var_allprocs_abs2idx = {}

        for io in ('input', 'output'):
            sizes = self._var_sizes[io] = np.zeros((self.comm.size, len(self._var_rel_names[io])),
                                                   dtype=INT_DTYPE)

            for i, (name, metadata) in enumerate(self._var_allprocs_abs2meta[io].items()):
>               sizes[iproc, i] = metadata['size']
E               TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

..\..\Anaconda3\envs\FAST_OAD_bug_replication\lib\site-packages\openmdao\core\component.py:298: TypeError

Environment

Additional context Weirdly enough replacing baz with data:baz or removing the data in front of foo and bar will solve the issue on this test case

florentLutz commented 1 year ago

The problem comes from the fact that in some components of the code variable foocopies the shape of bar, but not in another one, even if foo is not used. This, however, only happens when using the run_system so it is bound to unit_tests. A simple workaround is to declare foo as an input with a proper copy shape but not use it.