Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
import os

import ansys.simai.core as asc
from ansys.simai.core.data.optimizations import Optimization
from ansys.simai.core.data.predictions import Prediction

ORGANIZATION_NAME = "<your_organization_name>"
Expand Down Expand Up @@ -213,9 +212,7 @@
# Get the optimization ID for either a server-side or legacy optimization,
# and print the generated geometries and objective values:

optimization_id = (
optimization.id if isinstance(optimization, Optimization) else optimization.optimization.id
)
optimization_id = optimization.optimization.id

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Was the previous method broken ? I don't think we should recommend users to use that approach when we probably don't want to keep it long term.


print(f"Optimization ID: {optimization_id}")
print(f"Generated geometries: {[geo.name for geo in optimization.list_geometries()]}")
Expand Down
6 changes: 6 additions & 0 deletions src/ansys/simai/core/data/optimizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from typing import Any, Dict, List, Literal, Optional, Union

from tqdm import tqdm
from typing_extensions import Self
from wakepy import keep

from ansys.simai.core.data.base import ComputableDataModel, Directory
Expand Down Expand Up @@ -73,6 +74,11 @@ def __init__(self, *args, **kwargs):
self._geometries = None
self._objectives = None

@property
def optimization(self) -> Self:
"""Returns self. Present for backwards compatibility with LegacyOptimizationResult."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd add a deprecation warning saying this will be removed when the legacy client-side optimization will be removed.

return self

@property
def iteration_results(self) -> Optional[List[Dict]]:
"""List of iteration results generated by the optimization."""
Expand Down
1 change: 1 addition & 0 deletions tests/test_optimizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ def test_run_non_parametric_optimization(simai_client, geometry_factory, model_f

assert isinstance(result, Optimization)
assert not result.is_ready
assert result.optimization.id == "theid"

iteration_results = [
{
Expand Down
Loading