Skip to content

Fix design vector size in the CG, BFGS and POWELL optimizers - #3064

Open
SahilKumar965 wants to merge 1 commit into
su2code:developfrom
SahilKumar965:fix/scipy-optimizer-dv-size
Open

SahilKumar965 wants to merge 1 commit into
su2code:developfrom
SahilKumar965:fix/scipy-optimizer-dv-size

Conversation

@SahilKumar965

Copy link
Copy Markdown

Proposed Changes

scipy_cg, scipy_bfgs and scipy_powell use n_dv = len(DEFINITION_DV["KIND"]), so they count one design variable per entry. But some entries have more than one value, e.g. an FFD_CONTROL_POINT_2D with direction (0, 0) has size 2 and an FFD_CONTROL_POINT with (0, 0, 0) has size 3. In that case these optimizers pass a design vector that is too short and unpack_dvs stops with "unexpected design vector length". The x0 prescaling has the same problem.

SLSQP already does this right with sum(SIZE), so I changed the other three the same way and prescale x0 value by value with the scale of its entry.

I tested it with three DV entries of size 1, 2 and 3 (scales 1, 0.5, 2) and checked the vector each optimizer passes at the first evaluation:

          develop                                     this PR
SLSQP     ok                                          ok
CG        AssertionError: unexpected design vector    ok
BFGS      AssertionError: unexpected design vector    ok
POWELL    AssertionError: unexpected design vector    ok

When all entries have size 1 the result is the same as before.

Related Work

No issue for this one. Found it while looking at #3054 / #3056.

PR Checklist

  • I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings (try with --warnlevel=3 when using meson).
  • My contribution is commented and consistent with SU2 style (https://su2code.github.io/docs_v7/Style-Guide/).
  • I used the pre-commit hook to prevent dirty commits and used pre-commit run --all to format old commits.
  • I have added a test case that demonstrates my contribution, if necessary.
  • I have updated appropriate documentation (Tutorials, Docs Page, config_template.cpp), if necessary.

scipy_cg, scipy_bfgs and scipy_powell counted one design variable per
DEFINITION_DV entry and prescaled x0 per entry. Entries can hold more than
one value (an FFD_CONTROL_POINT_2D with direction (0, 0) has size 2, an
FFD_CONTROL_POINT with (0, 0, 0) has size 3), so with those the optimizer
passed a too short design vector and unpack_dvs stopped with "unexpected
design vector length".

Count the design variables with sum(SIZE) like scipy_slsqp and
Config.unpack_dvs, and prescale each value with the scale of its entry.
Nothing changes when all entries have size 1.

This branch has not been deployed

No deployments
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.

1 participant