Skip to content

Add support for recursive components in DashAI Models#368

Merged
cristian-tamblay merged 12 commits into
developfrom
fix/recursive-model
Nov 10, 2025
Merged

Add support for recursive components in DashAI Models#368
cristian-tamblay merged 12 commits into
developfrom
fix/recursive-model

Conversation

@Irozuku
Copy link
Copy Markdown
Collaborator

@Irozuku Irozuku commented Oct 30, 2025

This pull request introduces significant improvements to how model parameters are extracted, instantiated, and optimized across the backend and frontend of DashAI. The main focus is on refactoring the model factory to support recursive instantiation of nested components and optimizable parameters, as well as updating optimizers and frontend logic to work with the new parameter structure.

Backend Model Factory and Optimizer Refactor:

  • Recursive extraction and instantiation of model parameters:

    • The ModelFactory class now recursively instantiates models and their subcomponents from a parameter dictionary, collecting references to all optimizable parameters (object, name, bounds). This enables seamless optimization of both top-level and nested parameters. (DashAI/back/models/model_factory.py)
    • The _extract_parameters and _process_param methods have been rewritten to support nested DashAI components, optimizable parameters, and primitive values, ensuring all optimizable parameters are correctly bound to their respective objects.
  • Optimizer updates for new parameter format:

    • The base optimizer, optuna_optimizer, and hyperopt_optimizer now expect parameters as a list of tuples (object, parameter name, bounds) and set parameter values directly on the correct objects during optimization. This change supports nested models and improves parameter importance calculation. (DashAI/back/optimizers/base_optimizer.py, DashAI/back/optimizers/optuna_optimizer.py, DashAI/back/optimizers/hyperopt_optimizer.py)

Frontend Improvements:

  • Improved detection of optimizable parameters:
    • The frontend utility checkIfHaveOptimazers now recursively checks for optimizable parameters in nested objects, enabling accurate UI logic for enabling/disabling tabs related to hyperparameter optimization. (DashAI/front/src/utils/schema.js, DashAI/front/src/pages/results/components/ResultsDetailsLayout.jsx)

Other Notable Changes:

  • The BOW text classification model constructor was simplified to directly accept the classifier object, removing unnecessary parameter transformation logic. (DashAI/back/models/scikit_learn/bow_text_classification_model.py)

@Irozuku Irozuku changed the title Add support for recursive components for DashAI Models Add support for recursive components in DashAI Models Oct 30, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the parameter extraction and optimization process to support nested model components with optimizable parameters. The main changes include restructuring how models and their sub-components are instantiated, and updating optimizers to work with the new parameter structure.

Key Changes:

  • Refactored ModelFactory to recursively instantiate nested DashAI components and collect optimizable parameter references
  • Updated optimizers (Optuna, Hyperopt) to work with list-based parameter structure instead of dictionary
  • Simplified recursive optimizer detection functions in the frontend to work with any nested structure
  • Fixed placeholder value for lower_bound in SVC max_iter parameter

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
DashAI/back/models/model_factory.py Complete refactor of parameter extraction to recursively build nested models and collect optimizable refs as list of tuples
DashAI/back/optimizers/optuna_optimizer.py Updated to iterate over list-based parameters structure instead of dict
DashAI/back/optimizers/hyperopt_optimizer.py Updated search space generation and objective function for new parameter format
DashAI/back/optimizers/base_optimizer.py Updated importance_plot to destructure tuple-based parameters
DashAI/back/models/scikit_learn/bow_text_classification_model.py Removed manual parameter transformation logic, simplified to direct assignment
DashAI/back/models/scikit_learn/svc.py Fixed max_iter lower_bound from 1 to -1
DashAI/front/src/utils/schema.js Added unused import and refactored optimizer check functions for better recursion
DashAI/front/src/pages/results/components/ResultsDetailsLayout.jsx Updated to use boolean return from checkIfHaveOptimazers instead of count
Comments suppressed due to low confidence (3)

DashAI/back/models/model_factory.py:14

  • The docstring indicates optimizable_parameters is a dict, but the refactored code now returns a list of tuples (object reference, parameter name, bounds). The documentation should be updated to reflect this change.
    optimizable_parameters : dict

DashAI/back/optimizers/optuna_optimizer.py:114

  • After optimization, the code sets parameters directly on the best_model using parameter names from best_params. However, with nested models, the parameters may belong to sub-models, not the top-level model. This should iterate over self.parameters to get the correct object reference for each parameter: for obj, key, _ in self.parameters: if key in best_params: setattr(obj, key, best_params[key])
        for hyperparameter, value in best_params.items():
            setattr(best_model, hyperparameter, value)

DashAI/front/src/utils/schema.js:3

  • Unused import isObject.
import { isObject } from "formik";

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread DashAI/front/src/utils/schema.js Outdated
Comment thread DashAI/back/optimizers/optuna_optimizer.py Outdated
Comment thread DashAI/back/optimizers/hyperopt_optimizer.py
@cristian-tamblay cristian-tamblay merged commit e4eda08 into develop Nov 10, 2025
18 checks passed
@cristian-tamblay cristian-tamblay deleted the fix/recursive-model branch November 10, 2025 13:45
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.

3 participants