Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
timeout-minutes: 30
strategy:
matrix:
python-version: ['3.10', '3.12', '3.13']
python-version: ['3.10', '3.12', '3.13', '3.14']
aiida-version: ['stable']

services:
Expand Down
11 changes: 6 additions & 5 deletions src/aiida_pythonjob/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)

from aiida.common.exceptions import NotExistent
from aiida.orm import Computer, InstalledCode, Str, User, load_code, load_computer
from aiida.orm import Computer, InstalledCode, User, load_code, load_computer
from node_graph.socket_meta import SocketMeta
from node_graph.socket_spec import SocketSpec
from node_graph.utils.struct_utils import is_structured_instance, structured_to_dict
Expand Down Expand Up @@ -110,12 +110,13 @@ def get_or_create_code(
) -> InstalledCode:
"""Try to load code, create if not exit."""

computer_label = computer.label if isinstance(computer, Computer) else computer

try:
return load_code(f"{label}@{computer}")
return load_code(f"{label}@{computer_label}")
except NotExistent:
description = f"Code on computer: {computer}"
computer = computer.value if isinstance(computer, Str) else computer
computer = load_computer(computer)
description = f"Code on computer: {computer_label}"
computer = load_computer(computer_label)
filepath_executable = filepath_executable or label
code = InstalledCode(
computer=computer,
Expand Down
19 changes: 18 additions & 1 deletion tests/test_pythonjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ def add(x, y):
with pytest.raises(ValueError, match="Either `function` or `function_data` must be provided."):
prepare_pythonjob_inputs(
function_inputs={"x": 1, "y": 2},
computer=fixture_localhost,
)
with pytest.raises(ValueError, match="Only one of `function` or `function_data` should be provided."):
prepare_pythonjob_inputs(
function=add,
function_data={"module_path": "math", "name": "sqrt", "is_pickle": False},
computer=fixture_localhost,
)


Expand All @@ -34,6 +36,7 @@ def add(x, y):
prepare_pythonjob_inputs(
function=add,
function_inputs={"x": 1},
computer=fixture_localhost,
)


Expand All @@ -47,6 +50,7 @@ def add(x, y):
add,
function_inputs={"x": 1, "y": 2},
process_label="add",
computer=fixture_localhost,
)
result, node = run_get_node(PythonJob, **inputs)

Expand All @@ -64,6 +68,7 @@ def add(x, y):
add,
function_inputs={"x": 1, "y": 2},
outputs_spec=spec.namespace(sum=Any, diff=Any),
computer=fixture_localhost,
)
result, node = run_get_node(PythonJob, **inputs)

Expand All @@ -80,6 +85,7 @@ def test_importable_function(fixture_localhost):
inputs = prepare_pythonjob_inputs(
add,
function_inputs={"x": 1, "y": 2},
computer=fixture_localhost,
)
result, node = run_get_node(PythonJob, **inputs)
print("result: ", result)
Expand All @@ -98,6 +104,7 @@ def add(x, y=1, **kwargs):
inputs = prepare_pythonjob_inputs(
add,
function_inputs={"x": 1, "y": 2, "a": 3, "b": 4},
computer=fixture_localhost,
)
result, node = run_get_node(PythonJob, **inputs)
assert result["result"].value == 10
Expand All @@ -120,6 +127,7 @@ def myfunc(x, y):
add_multiply=spec.namespace(add=spec.dynamic(Any), multiply=Any),
minus=Any,
),
computer=fixture_localhost,
)
result, node = run_get_node(PythonJob, **inputs)
print("result: ", result)
Expand All @@ -146,13 +154,15 @@ def multiply(x, y):
inputs1 = prepare_pythonjob_inputs(
add,
function_inputs={"x": 1, "y": 2},
computer=fixture_localhost,
)
result1, node1 = run_get_node(PythonJob, inputs=inputs1)

inputs2 = prepare_pythonjob_inputs(
multiply,
function_inputs={"x": 1, "y": 2},
parent_folder=result1["remote_folder"],
computer=fixture_localhost,
)
result2, node2 = run_get_node(PythonJob, inputs=inputs2)
print("result2: ", result2)
Expand All @@ -179,6 +189,7 @@ def multiply(x, y):
multiply,
function_inputs={"x": 1, "y": 2},
parent_folder=parent_folder,
computer=fixture_localhost,
)
result2, node2 = run_get_node(PythonJob, inputs=inputs2)

Expand Down Expand Up @@ -220,6 +231,7 @@ def add():
"another_input.txt": single_file_data,
"inputs_folder": input_folder,
},
computer=fixture_localhost,
)
result, node = run_get_node(PythonJob, inputs=inputs)
assert result["result"].value == 9
Expand All @@ -242,6 +254,7 @@ def add(x, y):
"additional_retrieve_list": ["result.txt"],
}
},
computer=fixture_localhost,
)
result, node = run_get_node(PythonJob, inputs=inputs)
# ------------------------- Submit the calculation -------------------
Expand All @@ -262,12 +275,13 @@ def multiply(x_folder_name, y):
x = int(f.read())
return x * y

inputs = prepare_pythonjob_inputs(add, function_inputs={"x": 1, "y": 2})
inputs = prepare_pythonjob_inputs(add, function_inputs={"x": 1, "y": 2}, computer=fixture_localhost)
result, node = run_get_node(PythonJob, inputs=inputs)
inputs = prepare_pythonjob_inputs(
multiply,
function_inputs={"x_folder_name": "x_folder_name", "y": 2},
copy_files={"x_folder_name": result["remote_folder"]},
computer=fixture_localhost,
)
result, node = run_get_node(PythonJob, inputs=inputs)
assert result["result"].value == 6
Expand All @@ -287,6 +301,7 @@ def add(x: array, y: array) -> array:
inputs = prepare_pythonjob_inputs(
add,
function_inputs={"x": array([1, 1]), "y": array([1, -2])},
computer=fixture_localhost,
)
result, node = run_get_node(PythonJob, inputs=inputs)
assert node.exit_status == 410
Expand All @@ -303,6 +318,7 @@ def add(x, y):
inputs = prepare_pythonjob_inputs(
add,
function_inputs={"x": 2, "y": 3},
computer=fixture_localhost,
)
result, node = run_get_node(PythonJob, **inputs)
assert result["result"].value == 8
Expand All @@ -320,6 +336,7 @@ def add(x, y):
add,
function_inputs={"x": 1, "y": 2},
process_label="add",
computer=fixture_localhost,
)
node = submit(PythonJob, **inputs, wait=True)

Expand Down
Loading