Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for non_parametric optimization #100

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tmpbeing
Copy link
Collaborator

No description provided.

@github-actions github-actions bot added the enhancement New features or code improvements label Oct 17, 2024
@tmpbeing tmpbeing force-pushed the feat/non_parametric_optimization branch from 50c09f3 to 2f6d909 Compare October 17, 2024 16:23
Copy link

codecov bot commented Oct 17, 2024

Codecov Report

Attention: Patch coverage is 86.66667% with 8 lines in your changes missing coverage. Please review.

Project coverage is 85.47%. Comparing base (7b56823) to head (2f6d909).

Files with missing lines Patch % Lines
src/ansys/simai/core/data/optimizations.py 86.44% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #100      +/-   ##
==========================================
+ Coverage   83.54%   85.47%   +1.93%     
==========================================
  Files          44       44              
  Lines        2576     2617      +41     
==========================================
+ Hits         2152     2237      +85     
+ Misses        424      380      -44     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@yias yias left a comment

Choose a reason for hiding this comment

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

It looks fine. I just have a few comments.

I'm also wondering if a run_parametric and run_non_parametric could be a separated dataclass/pydantic class with fields and validators for avoiding having all the functions classified as internally used (_)

"""
geometry = get_object_from_identifiable(geometry, self._client._geometry_directory)
objective = _build_objective(minimize, maximize)
optimization_parameters = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

since optimization parameters is used both in run_parametric and run_non_parametric with small differences, it might deserve to have a function or class for its construction, according to parametric or non-parametric. Maye it would save some a few lines of code too 😄

if trial_run.fields.get("is_feasible", True):
iterations_results.append(iteration_result)
else:
logger.debug("Trial run results did not match constraints. Skipping.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this is something not important for the user, and it doesn't need to be notified.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Which is why it's in debug level. Most users won't ever see log from the SDK, you have to specifically enable them, even more so when it's debug.

src/ansys/simai/core/data/optimizations.py Show resolved Hide resolved
src/ansys/simai/core/data/optimizations.py Show resolved Hide resolved
src/ansys/simai/core/data/optimizations.py Show resolved Hide resolved
src/ansys/simai/core/data/optimizations.py Show resolved Hide resolved
for _ in range(n_iters):
logger.debug("Running iteration")
progress_bar.set_description("Running iteration")
trial_run = optimization._run_iteration({})
Copy link
Collaborator

Choose a reason for hiding this comment

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

This {} arg could really use a validation with a raise InvalidArguments

optimization: Identifiable[Optimization],
geometry: Identifiable[Geometry],
geometry_parameters: Dict,
def _run_iteration(
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: same method name for both optim and optimtrialrun objects, but with different args..

Copy link
Collaborator

@awoimbee awoimbee left a comment

Choose a reason for hiding this comment

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

Generally nice but data/optimizations.py is hard to understand

self,
geometry: Identifiable[Geometry],
bounding_boxes: List[List[float]],
symmetries: List[Literal["x", "y", "z", "X", "Y", "Z"]],
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the value of typing for both upper and lower case is not worth it compared to "Hugh ? Why am I seeing double ?"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since I could not wrap my head around the interaction of the different components I made this:

sequenceDiagram
    participant User
    participant OptDir as OptimizationDirectory
    participant TrialDir as OptimizationTrialRunDirectory

    User ->> OptDir: run_parametric
    activate User
    activate OptDir
    create participant Opti as Optimization
    OptDir -x Opti: creates


    loop Until optimization complete
        OptDir->>Opti: _run_iteration
        activate Opti
        Opti->>TrialDir: _run_iteration
        activate TrialDir
        create participant Trial as OptimizationTrialRun
        TrialDir-xTrial: Creates
        activate Trial
        TrialDir-->>Opti: returns OptimizationTrialRun
        deactivate TrialDir
        Opti-->>OptDir: returns OptimizationTrialRun
        deactivate Opti
        OptDir->>Trial: Get iteration results
        deactivate Trial
    end
    deactivate OptDir

    OptDir-->>User: result (List[Dict])
    deactivate User
Loading

Conclusions:

  • Some objects are not meant to be handled by end users (OptimizationTrialRun and OptimizationTrialRunDirectory so should be prefixed by "_")
  • The relationships between objects must be better defined in the code, even in the definition order, define the children first: OptimizationTrialRun then OptimizationTrialRunDirectory then Optimization then OptimizationDirectory
  • Maybe _run_iteration should only be defined on the Optimization ?
  • I don't understand what OptimizationTrialRunDirectory.get could be used for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features or code improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants