Skip to content

Fixed an MPhys issue with setting scalars with Numpy 2.4#401

Open
sabakhshi wants to merge 2 commits intomainfrom
mphysNumpyFix
Open

Fixed an MPhys issue with setting scalars with Numpy 2.4#401
sabakhshi wants to merge 2 commits intomainfrom
mphysNumpyFix

Conversation

@sabakhshi
Copy link
Copy Markdown
Contributor

Purpose

The Mphys wrapper was not working with Numpy versions >2.4.
This is because as of Numpy 2.4 1D vectors of length 1 can no longer be treated as scalar data types.
This issue manifested when ADflow tried to print the alpha value set by OpenMDAO.
We now check if we are setting a 1D array of len(1) and explicitly index the first entry to get a scalar
data type.

Expected time until merged

1-2 days

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (non-backwards-compatible fix or feature)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Documentation update
  • Maintenance update
  • Other (please describe)

Testing

No new test required since we don't test on Numpy 2.4 yet.
This is just getting ahead of the issue.
The fix may no longer be needed if OpenMDAO changes something upstream
to account for this.

Checklist

  • I have run ruff check and ruff format to make sure the Python code adheres to PEP-8 and is consistently formatted
  • I have formatted the Fortran code with fprettify or C/C++ code with clang-format as applicable
  • I have run unit and regression tests which pass locally with my changes
  • I have added new tests that prove my fix is effective or that my feature works
  • I have added necessary documentation

@sabakhshi sabakhshi requested a review from a team as a code owner April 10, 2026 00:21
@sabakhshi sabakhshi requested review from ArshSaja and anilyil April 10, 2026 00:21
Updated comment to clarify purpose of code change.
Copy link
Copy Markdown
Member

@A-CGray A-CGray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this @sabakhshi

@A-CGray A-CGray requested review from sanjan98 and removed request for ArshSaja and anilyil April 10, 2026 17:21
@A-CGray
Copy link
Copy Markdown
Member

A-CGray commented Apr 10, 2026

@sanjan98 you're running ADflow through MPhys at the moment right? Could you test out this fix on your case using numpy 2.3 and 2.4?

@sanjan98
Copy link
Copy Markdown
Contributor

@A-CGray I can test it tomorrow and approve

@sanjan98
Copy link
Copy Markdown
Contributor

@sabakhshi @A-CGray
Going through this PR, isn't it better to fix the root cause at the OpenMDAO level? Or add numpy2.4 to the CI testing matrix if we dont want to depend on OpenMDAO? I dont understand how I can isolate testing for just this fix with numpy 2.4. Let me know what you guys think.

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.

3 participants