Skip to content

Commit

Permalink
Getter/setter methods implemented for execution options property of N…
Browse files Browse the repository at this point in the history
…ode class. (#323)
  • Loading branch information
ekrja authored Oct 17, 2024
1 parent 027b507 commit f99dd82
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 1 deletion.
63 changes: 62 additions & 1 deletion src/ansys/optislang/core/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
49 changes: 49 additions & 0 deletions src/ansys/optislang/core/tcp/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
PROJECT_COMMANDS_RETURN_STATES,
DesignFlow,
Edge,
ExecutionOption,
InnerInputSlot,
InnerOutputSlot,
InputSlot,
Expand Down Expand Up @@ -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, ...]:
Expand Down Expand Up @@ -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.
Expand Down
26 changes: 26 additions & 0 deletions tests/tcp/test_tcp_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from ansys.optislang.core.tcp.nodes import (
DesignFlow,
Edge,
ExecutionOption,
TcpInnerInputSlotProxy,
TcpInnerOutputSlotProxy,
TcpInputSlotProxy,
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit f99dd82

Please sign in to comment.