-
Notifications
You must be signed in to change notification settings - Fork 118
Support calling addObjective on subset of procs
#465
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #465 +/- ##
==========================================
+ Coverage 86.27% 86.72% +0.44%
==========================================
Files 24 24
Lines 3432 3435 +3
==========================================
+ Hits 2961 2979 +18
+ Misses 471 456 -15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I don't believe this is a bug, we've never supported distributed objectives before since we've never needed to, only constraints/DVs. In any case, I think this was a pretty non-documented feature and this change LGTM.
| """ | ||
| if comm is None: | ||
| raise unittest.SkipTest("mpi4py not available, skipping test.") | ||
| if comm.size != self.N_PROCS: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When does this condition happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have mpi4py installed but you run the test through something other than testflo (e.g unittest or pytest)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this sort of thing do not need to be handled, we explicitly say in the docs to run tests with testflo so I don't think we need to support running raw unittest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but whenever I want to interactively debug a failing test I have to run them with unittest and I'd rather not have to comment this test out every time I want to do that. I guess I could also try changing how the test works so it won't fail if run in serial, but it seemed easier to just do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll approve, but I don't think we should do things like this in general, because we have tons of MPI-based tests (here or in other repos) and we should not have to add these checks for each one. Maybe in the longer term we should move away from testflo-based testing to something more standard like pytest, it may not be sufficient for packages like ADflow but the parallel portions of pyOptSparse are minimal and easy to test.
Right, I don't think what I've implemented here actually supports objectives that are distributed at runtime (as in it still expects the same objective value to be returned on all procs when it calls |
No it does not, that functionality lives in multipoint. I've long thought that multipoint could be moved into pyOptSparse or at least seen as a "plugin" for this repo, but that's probably a long-term discussion. My original point was just that we had never had the need to run an allreduce on the objective, since typically we just have one objective function which is available on all procs. |
addObjective on subset of procs
|
I would be OK with a patch release after this PR is merged, feel free to bump the version. Alternatively we can wait for #459 |
Purpose
Adds a
_finalizeObjectivesmethod that reduces any added objectives across all procs so that all procs have the same objectives. This is already done for design variables and constraints.Expected time until merged
Type of change
Testing
I added a small unit test that checks that all procs have the same objectives, constraints and design variables after
finalizeis called.Checklist
ruff checkandruff formatto make sure the Python code adheres to PEP-8 and is consistently formattedfprettifyor C/C++ code withclang-formatas applicable