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(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 process.
- 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.
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<=
.
n_iters (int) – Number of iterations of the optimization loop.
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
TrialRuns#
Trial runs are a single step of the optimization process.
Directory#
Model#
- class OptimizationTrialRun#
Provides the local representation of an optimization trial run object.
The optimization trial run is an iteration of the optimization process. Each trial run tests a geometry and returns new parameters for the next geometry to try.
- 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