Skip to content

Address a numpy deprecation warning about assigning a vector to a single vector index.#817

Merged
jkirk5 merged 1 commit intoOpenMDAO:mainfrom
Kenneth-T-Moore:cleanup1
Jul 18, 2025
Merged

Address a numpy deprecation warning about assigning a vector to a single vector index.#817
jkirk5 merged 1 commit intoOpenMDAO:mainfrom
Kenneth-T-Moore:cleanup1

Conversation

@Kenneth-T-Moore
Copy link
Copy Markdown
Member

Summary

Address a numpy deprecation warning about assigning a vector to a single vector index.

Related Issues

  • Resolves #

Backwards incompatibilities

None

New Dependencies

None

@jkirk5
Copy link
Copy Markdown
Contributor

jkirk5 commented Jul 15, 2025

Do we know why those variables are vectors when they shouldn't be? I'm fine with this fix but we might run into this issue in other places if we don't address the root cause

@Kenneth-T-Moore
Copy link
Copy Markdown
Member Author

Kenneth-T-Moore commented Jul 16, 2025

Do we know why those variables are vectors when they shouldn't be? I'm fine with this fix but we might run into this issue in other places if we don't address the root cause

It seems to mainly be openmdao behavior right now that everything you get from inputs is a vector, no matter how you declare it.

    import numpy as np
    
    import openmdao.api as om
    
    class MyComp(om.ExplicitComponent):
    
        def setup(self):
    
            self.add_input('x1', val = 1.0)
            self.add_input('x2', val = np.array((1, )))
            self.add_input('x3', shape=1)
            self.add_input('x4', shape=(1, ))
            self.add_input('x5', shape=0)
            self.add_output('zzz')
    
        def compute(self, inputs, outputs, discrete_inputs=None, discrete_outputs=None):
            
            print('x1', inputs['x1'])
            print('x2', inputs['x2'])
            print('x3', inputs['x3'])
            print('x4', inputs['x4'])
            print('x5', inputs['x5'])
    
    prob = om.Problem()
    model = prob.model
    model.add_subsystem('comp', MyComp())
    prob.setup()
    
    prob.run_model()
    print('done')

/Users/ktmoore1/Work/OpenMDAO/OpenMDAO/openmdao/visualization/n2_viewer/n2_viewer.py:114: OpenMDAOWarning:All-NaN slice encountered
x1 [1.]
x2 [1.]
x3 [1.]
x4 [1.]
x5 []
done

@jkirk5 jkirk5 added this pull request to the merge queue Jul 18, 2025
Merged via the queue into OpenMDAO:main with commit 5363e88 Jul 18, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants