Optimization#
Directory#
- class OptimizationDirectory#
Provides a collection of methods related to optimizations.
This class is accessed through
client.optimizations.Example
import ansys.simai.core as asc simai_client = asc.from_config() simai_client.optimizations.run_non_parametric(...)
- delete(optimization: Optimization | str) None#
Delete a specific optimization from the server.
- Parameters:
optimization (Optimization | str) – ID or
modelof the optimization.- Raises:
ansys.simai.core.errors.NotFoundError – No optimization with the given ID exists.
- get(optimization_id: str) Optimization#
Get a specific optimization object from the server.
- Parameters:
optimization_id (str) – ID of the optimization.
- Returns:
- Return type:
- list(workspace_id: str) list[Optimization]#
List all optimizations in the workspace available on the server.
- run_non_parametric(geometry: Geometry | str, bounding_boxes: List[List[float]], n_iters: int, max_displacement: List[float] | None = None, offline_token: str | None = None, symmetries: List[Literal['x', 'y', 'z', 'X', 'Y', 'Z']] | None = None, axial_symmetry: Literal['x', 'y', 'z'] | None = None, scalars: Dict[str, float] | None = None, minimize: List[str] | None = None, maximize: List[str] | None = None, show_progress: bool = False, boundary_conditions: Dict[str, float] | None = None, detail_level: int | None = None, part_morphing: OptimizationPartMorphingSchema | None = None) Optimization | LegacyOptimizationResult#
Run an optimization to generate geometries, using automorphing. Automorphing is a non-parametric deformation of a surface geometry. If possible, the function will try to run the optimization loop server-side. If not possible, the function will fall back to running the optimization loop client-side (legacy).
Warning
The
boundary_conditionsparameter is deprecated.- Parameters:
geometry (Geometry | str) – Required. The object (Geometry) or the ID (str) of the baseline geometry on which to perform the non-parametric optimization and that has already been used to build an AI model. The optimization will run in the same workspace as the model.
bounding_boxes (List[List[float]]) –
Required. The list of the bounds of the different boxes that will define the absolute locations of the geometry to optimize. It is a list of lists, and each sub-list must have exactly six items with the following expected order:
[x_min, x_max, y_min, y_max, z_min, z_max].Example format:
[ [box1_xmin, box1_xmax, box1_ymin, box1_ymax, box1_zmin, box1_zmax], [box2_xmin, box2_xmax, box2_ymin, box2_ymax, box2_zmin, box2_zmax], ... ]
n_iters (int) – Required. The number of optimization iterations. This number must be a strictly positive integer. It will define the number of automorphed geometries uploaded to the SimAI workspace.
offline_token (str | None) – Optional. Offline token to use for authentication. If not provided, the method will try to use the offline token defined in the client configuration. If no
offline_tokencan be passed as function parameter or in the client configuration, server-side optimization will not work. See Current user to generate an offline token.symmetries (List[Literal['x', 'y', 'z', 'X', 'Y', 'Z']] | None) –
Optional. The list of symmetry axes, axes being x, y, and z, defining a plane around which the geometry is mirrored.
The planar symmetry is applied to all the
bounding_boxesdefined.symmetriesandaxial_symmetryare mutually exclusive parameters.
axial_symmetry (Literal['x', 'y', 'z'] | None) –
Optional. The axis, defined by a scalar, along which axial symmetry is applied. For the deformation to be axially symmetrical:
The center of the bounding box must coincide with the targeted central axis.
The mesh should be axially symmetrical in the bounding box.
The
axial_symmetryis applied to all thebounding_boxesdefined.symmetriesandaxial_symmetryare mutually exclusive parameters.
scalars (Dict[str, float] | None) – Optional. The values of the scalars to perform the optimization at. The values must correspond to existing scalars already defined in your SimAI workspace.
minimize (List[str] | None) – Required if no
maximizeparameter is defined. A list of one global coefficient to minimize. This global coefficient must correspond to one of the existing coefficients defined in your model configuration.Required if no
minimizeparameter is defined. A list of one global coefficient to maximize. This global coefficient must correspond to one of the existing coefficients defined in your model configuration.Note
minimizeandmaximizeare mutually exclusive objectives; define only one.The defined objective must be computed from the surface fields because mesh nodes must be involved.
max_displacement (List[float] | None) –
Required if the model uses server side optimizations, else Optional. User-defined constraint on the maximum allowable deformation of the initial mesh in non-parametric optimization. It is specified as a list (
max_displacement) matching the number of bounding boxes (bounding_boxes).For example, for two bounding boxes:
bounding_boxes = [[0,1,0,2,0,4],[10,2,10,4,10,5]]max_displacement = [0.002, 0.001]
Each value limits the displacement within the corresponding bounding box, using the same metric as the bounding box coordinates.
show_progress (bool) – Optional. Whether to print progress bar on stdout. It is updated each time a new iteration is completed.
boundary_conditions (Dict[str, float] | None) – Optional. (Deprecated) The values of the boundary conditions to perform the optimization at. The values must correspond to existing boundary conditions already defined in your SimAI workspace.
detail_level (int | None) –
Optional. Adjust how much deformation can be applied to the geometry. Integer from 1 to 10.
Low: coarse deformation, only rough shape changes.
High: fine details, subtle local adjustments possible.
Given the baseline geometry and bounding boxes, some level of detail_level might not be possible to achieve (too low to generate deformation or too high leading to Out of memory issues). In those cases, errors will be raised indicating what level you can use for your configuration.
When using multiple bounding boxes, using this feature ensures to have the same amount of deformation in the bounding boxes.
Example :
detail_level=4part_morphing (OptimizationPartMorphingSchema | None) –
Optional. User-defined constraints to perform on the parts to be morphed.
The id of the parts to be deformed must be provided as a list of integers given in the input
part_ids, and it must correspond to a cell field of the baseline geometry exactly namedPartId.continuity_constraintindicates how much the continuity at the interface between deformed and non-deformed parts must be enforced. It can be set between 0 and 1 included. At 0, the continuity is not constrained at all during the optimization. For acontinuity_constraintof 1, the continuity is the best. This parameter also has an impact on the overall magnitude deformation. The more the continuity is enforced, the lower the overall magnitude deformation will be. To overcome that behavior, the user can increase thedetail_levelvalue.Example:
part_morphing = {"part_ids":[1,2], "continuity_constraint":0.8}
Example
import ansys.simai.core as asc simai_client = asc.from_config(workspace="optimization-workspace") geometry = simai_client.geometries.list()[0] simai_client.optimizations.run_non_parametric( geometry, bounding_boxes=[[0, 1, 0, 1, 0, 1]], scalars={"VelocityX": 10.5}, symmetries=["y"], n_iters=10, minimize=["TotalForceX"], show_progress=True, )
- Returns:
An object containing the results of the optimization.
- Return type:
Model#
- class Optimization#
Provides the local representation of an optimization definition object.
- wait(timeout: float | None = None) bool#
Wait for all jobs concerning the object to either finish or fail.
- property failure_reason#
Optional message giving the causes for why the creation of the object failed.
See also
- property has_failed#
Boolean indicating if the creation of the object failed.
See also
- property is_pending#
Boolean indicating if the object is still in creation. The value becomes
Falseonce object creation is either successful or has failed.See also
- property is_ready#
Boolean indicating if the object has finished creating without error.
See also
- class OptimizationPartMorphingSchema#
Type used to specify optimization part morphing.
- Parameters:
parts_ids – The id of the parts to be deformed provided as a list of integers, and it must correspond to a cell field of the baseline geometry exactly named
PartId.continuity_constraint (float) – Indicates how much the continuity at the interface between deformed and non-deformed parts must be enforced. It can be set between 0 and 1 included. At 0, the continuity is not constrained at all during the optimization. For a
continuity_constraintof 1, the continuity is the best. This parameter also has an impact on the overall magnitude deformation. The more the continuity is enforced, the lower the overall magnitude deformation will be. To overcome that behavior, the user can increase thedetail_levelvalue.
LegacyOptimization#
Directory#
- class LegacyOptimizationDirectory#
Provides a collection of methods related to legacy client-side optimizations.
This class is accessed through
client.legacy_optimizations.Example
import ansys.simai.core as asc simai_client = asc.from_config() simai_client.legacy_optimizations.run_non_parametric(...)
- get(optimization_id: str) LegacyOptimization#
Get a specific (client-side) optimization object from the server.
- Parameters:
optimization_id (str) – ID of the optimization.
- Returns:
- Return type:
- run_non_parametric(geometry: Geometry | str, bounding_boxes: List[List[float]], n_iters: int, symmetries: List[Literal['x', 'y', 'z', 'X', 'Y', 'Z']] | None = None, axial_symmetry: Literal['x', 'y', 'z'] | None = None, scalars: Dict[str, float] | None = None, minimize: List[str] | None = None, maximize: List[str] | None = None, max_displacement: List[float] | None = None, show_progress: bool = False, boundary_conditions: Dict[str, float] | None = None) LegacyOptimizationResult#
Run an optimization loop to generate geometries, client-side, using automorphing. Automorphing is a non-parametric deformation of a surface geometry.
- Parameters:
geometry (Geometry | str) – Required. The object (Geometry) or the ID (str) of the baseline geometry on which to perform the non-parametric optimization and that has already been used to build an AI model. The optimization will run in the same workspace as the model.
bounding_boxes (List[List[float]]) –
Required. The list of the bounds of the different boxes that will define the absolute locations of the geometry to optimize. It is a list of lists, and each sub-list must have exactly six items with the following expected order:
[x_min, x_max, y_min, y_max, z_min, z_max].Example format:
[ [box1_xmin, box1_xmax, box1_ymin, box1_ymax, box1_zmin, box1_zmax], [box2_xmin, box2_xmax, box2_ymin, box2_ymax, box2_zmin, box2_zmax], ... ]
n_iters (int) – Required. The number of optimization iterations. This number must be a strictly positive integer. It will define the number of automorphed geometries uploaded to the SimAI workspace.
symmetries (List[Literal['x', 'y', 'z', 'X', 'Y', 'Z']] | None) –
Optional. The list of symmetry axes, axes being x, y, and z, defining a plane around which the geometry is mirrored.
The planar symmetry is applied to all the
bounding_boxesdefined.symmetriesandaxial_symmetryare mutually exclusive parameters.
axial_symmetry (Literal['x', 'y', 'z'] | None) –
Optional. The axis, defined by a scalar, along which axial symmetry is applied. For the deformation to be axially symmetrical:
The center of the bounding box must coincide with the targeted central axis.
The mesh should be axially symmetrical in the bounding box.
The
axial_symmetryis applied to all thebounding_boxesdefined.symmetriesandaxial_symmetryare mutually exclusive parameters.
scalars (Dict[str, float] | None) – Optional. The values of the scalars to perform the optimization at. The values must correspond to existing scalars already defined in your SimAI workspace.
minimize (List[str] | None) – Required if no
maximizeparameter is defined. A list of one global coefficient to minimize. This global coefficient must correspond to one of the existing coefficients defined in your model configuration.Required if no
minimizeparameter is defined. A list of one global coefficient to maximize. This global coefficient must correspond to one of the existing coefficients defined in your model configuration.Note
minimizeandmaximizeare mutually exclusive objectives; define only one.The defined objective must be computed from the surface fields because mesh nodes must be involved.
max_displacement (List[float] | None) –
Optional. User-defined constraint on the maximum allowable deformation of the initial mesh in non-parametric optimization. It is specified as a list (
max_displacement) matching the number of bounding boxes (bounding_boxes).For example, for two bounding boxes:
bounding_boxes = [[0,1,0,2,0,4],[10,2,10,4,10,5]]max_displacement = [0.002, 0.001]
Each value limits the displacement within the corresponding bounding box, using the same metric as the bounding box coordinates.
show_progress (bool) – Optional. Whether to print progress bar on stdout. It is updated each time a new iteration is completed.
boundary_conditions (Dict[str, float] | None) – Optional. (Deprecated) The values of the boundary conditions to perform the optimization at. The values must correspond to existing boundary conditions already defined in your SimAI workspace.
Example
import ansys.simai.core as asc simai_client = asc.from_config(workspace="optimization-workspace") geometry = simai_client.geometries.list()[0] simai_client.legacy_optimizations.run_non_parametric( geometry, bounding_boxes=[[0, 1, 0, 1, 0, 1]], scalars={"VelocityX": 10.5}, symmetries=["y"], n_iters=10, minimize=["TotalForceX"], show_progress=True, )
- Returns:
An object containing the results of the optimization.
- Return type:
Model#
- class LegacyOptimization#
Provides the local representation of a legacy client-side optimization definition object.
- wait(timeout: float | None = None) bool#
Wait for all jobs concerning the object to either finish or fail.
- property failure_reason#
Optional message giving the causes for why the creation of the object failed.
See also
- property has_failed#
Boolean indicating if the creation of the object failed.
See also
- property is_pending#
Boolean indicating if the object is still in creation. The value becomes
Falseonce object creation is either successful or has failed.See also
- property is_ready#
Boolean indicating if the object has finished creating without error.
See also
- class LegacyOptimizationResult#
Result for a non-parametric legacy optimization.
- property optimization: LegacyOptimization#
Optimization object of the optimization run.