Optimization#
Directory#
- class OptimizationDirectory#
Provides a collection of methods related to optimizations.
This class is accessed through
client.optimizations
.Example
import ansys.simai.core simai = ansys.simai.core.from_config() simai.optimizations.run(...)
- get(optimization_id: str) Optimization #
Get a specific 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]], symmetries: List[Literal['x', 'y', 'z', 'X', 'Y', 'Z']], boundary_conditions: Dict[str, float], n_iters: int, minimize: List[str] | None = None, maximize: List[str] | None = None, show_progress: bool = False)#
Run an optimization loop with server-side geometry generation using automorphism.
- Parameters:
geometry (Geometry | str) – The base geometry on which to perform the automorphism. The optimization will run in the same workspace as the geometry.
bounding_boxes (List[List[float]]) – list of the bounds of the different boxes that will define the locations of the geometry to optimize. The format is [ [box1_xmin, box1_xmax, box1_ymin, box1_ymax, box1_zmin, box1_zmax], [box2_xmin, box2_xmax, box2_ymin, box2_ymax, box2_zmin, box2_zmax], … ]
symmetries (List[Literal['x', 'y', 'z', 'X', 'Y', 'Z']]) – list of symmetry axes, axes being x, y or z
boundary_conditions (Dict[str, float]) – Values of the boundary conditions to perform the optimization at. The values should map to existing boundary conditions in your project/workspace.
n_iters (int) – Number of iterations of the optimization loop.
minimize (List[str] | None) – List of global coefficients to minimize. The global coefficients should map to existing coefficients in your project/workspace.
maximize (List[str] | None) – List of global coefficients to maximize. The global coefficients should map to existing coefficients in your project/workspace.
show_progress (bool) – Whether to print progress on stdout.
workspace – Workspace to run the optimization in. If a workspace is not specified, the default is the configured workspace.
Warning
This feature is in beta. Results are not guaranteed.
- run_parametric(geometry_generation_fn: Callable[[...], Path | str | PathLike | Tuple[BinaryIO | RawIOBase | BufferedIOBase | Path | str | PathLike, str]], geometry_parameters: Dict[str, Tuple[float, float]], boundary_conditions: Dict[str, float], n_iters: int, minimize: List[str] | None = None, maximize: List[str] | None = None, outcome_constraints: List[str] | None = None, show_progress: bool = False, workspace: Workspace | str | None = None) List[Dict] #
Run an optimization loop with client-side parametric geometry generation.
- Parameters:
geometry_generation_fn (Callable[[...], Path | str | PathLike | Tuple[BinaryIO | RawIOBase | BufferedIOBase | Path | str | PathLike, str]]) – Function to call to generate a new geometry with the generated parameters. This parameter should return a
NamedFile
object.geometry_parameters (Dict[str, Tuple[float, float]]) – Name of the geometry parameters and their bounds or possible values (choices).
boundary_conditions (Dict[str, float]) – Values of the boundary conditions to perform the optimization at. The values should map to existing boundary conditions in your project/workspace.
n_iters (int) – Number of iterations of the optimization loop.
minimize (List[str] | None) – List of global coefficients to minimize. The global coefficients should map to existing coefficients in your project/workspace.
maximize (List[str] | None) – List of global coefficients to maximize. The global coefficients should map to existing coefficients in your project/workspace.
outcome_constraints (List[str] | None) –
List of strings representing a linear inequality constraint on a global coefficient. The outcome constraint should be in the form
gc >= x
, where:gc
is a valid global coefficient name.x
is a float bound.The comparison operator is
>=
or<=
.
show_progress (bool) – Whether to print progress on stdout.
workspace (Workspace | str | None) – Workspace to run the optimization in. If a workspace is not specified, the default is the configured workspace.
- Returns:
List of dictionaries representing the result of each iteration. when constraints are specified, the list can be shorter than the number of iterations.
- Return type:
Warning
This is a long-running process and your computer must be powered on to generate the iterations. This method attempts to prevent your computer from sleeping, keeping your computer open during the process.
Example
import ansys.simai.core # Function takes the parameters def my_geometry_generation_function(param_a, param_b): # Implementation return "/path/to/generated/geometry.stl" simai = ansys.simai.core.from_config(workspace="optimization-workspace") results = simai.optimizations.run( geometry_generation_fn=my_geometry_generation_function, geometry_parameters={ "param_a": {"bounds": (-12.5, 12.5)}, "param_b": {"choices": (0, 1)}, }, minimize=["TotalForceX"], boundary_conditions={"VelocityX": 10.5}, outcome_constraints=["TotalForceX <= 10"], n_iters=100, ) print(results)
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
False
once 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