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

Various small changes #241

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Various small changes #241

wants to merge 8 commits into from

Conversation

A-CGray
Copy link
Member

@A-CGray A-CGray commented Apr 5, 2024

Purpose

  • Changes the hard-coded lower bound for the triangulated surface constraint from a dummy value of -1e10 to None which is the correct way to represent that there is no lower bound.
  • Converts the SVD vectors computed when using composite DVs from a numpy matrix to a numpy array. Using a matrix causes the design variable values to end up as a 2D array which causes pyoptsparse to fail.
  • Fixes a check in addRefAxis that is supposed to evaluate to false is x/y/zFraction is None, but currently also evaluates to False is the values are zero.

Expected time until merged

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

Checklist

  • I have run flake8 and black 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

@A-CGray A-CGray requested a review from a team as a code owner April 5, 2024 15:07
@A-CGray A-CGray requested review from anilyil and sseraj April 5, 2024 15:07
Copy link

codecov bot commented Apr 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.46%. Comparing base (44a25b3) to head (9ebf1ed).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #241   +/-   ##
=======================================
  Coverage   65.46%   65.46%           
=======================================
  Files          47       47           
  Lines       12266    12266           
=======================================
  Hits         8030     8030           
  Misses       4236     4236           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -1520,6 +1520,7 @@ def addCompositeDV(self, dvName, ptSetName=None, u=None, scale=None, prependName
self.computeTotalJacobian(ptSetName)
J_full = self.JT[ptSetName].todense() # this is in CSR format but we convert it to a dense matrix
u, s, _ = np.linalg.svd(J_full, full_matrices=False)
u = np.array(u)
Copy link
Contributor

Choose a reason for hiding this comment

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

The other two changes look good. Can you explain this one a bit more? I thought u was supposed to be an N_DV by N_DV matrix

Copy link
Member Author

@A-CGray A-CGray Apr 5, 2024

Choose a reason for hiding this comment

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

Yeah it is, the issue is that it's an N_DV by N_DV np.matrix not np.array. Because of this, values ends up being a (1,N_DV) np.matrix and that breaks pyoptsparse. Calling flatten on a matrix doesn't do anything because the matrix type always wants to remain 2d.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know why the return is an np.matrix because the docs suggest that the return type should be an array

Copy link
Member Author

Choose a reason for hiding this comment

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

@ArshSaja , I think you're the only person other than @ewu63 who's used the composite DVs, did you ever run into this?

Copy link
Contributor

Choose a reason for hiding this comment

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

@A-CGray This is expected as the input J_full is of a dense matrix type, thus the output will be of a matrix type. The docs you linked do mention this (right before the examples) ,

If a is a matrix object (as opposed to an ndarray), then so are all the return values.

We should probably just change todense() to toarray(), resulting in a dense array as opposed to dense matrix. I dont think there should be any, but make sure that there are no special matrix operations like * (matmul) elsewhere that might be affected.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, good catch, shows you how observant I am. I agree, will change to toarray and remove this conversion

Copy link
Contributor

Choose a reason for hiding this comment

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

@ArshSaja confirmed that he also had to fix this to use composite DVs, so it seems like this was broken from the start

sseraj
sseraj previously approved these changes Apr 5, 2024
@A-CGray A-CGray requested review from ArshSaja and removed request for anilyil April 5, 2024 17:10
@@ -1520,6 +1520,7 @@ def addCompositeDV(self, dvName, ptSetName=None, u=None, scale=None, prependName
self.computeTotalJacobian(ptSetName)
J_full = self.JT[ptSetName].todense() # this is in CSR format but we convert it to a dense matrix
u, s, _ = np.linalg.svd(J_full, full_matrices=False)
u = np.array(u)
Copy link
Contributor

Choose a reason for hiding this comment

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

@A-CGray This is expected as the input J_full is of a dense matrix type, thus the output will be of a matrix type. The docs you linked do mention this (right before the examples) ,

If a is a matrix object (as opposed to an ndarray), then so are all the return values.

We should probably just change todense() to toarray(), resulting in a dense array as opposed to dense matrix. I dont think there should be any, but make sure that there are no special matrix operations like * (matmul) elsewhere that might be affected.

pygeo/parameterization/DVGeo.py Show resolved Hide resolved
@A-CGray A-CGray requested review from eirikurj and sseraj April 29, 2024 16:53
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.

None yet

3 participants