Skip to content
Draft
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
6 changes: 4 additions & 2 deletions tests/e2e/test_client_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ def test_queue_node(self, e2e_client: Client):
Args:
e2e_client: A Client instance.
"""
node_name = "Add"
node_name = "Add" # TODO CHANGE TO ID
inputs = {
"lhs": 1,
"rhs": 2,
} # Inputs are left hand side and right hand side of equation

job_id = e2e_client.queue_node(node=node_name, inputs=inputs)
job_id = e2e_client.queue_node(
node=node_name, inputs=inputs
) # TODO CHANGE TO ID

# Add the job_id as an attribute of the test class so that it can be used in other tests
TestClientMethods.job_id = job_id
Expand Down
11 changes: 7 additions & 4 deletions tests/unit/api_providers/test_workflows_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def mock_workflow_dict() -> dict[str, Any]:
@pytest.fixture
def mock_executable_dict(mock_workflow_dict: dict[str, Any]) -> dict[str, Any]:
"""Executable workflow test data."""
return {"node_id": "Workflow", "inputs": mock_workflow_dict}
return {"node_id": "Workflow", "inputs": mock_workflow_dict} # TODO CHANGE TO ID


@pytest.fixture
Expand All @@ -73,7 +73,7 @@ def mock_executable_workflow(
):
"""Create mock executable workflow object."""
executable = Mock(spec=WorkflowExecutable)
executable.node_id = "Workflow"
executable.node_id = "Workflow" # TODO CHANGE TO ID
executable.inputs = {
"graph": mock_workflow.graph,
"inputs": mock_workflow.inputs,
Expand Down Expand Up @@ -487,15 +487,18 @@ def test_read_version_success(
):
"""Test reading workflow versions (latest and specific)."""
mock_response = Mock()
mock_response.workflow = {"node_id": "Workflow", "inputs": mock_workflow_dict}
mock_response.workflow = {
"node_id": "Workflow",
"inputs": mock_workflow_dict,
} # TODO CHANGE TO ID

api_method = getattr(mock_workflows_client, expected_api_method)
api_method.return_value = mock_response

result = version_manager.read_version("project-123", "workflow-123", version_id)

assert isinstance(result, WorkflowExecutable)
assert result.node_id == "Workflow"
assert result.node_id == "Workflow" # TODO CHANGE TO ID
assert result.inputs == mock_workflow_dict

api_method.assert_called_once_with(*expected_api_args)
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/nodes/test_base.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import pytest
from typeguard import TypeCheckError
from uncertainty_engine_types import Handle

from uncertainty_engine.nodes.base import Node
from typeguard import TypeCheckError


def test_node():
"""
Verify result for arbitrary test node.
"""
node = Node("test_node", a=1, b=2)
assert node.node_name == "test_node"
assert node.node_name == "test_node" # TODO CHANGE TO ID
assert node.a == 1
assert node.b == 2
assert node.label is None
Expand All @@ -22,11 +22,11 @@ def test_node_no_inputs():
Verify result for test node with no inputs.
"""
node = Node("test_node")
assert node.node_name == "test_node"
assert node.node_name == "test_node" # TODO CHANGE TO ID
assert node() == ("test_node", {})


def test_node_name_type():
def test_node_name_type(): # TODO CHANGE TO ID
"""
Verify error is raised if node name is not a string.
"""
Expand Down
2 changes: 1 addition & 1 deletion uncertainty_engine/api_providers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class WorkflowExecutable(BaseModel):
node_id: Literal["Workflow"]
node_id: Literal["Workflow"] # TODO CHANGE TO ID
inputs: dict[str, Any]


Expand Down
2 changes: 1 addition & 1 deletion uncertainty_engine/api_providers/workflows_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def save(

executable_workflow = (
WorkflowExecutable( # Workflow must be wrapped by this to be executable
node_id="Workflow",
node_id="Workflow", # TODO CHANGE TO ID
inputs={
"external_input_id": workflow.external_input_id,
"graph": workflow.graph,
Expand Down
28 changes: 15 additions & 13 deletions uncertainty_engine/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Job(BaseModel):
Represents a job in the Uncertainty Engine.
"""

node_id: str
node_id: str # TODO CHANGE TO ID
job_id: str


Expand Down Expand Up @@ -178,7 +178,7 @@ def list_nodes(self, category: Optional[str] = None) -> list:

return node_list

def get_node_info(self, node: str) -> NodeInfo:
def get_node_info(self, node: str) -> NodeInfo: # TODO CHANGE TO ID
"""
Get information about a specific node.

Expand All @@ -189,20 +189,20 @@ def get_node_info(self, node: str) -> NodeInfo:
Information about the node as a NodeInfo object.
"""

node_info = self.core_api.get(f"/nodes/{node}")
node_info = self.core_api.get(f"/nodes/{node}") # TODO CHANGE TO ID
return NodeInfo(**node_info)

def queue_node(
self,
node: Union[str, Node],
node: Union[str, Node], # TODO CHANGE TO ID
inputs: Optional[dict[str, Any]] = None,
input: Optional[dict[str, Any]] = None,
) -> Job:
"""
Queue a node for execution.

Args:
node: The name of the node to execute or the node object itself.
node: The name of the node to execute or the node object itself. # TODO CHANGE TO ID
inputs: The input data for the node. If the node is defined by its name,
this is required. Defaults to ``None``.
input: **DEPRECATED** The input data for the node. Use `inputs` instead.
Expand All @@ -214,34 +214,34 @@ def queue_node(
# TODO: Remove once `input` is removed and make `inputs` required
final_inputs = handle_input_deprecation(input, inputs)

if isinstance(node, Node):
node, final_inputs = node()
elif isinstance(node, str) and final_inputs is None:
if isinstance(node, Node): # TODO CHANGE TO ID
node, final_inputs = node() # TODO CHANGE TO ID
elif isinstance(node, str) and final_inputs is None: # TODO CHANGE TO ID
raise ValueError(
"Input data/parameters are required when specifying a node by name."
)

job_id = self.core_api.post(
"/nodes/queue",
{
"node_id": node,
"node_id": node, # TODO CHANGE TO ID
"inputs": final_inputs,
},
)

return Job(node_id=node, job_id=job_id)
return Job(node_id=node, job_id=job_id) # TODO CHANGE TO ID

def run_node(
self,
node: Union[str, Node],
node: Union[str, Node], # TODO CHANGE TO ID
inputs: Optional[dict[str, Any]] = None,
input: Optional[dict[str, Any]] = None,
) -> JobInfo:
"""
Run a node synchronously.

Args:
node: The name of the node to execute or the node object itself.
node: The name of the node to execute or the node object itself. # TODO CHANGE TO ID
inputs: The input data for the node. If the node is defined by its name,
this is required. Defaults to ``None``.
input: **DEPRECATED** The input data for the node. Use `inputs` instead.
Expand Down Expand Up @@ -273,7 +273,9 @@ def job_status(self, job: Job) -> JobInfo:
outputs={'ans': 3.0}
)
"""
response_data = self.core_api.get(f"/nodes/status/{job.node_id}/{job.job_id}")
response_data = self.core_api.get(
f"/nodes/status/{job.node_id}/{job.job_id}"
) # TODO CHANGE TO ID
return JobInfo(**response_data)

def view_tokens(self) -> int:
Expand Down
11 changes: 7 additions & 4 deletions uncertainty_engine/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ def add_node(

node_input_dict = dict()
for ki, vi in node.__dict__.items():
if ki not in ["node_name", "label"]:
if ki not in ["node_name", "label"]: # TODO CHANGE TO ID
if isinstance(vi, Handle):
node_input_dict[ki] = vi.model_dump()
else:
node_input_dict[ki] = {
"node_name": self.external_input_id,
"node_name": self.external_input_id, # TODO CHANGE TO ID
"node_handle": f"{label}_{ki}",
}
self.external_input[f"{label}_{ki}"] = vi
Expand All @@ -71,7 +71,10 @@ def add_node(
if ki not in ["self", "label"]
}

self.nodes["nodes"][label] = {"type": node.node_name, "inputs": node_input_dict}
self.nodes["nodes"][label] = {
"type": node.node_name,
"inputs": node_input_dict,
} # TODO CHANGE TO ID

def add_nodes_from(self, nodes: list[Node]) -> None:
"""
Expand All @@ -96,7 +99,7 @@ def add_edge(
target_key: The input key of the target node.
"""
self.nodes["nodes"][target]["inputs"][target_key] = {
"node_name": source,
"node_name": source, # TODO CHANGE TO ID
"node_handle": source_key,
}

Expand Down
14 changes: 8 additions & 6 deletions uncertainty_engine/nodes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ class Node:
A generic representation of a node in the Uncertainty Engine.

Args:
node_name: The name of the node.
node_name: The name of the node. # TODO CHANGE TO ID
label: A human-readable label for the node. Defaults to None.
**kwargs: Arbitrary keyword arguments representing the input parameters of the node.

Example:
>>> add_node = Node(
... node_name="Add",
... node_name="Add", # TODO CHANGE TO ID
... lhs=1,
... rhs=2,
... )
>>> add_node()
('Add', {'lhs': 1, 'rhs': 2})
"""

def __init__(self, node_name: str, label: Optional[str] = None, **kwargs):
self.node_name = node_name
def __init__(
self, node_name: str, label: Optional[str] = None, **kwargs
): # TODO CHANGE TO ID
self.node_name = node_name # TODO CHANGE TO ID
self.label = label
for key, value in kwargs.items():
setattr(self, key, value)
Expand All @@ -41,9 +43,9 @@ def __call__(self) -> tuple[str, dict]:
input = {
key: getattr(self, key)
for key in self.__dict__
if key not in ["node_name", "label"]
if key not in ["node_name", "label"] # TODO CHANGE TO ID
}
return self.node_name, input
return self.node_name, input # TODO CHANGE TO ID

def make_handle(self, output_name: str) -> Handle:
"""
Expand Down
2 changes: 1 addition & 1 deletion uncertainty_engine/nodes/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(
label: Optional[str] = None,
):
super().__init__(
node_name=self.node_name,
node_name=self.node_name, # TODO CHANGE TO ID
label=label,
lhs=lhs,
rhs=rhs,
Expand Down
10 changes: 5 additions & 5 deletions uncertainty_engine/nodes/sensor_designer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BuildSensorDesigner(Node):
sigma: The uncertainty of the sensor data. If a float, the same uncertainty is applied to all sensors.
"""

node_name: str = "BuildSensorDesigner"
node_name: str = "BuildSensorDesigner" # TODO CHANGE TO ID

def __init__(
self,
Expand Down Expand Up @@ -50,7 +50,7 @@ def __init__(
quantities_of_interest_data_processed = None

super().__init__(
node_name=self.node_name,
node_name=self.node_name, # TODO CHANGE TO ID
label=label,
sensor_data=sensor_data_processed,
quantities_of_interest_data=quantities_of_interest_data_processed,
Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(
).model_dump()

super().__init__(
node_name=self.node_name,
node_name=self.node_name, # TODO CHANGE TO ID
label=label,
sensor_designer=sensor_designer_processed,
num_sensors=num_sensors,
Expand All @@ -105,7 +105,7 @@ class ScoreSensorDesign(Node):
design: A list of sensors that make up the design.
"""

node_name: str = "ScoreSensorDesign"
node_name: str = "ScoreSensorDesign" # TODO CHANGE TO ID

def __init__(
self,
Expand All @@ -122,7 +122,7 @@ def __init__(
).model_dump()

super().__init__(
node_name=self.node_name,
node_name=self.node_name, # TODO CHANGE TO ID
label=label,
sensor_designer=sensor_designer_processed,
design=design,
Expand Down
6 changes: 3 additions & 3 deletions uncertainty_engine/nodes/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ class Workflow(Node):
... graph=graph.nodes,
... inputs=graph.external_input,
... requested_output={
... "Result": {"node_name": "Download", "node_handle": "file"}
... "Result": {"node_name": "Download", "node_handle": "file"} # TODO CHANGE TO ID
... }
... )
>>> client.queue_node(workflow)
"<job_id>"
"""

node_name: str = "Workflow"
node_name: str = "Workflow" # TODO CHANGE TO ID

def __init__(
self,
Expand All @@ -58,7 +58,7 @@ def __init__(
self.inputs = final_inputs

super().__init__(
node_name=self.node_name,
node_name=self.node_name, # TODO CHANGE TO ID
external_input_id=external_input_id,
graph=graph,
inputs=final_inputs,
Expand Down
Loading