-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds script to import cctbx data to rs (#264)
Co-authored-by: kmdalton <[email protected]>
- Loading branch information
Showing
7 changed files
with
659 additions
and
23 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
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,48 @@ | ||
import logging | ||
import warnings | ||
from contextlib import contextmanager | ||
from importlib.util import find_spec | ||
|
||
|
||
def set_ray_loglevel(level): | ||
logger = logging.getLogger("ray") | ||
logger.setLevel(level) | ||
for handler in logger.handlers: | ||
handler.setLevel(level) | ||
|
||
|
||
def check_for_ray(): | ||
has_ray = True | ||
if find_spec("ray") is None: | ||
has_ray = False | ||
|
||
message = ( | ||
"ray (https://www.ray.io/) is not available..." "Falling back to serial." | ||
) | ||
warnings.warn(message, ImportWarning) | ||
return has_ray | ||
|
||
|
||
def check_for_mpi(): | ||
try: | ||
from mpi4py import MPI | ||
|
||
return True | ||
except Exception as err: | ||
message = ( | ||
f"Failed `from mpi4py import MPI` with {err}. Falling back to serial mode." | ||
) | ||
warnings.warn(message, ImportWarning) | ||
return False | ||
|
||
|
||
@contextmanager | ||
def ray_context(log_level="DEBUG", **ray_kwargs): | ||
import ray | ||
|
||
set_ray_loglevel(log_level) | ||
ray.init(**ray_kwargs) | ||
try: | ||
yield ray | ||
finally: | ||
ray.shutdown() |
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.