From 3f6e2b03c50707395120047afd0b9ab014d7f3e9 Mon Sep 17 00:00:00 2001 From: Jan Ekr <108271285+ekrja@users.noreply.github.com> Date: Thu, 5 Sep 2024 10:20:06 +0200 Subject: [PATCH] Getter/setter methods implemented for execution options property of Node class. --- src/ansys/optislang/core/nodes.py | 63 ++++++++++++++++++++++++++- src/ansys/optislang/core/tcp/nodes.py | 49 +++++++++++++++++++++ tests/tcp/test_tcp_nodes.py | 26 +++++++++++ 3 files changed, 137 insertions(+), 1 deletion(-) diff --git a/src/ansys/optislang/core/nodes.py b/src/ansys/optislang/core/nodes.py index f31c85a88..551c1c5f3 100644 --- a/src/ansys/optislang/core/nodes.py +++ b/src/ansys/optislang/core/nodes.py @@ -24,7 +24,7 @@ from __future__ import annotations from abc import ABC, abstractmethod -from enum import Enum +from enum import Enum, Flag from typing import TYPE_CHECKING, Any, Optional, Tuple, Union from ansys.optislang.core.io import File, FileOutputFormat, RegisteredFile @@ -87,6 +87,17 @@ def from_str(cls, string: str) -> DesignFlow: return enum_from_str(string=string, enum_class=cls, replace=(" ", "_")) +class ExecutionOption(Flag): + """Provides actor execution options.""" + + INACTIVE = 0 + ACTIVE = 1 + END_POINT = 2 + STARTING_POINT = 4 + SAVE_POINT = 8 + RECYCLE_RESULTS = 16 + + class NodeClassType(Enum): """Provides types of pyOSL classes.""" @@ -345,6 +356,26 @@ def get_ancestors(self) -> Tuple[Node, ...]: # pragma: no cover """ pass + @abstractmethod + def get_execution_options(self) -> ExecutionOption: # pragma: no cover + """Get execution options. + + Returns + ------- + ExecutionOption + Execution options of the ``Node``. + + Raises + ------ + OslCommunicationError + Raised when an error occurs while communicating with the server. + OslCommandError + Raised when a command or query fails. + TimeoutError + Raised when the timeout float value expires. + """ + pass + @abstractmethod def get_connections( self, slot_type: Optional[SlotType] = None, slot_name: Optional[str] = None @@ -589,6 +620,36 @@ def get_status(self) -> str: # pragma: no cover """ pass + @abstractmethod + def set_execution_options(self, value: ExecutionOption) -> None: # pragma: no cover + """Set execution options. + + Parameters + ---------- + value : ExecutionOption + Execution options of the ``Node``. More execution options can be + combined using the bitwise operations. + + Raises + ------ + OslCommunicationError + Raised when an error occurs while communicating with the server. + OslCommandError + Raised when a command or query fails. + TimeoutError + Raised when the timeout float value expires. + + Examples + -------- + Combination of more execution options using the bitwise operation. + + >>> ... + >>> node.set_execution_options( + ExecutionOption.ACTIVE | ExecutionOption.STARTING_POINT + ) + """ + pass + @abstractmethod def set_property(self, name: str, value: Any) -> None: # pragma: no cover """Set node's property. diff --git a/src/ansys/optislang/core/tcp/nodes.py b/src/ansys/optislang/core/tcp/nodes.py index 2c4587ec7..ab7051379 100644 --- a/src/ansys/optislang/core/tcp/nodes.py +++ b/src/ansys/optislang/core/tcp/nodes.py @@ -42,6 +42,7 @@ PROJECT_COMMANDS_RETURN_STATES, DesignFlow, Edge, + ExecutionOption, InnerInputSlot, InnerOutputSlot, InputSlot, @@ -288,6 +289,25 @@ def get_ancestors(self) -> Tuple[TcpNodeProxy, ...]: logger=self._logger, ) + def get_execution_options(self) -> ExecutionOption: + """Get execution options. + + Returns + ------- + ExecutionOption + Execution options of the ``Node``. + + Raises + ------ + OslCommunicationError + Raised when an error occurs while communicating with the server. + OslCommandError + Raised when a command or query fails. + TimeoutError + Raised when the timeout float value expires. + """ + return ExecutionOption(self.get_property("ExecutionOptions")) + def get_connections( self, slot_type: Optional[SlotType] = None, slot_name: Optional[str] = None ) -> Tuple[Edge, ...]: @@ -623,6 +643,35 @@ def get_type(self) -> NodeType: ) return get_node_type_from_str(node_id=actor_info["type"]) + def set_execution_options(self, value: ExecutionOption) -> None: + """Set execution options. + + Parameters + ---------- + value : ExecutionOption + Execution options of the ``Node``. More execution options can be + combined using the bitwise operations. + + Raises + ------ + OslCommunicationError + Raised when an error occurs while communicating with the server. + OslCommandError + Raised when a command or query fails. + TimeoutError + Raised when the timeout float value expires. + + Examples + -------- + Combination of more execution options using the bitwise operation. + + >>> ... + >>> node.set_execution_options( + ExecutionOption.ACTIVE | ExecutionOption.STARTING_POINT + ) + """ + return self.set_property("ExecutionOptions", value.value) + def set_property(self, name: str, value: Any) -> None: """Set node's property. diff --git a/tests/tcp/test_tcp_nodes.py b/tests/tcp/test_tcp_nodes.py index 399c81ece..4a0679582 100644 --- a/tests/tcp/test_tcp_nodes.py +++ b/tests/tcp/test_tcp_nodes.py @@ -32,6 +32,7 @@ from ansys.optislang.core.tcp.nodes import ( DesignFlow, Edge, + ExecutionOption, TcpInnerInputSlotProxy, TcpInnerOutputSlotProxy, TcpInputSlotProxy, @@ -216,6 +217,31 @@ def test_set_property(optislang: Optislang, tmp_example_project): assert node.get_property("ExecutionOptions") == set_int_property +def test_node_execution_options(optislang: Optislang, tmp_example_project): + """Test `set_execution_options` and `get_execution_options` methods.""" + optislang.application.open(file_path=tmp_example_project("calculator_with_params")) + root_system = optislang.project.root_system + node: TcpNodeProxy = root_system.find_nodes_by_name("Calculator")[0] + + execution_options_list = [ + ExecutionOption.INACTIVE, + ExecutionOption.ACTIVE, + ExecutionOption.STARTING_POINT, + ExecutionOption.ACTIVE | ExecutionOption.STARTING_POINT, + ExecutionOption.END_POINT, + ExecutionOption.ACTIVE | ExecutionOption.END_POINT, + ExecutionOption.SAVE_POINT, + ExecutionOption.ACTIVE | ExecutionOption.SAVE_POINT, + ExecutionOption.RECYCLE_RESULTS, + ExecutionOption.ACTIVE | ExecutionOption.RECYCLE_RESULTS, + ] + + for execution_options in execution_options_list: + node.set_execution_options(execution_options) + recv_execution_options = node.get_execution_options() + assert execution_options == recv_execution_options + + # endregion