Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getter/setter methods implemented for execution options property of Node class. #323

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading