-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: modularize file state (#126)
- Loading branch information
1 parent
2ee606f
commit 08f30ae
Showing
63 changed files
with
5,523 additions
and
1,696 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,6 @@ jahs_bench_data/ | |
|
||
# MacOS | ||
*.DS_Store | ||
|
||
# Yaml tests | ||
path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
"""Environment variable parsing for the state.""" | ||
|
||
from __future__ import annotations | ||
|
||
import os | ||
from typing import Callable, TypeVar | ||
|
||
T = TypeVar("T") | ||
V = TypeVar("V") | ||
|
||
|
||
def get_env(key: str, parse: Callable[[str], T], default: V) -> T | V: | ||
"""Get an environment variable or return a default value.""" | ||
if (e := os.environ.get(key)) is not None: | ||
return parse(e) | ||
|
||
return default | ||
|
||
|
||
def is_nullable(e: str) -> bool: | ||
"""Check if an environment variable is nullable.""" | ||
return e.lower() in ("none", "n", "null") | ||
|
||
|
||
TRIAL_FILELOCK_POLL = get_env( | ||
"NEPS_TRIAL_FILELOCK_POLL", | ||
parse=float, | ||
default=0.05, | ||
) | ||
TRIAL_FILELOCK_TIMEOUT = get_env( | ||
"NEPS_TRIAL_FILELOCK_TIMEOUT", | ||
parse=lambda e: None if is_nullable(e) else float(e), | ||
default=None, | ||
) | ||
|
||
JOBQUEUE_FILELOCK_POLL = get_env( | ||
"NEPS_JOBQUEUE_FILELOCK_POLL", | ||
parse=float, | ||
default=0.05, | ||
) | ||
JOBQUEUE_FILELOCK_TIMEOUT = get_env( | ||
"NEPS_JOBQUEUE_FILELOCK_TIMEOUT", | ||
parse=lambda e: None if is_nullable(e) else float(e), | ||
default=None, | ||
) | ||
|
||
SEED_SNAPSHOT_FILELOCK_POLL = get_env( | ||
"NEPS_SEED_SNAPSHOT_FILELOCK_POLL", | ||
parse=float, | ||
default=0.05, | ||
) | ||
SEED_SNAPSHOT_FILELOCK_TIMEOUT = get_env( | ||
"NEPS_SEED_SNAPSHOT_FILELOCK_TIMEOUT", | ||
parse=lambda e: None if is_nullable(e) else float(e), | ||
default=None, | ||
) | ||
|
||
OPTIMIZER_INFO_FILELOCK_POLL = get_env( | ||
"NEPS_OPTIMIZER_INFO_FILELOCK_POLL", | ||
parse=float, | ||
default=0.05, | ||
) | ||
OPTIMIZER_INFO_FILELOCK_TIMEOUT = get_env( | ||
"NEPS_OPTIMIZER_INFO_FILELOCK_TIMEOUT", | ||
parse=lambda e: None if is_nullable(e) else float(e), | ||
default=None, | ||
) | ||
|
||
OPTIMIZER_STATE_FILELOCK_POLL = get_env( | ||
"NEPS_OPTIMIZER_STATE_FILELOCK_POLL", | ||
parse=float, | ||
default=0.05, | ||
) | ||
OPTIMIZER_STATE_FILELOCK_TIMEOUT = get_env( | ||
"NEPS_OPTIMIZER_STATE_FILELOCK_TIMEOUT", | ||
parse=lambda e: None if is_nullable(e) else float(e), | ||
default=None, | ||
) | ||
|
||
GLOBAL_ERR_FILELOCK_POLL = get_env( | ||
"NEPS_GLOBAL_ERR_FILELOCK_POLL", | ||
parse=float, | ||
default=0.05, | ||
) | ||
GLOBAL_ERR_FILELOCK_TIMEOUT = get_env( | ||
"NEPS_GLOBAL_ERR_FILELOCK_TIMEOUT", | ||
parse=lambda e: None if is_nullable(e) else float(e), | ||
default=None, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""Exceptions for NePS that don't belong in a specific module.""" | ||
|
||
from __future__ import annotations | ||
|
||
|
||
class NePSError(Exception): | ||
"""Base class for all NePS exceptions. | ||
This allows an easier way to catch all NePS exceptions | ||
if we inherit all exceptions from this class. | ||
""" | ||
|
||
|
||
class VersionMismatchError(NePSError): | ||
"""Raised when the version of a resource does not match the expected version.""" | ||
|
||
|
||
class VersionedResourceAlreadyExistsError(NePSError): | ||
"""Raised when a version already exists when trying to create a new versioned | ||
data. | ||
""" | ||
|
||
|
||
class VersionedResourceRemovedError(NePSError): | ||
"""Raised when a version already exists when trying to create a new versioned | ||
data. | ||
""" | ||
|
||
|
||
class VersionedResourceDoesNotExistsError(NePSError): | ||
"""Raised when a versioned resource does not exist at a location.""" | ||
|
||
|
||
class LockFailedError(NePSError): | ||
"""Raised when a lock cannot be acquired.""" | ||
|
||
|
||
class TrialAlreadyExistsError(VersionedResourceAlreadyExistsError): | ||
"""Raised when a trial already exists in the store.""" | ||
|
||
|
||
class TrialNotFoundError(VersionedResourceDoesNotExistsError): | ||
"""Raised when a trial already exists in the store.""" | ||
|
||
|
||
class WorkerFailedToGetPendingTrialsError(NePSError): | ||
"""Raised when a worker failed to get pending trials.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.