From 6119f599be5d313642164e7b57ae5833e0d3b94a Mon Sep 17 00:00:00 2001 From: SahilKumar965 <183753734+SahilKumar965@users.noreply.github.com> Date: Fri, 4 Dec 2026 14:12:00 +0530 Subject: [PATCH] Fix the number of design variables in the CG, BFGS and POWELL optimizers 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. --- SU2_PY/SU2/opt/scipy_tools.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/SU2_PY/SU2/opt/scipy_tools.py b/SU2_PY/SU2/opt/scipy_tools.py index 5bc6247ddcfe..b846bb9ac5ec 100644 --- a/SU2_PY/SU2/opt/scipy_tools.py +++ b/SU2_PY/SU2/opt/scipy_tools.py @@ -187,7 +187,8 @@ def scipy_cg(project, x0=None, xb=None, its=100, accu=1e-10, grads=True): fprime = obj_df # number of design variables - n_dv = len(project.config["DEFINITION_DV"]["KIND"]) + dv_size = project.config["DEFINITION_DV"]["SIZE"] + n_dv = sum(dv_size) project.n_dv = n_dv # Initial guess @@ -196,7 +197,8 @@ def scipy_cg(project, x0=None, xb=None, its=100, accu=1e-10, grads=True): # prescale x0 dv_scales = project.config["DEFINITION_DV"]["SCALE"] - x0 = [x0[i] / dv_scl for i, dv_scl in enumerate(dv_scales)] + x0_scales = [scl for scl, size in zip(dv_scales, dv_size) for _ in range(size)] + x0 = [x / scl for x, scl in zip(x0, x0_scales)] # scale accuracy obj = project.config["OPT_OBJECTIVE"] @@ -279,7 +281,8 @@ def scipy_bfgs(project, x0=None, xb=None, its=100, accu=1e-10, grads=True): fprime = obj_df # number of design variables - n_dv = len(project.config["DEFINITION_DV"]["KIND"]) + dv_size = project.config["DEFINITION_DV"]["SIZE"] + n_dv = sum(dv_size) project.n_dv = n_dv # Initial guess @@ -288,7 +291,8 @@ def scipy_bfgs(project, x0=None, xb=None, its=100, accu=1e-10, grads=True): # prescale x0 dv_scales = project.config["DEFINITION_DV"]["SCALE"] - x0 = [x0[i] / dv_scl for i, dv_scl in enumerate(dv_scales)] + x0_scales = [scl for scl, size in zip(dv_scales, dv_size) for _ in range(size)] + x0 = [x / scl for x, scl in zip(x0, x0_scales)] # scale accuracy obj = project.config["OPT_OBJECTIVE"] @@ -358,7 +362,8 @@ def scipy_powell(project, x0=None, xb=None, its=100, accu=1e-10, grads=False): func = obj_f # number of design variables - n_dv = len(project.config["DEFINITION_DV"]["KIND"]) + dv_size = project.config["DEFINITION_DV"]["SIZE"] + n_dv = sum(dv_size) project.n_dv = n_dv # Initial guess @@ -367,7 +372,8 @@ def scipy_powell(project, x0=None, xb=None, its=100, accu=1e-10, grads=False): # prescale x0 dv_scales = project.config["DEFINITION_DV"]["SCALE"] - x0 = [x0[i] / dv_scl for i, dv_scl in enumerate(dv_scales)] + x0_scales = [scl for scl, size in zip(dv_scales, dv_size) for _ in range(size)] + x0 = [x / scl for x, scl in zip(x0, x0_scales)] # scale accuracy obj = project.config["OPT_OBJECTIVE"]