Skip to content

Commit dc82a4a

Browse files
committed
log dir in config and remove verify cluster from serve.py
1 parent eb14500 commit dc82a4a

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

pyhdx/config.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ def assets_dir(self) -> Path:
6868

6969
return assets_dir
7070

71+
@property
72+
def log_dir(self) -> Path:
73+
spec_path = self.conf.server.log_dir
74+
log_dir = Path(spec_path.replace("~", str(Path().home())))
75+
76+
return log_dir
77+
7178
@property
7279
def TORCH_DTYPE(self) -> Union[torch.float64, torch.float32]:
7380
dtype = self.conf.fitting.dtype
@@ -125,4 +132,4 @@ def valid_config() -> bool:
125132

126133

127134
cfg = PyHDXConfig()
128-
cfg.set_config(conf)
135+
cfg.set_config(conf)

pyhdx/config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ cluster:
44

55
server:
66
assets_dir: ~/.pyhdx/assets
7+
log_dir: ~/.pyhdx/logs
78

89
fitting:
910
dtype: float64
@@ -25,4 +26,4 @@ plotting:
2526
dG_aspect: 2.5
2627
linear_bars_aspect: 30
2728
loss_aspect: 2.5
28-
rainbowclouds_aspect: 4
29+
rainbowclouds_aspect: 4

pyhdx/local_cluster.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from __future__ import annotations
22

33
import argparse
4+
import asyncio
45
import time
56
from asyncio import Future
67
from typing import Callable, Iterable, Any
78

89
from dask.distributed import LocalCluster, Client
10+
from distributed import connect
911

1012
from pyhdx.config import cfg
1113
from pyhdx.support import select_config
@@ -75,12 +77,22 @@ def default_cluster(**kwargs):
7577
def verify_cluster(scheduler_address, timeout="2s"):
7678
"""Check if a valid dask scheduler is running at the provided scheduler_address"""
7779
try:
78-
client = Client(scheduler_address, timeout=timeout)
80+
asyncio.run(connect(scheduler_address, timeout=timeout))
7981
return True
80-
except (TimeoutError, IOError):
82+
except (TimeoutError, OSError):
83+
return False
84+
85+
86+
def verify_cluster_async(scheduler_address, timeout="2s"):
87+
"""Check if a valid dask scheduler is running at the provided scheduler_address"""
88+
try:
89+
asyncio.run(connect(scheduler_address, timeout=timeout))
90+
return True
91+
except (TimeoutError, OSError):
8192
return False
8293

8394

95+
8496
def blocking_cluster():
8597
"""Start a dask LocalCluster and block until iterrupted"""
8698
parser = argparse.ArgumentParser(description="Start a new Dask local cluster")

pyhdx/web/serve.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,18 @@ def run_apps():
2424
np.random.seed(43)
2525
torch.manual_seed(43)
2626

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

33-
log_root_dir = Path.home() / ".pyhdx" / "logs"
34+
log_root_dir = cfg.log_dir
3435
log_dir = log_root_dir / datetime.datetime.now().strftime("%Y%m%d")
3536
log_dir.mkdir(
3637
parents=True, exist_ok=True
37-
) # catch error when log dir does not exist
38+
)
3839
root_log = logging.getLogger("pyhdx")
3940
root_log.setLevel(logging.DEBUG)
4041

0 commit comments

Comments
 (0)