Skip to content

Commit

Permalink
log dir in config and remove verify cluster from serve.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhsmit committed Sep 26, 2022
1 parent eb14500 commit dc82a4a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
9 changes: 8 additions & 1 deletion pyhdx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ def assets_dir(self) -> Path:

return assets_dir

@property
def log_dir(self) -> Path:
spec_path = self.conf.server.log_dir
log_dir = Path(spec_path.replace("~", str(Path().home())))

return log_dir

@property
def TORCH_DTYPE(self) -> Union[torch.float64, torch.float32]:
dtype = self.conf.fitting.dtype
Expand Down Expand Up @@ -125,4 +132,4 @@ def valid_config() -> bool:


cfg = PyHDXConfig()
cfg.set_config(conf)
cfg.set_config(conf)
3 changes: 2 additions & 1 deletion pyhdx/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ cluster:

server:
assets_dir: ~/.pyhdx/assets
log_dir: ~/.pyhdx/logs

fitting:
dtype: float64
Expand All @@ -25,4 +26,4 @@ plotting:
dG_aspect: 2.5
linear_bars_aspect: 30
loss_aspect: 2.5
rainbowclouds_aspect: 4
rainbowclouds_aspect: 4
16 changes: 14 additions & 2 deletions pyhdx/local_cluster.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from __future__ import annotations

import argparse
import asyncio
import time
from asyncio import Future
from typing import Callable, Iterable, Any

from dask.distributed import LocalCluster, Client
from distributed import connect

from pyhdx.config import cfg
from pyhdx.support import select_config
Expand Down Expand Up @@ -75,12 +77,22 @@ def default_cluster(**kwargs):
def verify_cluster(scheduler_address, timeout="2s"):
"""Check if a valid dask scheduler is running at the provided scheduler_address"""
try:
client = Client(scheduler_address, timeout=timeout)
asyncio.run(connect(scheduler_address, timeout=timeout))
return True
except (TimeoutError, IOError):
except (TimeoutError, OSError):
return False


def verify_cluster_async(scheduler_address, timeout="2s"):
"""Check if a valid dask scheduler is running at the provided scheduler_address"""
try:
asyncio.run(connect(scheduler_address, timeout=timeout))
return True
except (TimeoutError, OSError):
return False



def blocking_cluster():
"""Start a dask LocalCluster and block until iterrupted"""
parser = argparse.ArgumentParser(description="Start a new Dask local cluster")
Expand Down
15 changes: 8 additions & 7 deletions pyhdx/web/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ def run_apps():
np.random.seed(43)
torch.manual_seed(43)

scheduler_address = cfg.cluster.scheduler_address
if not verify_cluster(scheduler_address):
print(
f"No valid Dask scheduler found at specified address: '{scheduler_address}'"
)
# Checking clusters like this interferes with starting the server somehow
# scheduler_address = cfg.cluster.scheduler_address
# if not verify_cluster(scheduler_address):
# print(
# f"No valid Dask scheduler found at specified address: '{scheduler_address}'"
# )

log_root_dir = Path.home() / ".pyhdx" / "logs"
log_root_dir = cfg.log_dir
log_dir = log_root_dir / datetime.datetime.now().strftime("%Y%m%d")
log_dir.mkdir(
parents=True, exist_ok=True
) # catch error when log dir does not exist
)
root_log = logging.getLogger("pyhdx")
root_log.setLevel(logging.DEBUG)

Expand Down

0 comments on commit dc82a4a

Please sign in to comment.