Repository navigation
[OptApp] Introducing AlgorithmDataManager to store and retrieve data. - #14676
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Critical and moderate issues in AlgorithmDataManager remain unresolved.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR centralizes algorithm data storage and retrieval through AlgorithmDataManager and updates related optimization algorithms and tests.
Changes:
- Added per-control algorithm data management.
- Refactored algorithms and line-search utilities.
- Updated tests and expected output summaries.
File summaries
| File | Summary |
|---|---|
applications/OptimizationApplication/tests/algorithm_tests/test_line_search.py |
Updated line-search data fixtures. |
applications/OptimizationApplication/tests/algorithm_tests/analysis_based_tests/algorithm_steepest_descent/summary_orig.csv |
Updated expected control metadata. |
applications/OptimizationApplication/tests/algorithm_tests/analysis_based_tests/algorithm_steepest_descent_qnbb/summary_orig.csv |
Updated expected control metadata. |
applications/OptimizationApplication/tests/algorithm_tests/analysis_based_tests/algorithm_nesterov_accelerated_gradient/summary_orig.csv |
Updated expected control metadata. |
applications/OptimizationApplication/python_scripts/utilities/opt_line_search.py |
Uses managed algorithm data. |
applications/OptimizationApplication/python_scripts/algorithms/algorithm_steepest_descent.py |
Refactored algorithm data access. |
applications/OptimizationApplication/python_scripts/algorithms/algorithm_relaxed_gradient_projection.py |
Refactored algorithm data access. |
applications/OptimizationApplication/python_scripts/algorithms/algorithm_nesterov_accelarated_gradient.py |
Uses centralized data management. |
applications/OptimizationApplication/python_scripts/algorithms/algorithm_momentum_relaxed_gradient_projection.py |
Uses centralized data management. |
applications/OptimizationApplication/python_scripts/algorithms/algorithm_gradient_projection.py |
Refactored algorithm data access. |
applications/OptimizationApplication/python_scripts/algorithms/algorithm_data_manager.py |
Implements centralized per-control data management. |
Review details
Suppressed comments (2)
applications/OptimizationApplication/python_scripts/algorithms/algorithm_data_manager.py:21
- Storing each combined tensor only as per-control children changes the value returned by the existing
GetComponentValueByFullNameAPI:search_direction:historicalnow resolves to aBufferedDict, not an object with.data.L2ConvCriterionstill reads that key directly and will raise "is not a field" when configured with any of these algorithms. Preserve a compatible aggregate value or update the convergence consumer to use this manager.
for control_name, tensor_adaptor in zip(self.__list_of_control_names, value.GetTensorAdaptors()):
data_view.SetValue(f"{key}/{control_name}_{key}", tensor_adaptor, step_index, overwrite)
applications/OptimizationApplication/tests/algorithm_tests/test_line_search.py:33
- This fixture writes a combined adaptor directly into each per-control leaf, whereas
AlgorithmDataManager.SetValuestoresvalue.GetTensorAdaptors()(one adaptor per control). With only one control, the nested combined adaptor happens to expose the same flat data, so this does not exercise the new decomposition/reconstruction contract or multi-control history. ExerciseSetValue/GetValuewith at least two controls or add a dedicated manager test.
ComponentDataView("algorithm", cls.optimization_problem).GetBufferedData()["search_direction/test_control_search_direction"] = search_direction
ComponentDataView("algorithm", cls.optimization_problem_one_step).GetBufferedData()["search_direction/test_control_search_direction"] = sensitivity
ComponentDataView("algorithm", cls.optimization_problem).GetBufferedData()["control_field_update/test_control_control_field_update"] = control_field_update
- Files reviewed: 11/11 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| def HasValue(self, key: str, is_historical = True, step_index = 0) -> bool: | ||
| data_view = self.__GetBufferedDataDict(is_historical) | ||
| return data_view.HasValue(key, step_index) |
| for control_name, tensor_adaptor in zip(self.__list_of_control_names, value.GetTensorAdaptors()): | ||
| data_view.SetValue(f"{key}/{control_name}_{key}", tensor_adaptor, step_index, overwrite) |
|
@talhah-ansari can you please explain what does it improve? I can't understand |
Suggestion: name the fields per control at output time instead of adding
|
|
The kratos-reviewer recommends request changes on PR #14676 ("[OptApp] Introducing AlgorithmDataManager…"). It could only build or run one thing: a Python 3.11 compile of the PR's file, which confirmed blocker 1. Everything else comes from reading the code. The branch has already been reworked along the lines of your 2026-10-09 comment, so
Blockers
Should-fix
Nits: the Suggested direction (same as your earlier comment): take the names from To read the code, the reviewer fetched the PR into |
There was a problem hiding this comment.
@sunethwarna thanks. Is this CombinedTensorAdaptorData initialization still valid? Shouldn't there be 4 arguments?
There was a problem hiding this comment.
good catch... This is not used anywhere yet. Thats why it did not lead to failure in the unit tests.... I will fix it
Igarizza
left a comment
There was a problem hiding this comment.
@sunethwarna @talhah-ansari Nice work! I am happy with this version :)
|
|
||
| class AlgorithmDataManager: | ||
| def __init__(self, optimization_problem: OptimizationProblem): | ||
| self.__optimization_problem = optimization_problem |
📝 Description
This PR introduces a new
AlgorithmDataManagerutility class to centralize and standardize the management of algorithm data within the optimization algorithms. The affected algorithms have been refactored to use this new class for storing and retrieving data.🆕 Changelog
AlgorithmDataManagerclass inalgorithm_data_manager.pyto encapsulate logic for storing and retrieving algorithm-related data.AlgorithmGradientProjection,AlgorithmRelaxedGradientProjection,AlgorithmMomentumRelaxedGradientProjection, andAlgorithmNesterovAccelaratedGradientto useAlgorithmDataManagerfor all algorithm data interactions, replacing previous direct usage ofComponentDataViewandBufferedDict.