Skip to content

Fix CUSTOM_OBJFUNC support in Python layer#2756

Open
riddhi1228 wants to merge 4 commits intosu2code:developfrom
riddhi1228:fix/custom-objfunc-python-layer
Open

Fix CUSTOM_OBJFUNC support in Python layer#2756
riddhi1228 wants to merge 4 commits intosu2code:developfrom
riddhi1228:fix/custom-objfunc-python-layer

Conversation

@riddhi1228
Copy link

This PR fixes the handling of CUSTOM_OBJFUNC in the Python interface.

Problem

When evaluating custom objective functions, the Python layer could raise
a KeyError because the header "Custom_ObjFunc" from history files was not
normalized to the expected "CUSTOM_OBJFUNC" key.

Solution

  • Register CUSTOM_OBJFUNC in historyMap
  • Normalize "Custom_ObjFunc" header to "CUSTOM_OBJFUNC"
  • Ensure custom objective functions are correctly evaluated without KeyError

This resolves issue #2586.

- Register CUSTOM_OBJFUNC in historyMap
- Normalize Custom_ObjFunc header to CUSTOM_OBJFUNC key
- Prevent KeyError when evaluating custom objective functions

Fixes su2code#2586
@pcarruscag pcarruscag changed the base branch from master to develop March 12, 2026 16:28
@pcarruscag
Copy link
Member

==================== Start Test: sphere_ffd_def_bspline ====================
/github/workspace/tests/TestCases/deformation/spherical_ffd
sphere_ffd_def_bspline: PASSED
execution command: SU2_DEF def_spherical_bspline.cfg > def_spherical_bspline.log 2>&1
test_iter=10
test_vals (stored): 0.002068
sim_vals (computed): 0.002068
delta_vals: 0.000000
test duration: 0.03 min
Traceback (most recent call last):
  File "/github/workspace/install/bin/continuous_adjoint.py", line 32, in <module>
    import SU2
  File "/github/workspace/install/bin/SU2/__init__.py", line 19, in <module>
    from SU2 import eval
  File "/github/workspace/install/bin/SU2/eval/__init__.py", line 1, in <module>
    from SU2.eval.functions import function as func
  File "/github/workspace/install/bin/SU2/eval/functions.py", line 92
    header_to_key = {v["HEADER"]: k for k, v in su2io.historyOutFields.items()}
    ^
IndentationError: unexpected indent

@riddhi1228
Copy link
Author

Fixed — the indentation error on line 92 has been corrected and black formatting applied. Thanks for catching it.

@riddhi1228
Copy link
Author

The black formatting check is failing on historyMap.py even though black 22.6.0 reports no changes needed locally and the file is unchanged on the develop branch. This appears to be a pre-existing formatting issue in the repo rather than something introduced by this PR. Happy to investigate further if you can point me to what the CI is reformatting exactly.

@pcarruscag
Copy link
Member

It's ok. The bigger issue is that this historyMap.py file should be generated, not edited manually.
Can you try to run the script that generates the historyMap (it's somewhere in SU2_PY) and see if the tests still pass?

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.

2 participants