Skip to content

Commit

Permalink
Just some simple refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
d-krupke committed Feb 27, 2024
1 parent 84e4a13 commit 09fa0f5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
13 changes: 6 additions & 7 deletions src/slurminade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def clean_up():
- guard.py: Contains code to prevent you accidentally DDoSing your infrastructure.
- options.py: Contains a simple data structure to save slurm options.
"""
# set default logging
import logging
import sys

# Set up the root logger to print to stdout by default
logging.basicConfig(level=logging.INFO, stream=sys.stdout)

# flake8: noqa F401
from .function import slurmify, shell
Expand Down Expand Up @@ -97,10 +103,3 @@ def clean_up():
"shell",
"node_setup",
]

# set default logging
import logging
import sys

# Set up the root logger to print to stdout by default
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
5 changes: 4 additions & 1 deletion src/slurminade/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import json
import logging
import os.path
import typing
from pathlib import Path
Expand All @@ -20,7 +21,9 @@ def _load_conf(path: Path):
else:
return {}
except Exception as e:
print(f"slurminade could not open default configuration {path}!\n{e!s}")
logging.getLogger("slurminade").error(
f"slurminade could not open default configuration {path}!\n{e!s}"
)
return {}


Expand Down
3 changes: 1 addition & 2 deletions src/slurminade/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
from .function_call import FunctionCall
from .function_map import FunctionMap, get_entry_point
from .guard import dispatch_guard
from .job_reference import JobReference
from .options import SlurmOptions

# MAX_ARG_STRLEN on a Linux system with PAGE_SIZE 4096 is 131072
DEFAULT_MAX_ARG_LENGTH = 100000

from .job_reference import JobReference


class Dispatcher(abc.ABC):
"""
Expand Down
9 changes: 4 additions & 5 deletions src/slurminade/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,12 @@ def __call__(self, *args, **kwargs):
"""
if self.call_policy == CallPolicy.LOCALLY:
return self.run_locally(*args, **kwargs)
elif self.call_policy == CallPolicy.DISTRIBUTED:
if self.call_policy == CallPolicy.DISTRIBUTED:
return self.distribute(*args, **kwargs)
elif self.call_policy == CallPolicy.DISTRIBUTED_BLOCKING:
if self.call_policy == CallPolicy.DISTRIBUTED_BLOCKING:
return self.distribute_and_wait(*args, **kwargs)
else:
msg = "Unknown call policy."
raise RuntimeError(msg)
msg = "Unknown call policy."
raise RuntimeError(msg)

def get_entry_point(self) -> Path:
"""
Expand Down
4 changes: 2 additions & 2 deletions src/slurminade/function_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class FunctionMap:
# The slurm node just executes the file content of a script, so the file name is lost.
# slurminade will set this value in the beginning to reconstruct it.
entry_point: typing.Optional[str] = None
_data = {}
_ids = set()
_data: typing.ClassVar[typing.Dict[str, typing.Callable]] = {}
_ids: typing.ClassVar[typing.Set[str]] = set()

@staticmethod
def get_id(func: typing.Callable) -> str:
Expand Down
5 changes: 3 additions & 2 deletions src/slurminade/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class SlurmOptions(dict):
def _items(self):
for k, v in self.items():
if isinstance(v, dict):
v = SlurmOptions(**v)
yield k, v
yield k, SlurmOptions(**v)
else:
yield k, v

def __hash__(self):
return hash(tuple(sorted(hash((k, v)) for k, v in self._items())))
Expand Down

0 comments on commit 09fa0f5

Please sign in to comment.