From f6b272cefc671fd4edbffc892fbf3e3cb35148d8 Mon Sep 17 00:00:00 2001 From: Ronny Fahlberg <86288939+rfahlberg@users.noreply.github.com> Date: Sat, 7 Dec 2024 13:11:41 +0000 Subject: [PATCH] MAINT: OptimizationParameter: Fix wrapping of reference_value and range. --- src/ansys/optislang/core/project_parametric.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ansys/optislang/core/project_parametric.py b/src/ansys/optislang/core/project_parametric.py index 029eb851f..4da9365ee 100644 --- a/src/ansys/optislang/core/project_parametric.py +++ b/src/ansys/optislang/core/project_parametric.py @@ -2498,12 +2498,12 @@ class OptimizationParameter(Parameter): def __init__( self, name: str = "", - reference_value: Union[bool, float, str, None] = 0, + reference_value: Union[bool, float, str, int, None] = 0, reference_value_type: ParameterValueType = ParameterValueType.REAL, id: Optional[str] = None, const: bool = False, deterministic_resolution: Union[ParameterResolution, str] = ParameterResolution.CONTINUOUS, - range: Union[Sequence[float, float], Sequence[Sequence[float]]] = (-1, 1), + range: Union[Sequence[float, float], Sequence[Sequence[Union[bool, float, str, int]]]] = (-1, 1), ) -> None: """Create a new instance of ``OptimizationParameter``. @@ -2633,17 +2633,17 @@ def deterministic_resolution( ) @property - def range(self) -> Union[Tuple[float, float], Tuple[Tuple[float, ...]]]: + def range(self) -> Union[Tuple[float, float], Tuple[Tuple[Union[bool, float, str, int], ...]]]: """Range of the optimization parameter.""" return self.__range @range.setter - def range(self, range: Union[Sequence[float, float], Sequence[Sequence[float]]]) -> None: + def range(self, range: Union[Sequence[float, float], Sequence[Sequence[Union[bool, float, str, int]]]]) -> None: """Set the range of the optimization parameter. Parameters ---------- - range: Union[Sequence[float, float], Sequence[Sequence[float]]] + range: Union[Sequence[float, float], Sequence[Sequence[Union[bool, float, str, int]]]] Range of the optimization parameter. """ if not isinstance(range[0], (float, int)): @@ -2659,13 +2659,13 @@ def to_dict(self) -> dict: dict Input dictionary for the optiSLang server. """ - if len(self.range) == 1: - range_dict = {"discrete_states": self.range[0]} - else: + if self.deterministic_resolution == ParameterResolution.CONTINUOUS: range_dict = { "lower_bound": self.range[0], "upper_bound": self.range[1], } + else: + range_dict = {"discrete_states": self.range} output_dict = { "active": True, "const": self.const if self.const is not None else False,