diff --git a/src/ansys/optislang/core/nodes.py b/src/ansys/optislang/core/nodes.py index 5bfe63cdd..1e2a9a5b3 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 deprecated.sphinx import deprecated @@ -89,6 +89,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.""" @@ -348,6 +359,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 @@ -592,6 +623,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 539804f6c..d6eda6f8c 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, @@ -289,6 +290,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, ...]: @@ -624,6 +644,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 403d5da79..65950db64 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