forked from RosettaCommons/rosetta
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4179 from RosettaCommons/klimaj/init_distributed
Adding a pyrosetta.distributed.init() function Old repository SHA1: e7209884267213089de8e6409f3e9554dfae0b3e
- Loading branch information
Showing
3 changed files
with
32 additions
and
18 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 |
---|---|---|
@@ -1,3 +1,12 @@ | ||
# :noTabs=true: | ||
# | ||
# (c) Copyright Rosetta Commons Member Institutions. | ||
# (c) This file is part of the Rosetta software suite and is made available under license. | ||
# (c) The Rosetta software is developed by the contributing members of the Rosetta Commons. | ||
# (c) For more information, see http://www.rosettacommons.org. | ||
# (c) Questions about this can be addressed to University of Washington CoMotion, email: [email protected]. | ||
|
||
|
||
import functools | ||
import logging | ||
import threading | ||
|
@@ -9,13 +18,20 @@ | |
|
||
_logger = logging.getLogger("pyrosetta.distributed") | ||
|
||
__all__ = ["maybe_init", "requires_init", "with_lock"] | ||
__all__ = ["init", "maybe_init", "requires_init", "with_lock"] | ||
|
||
# Access lock for any non-threadsafe calls into rosetta internals. | ||
# Intended to provide a threadsafe api surface area to `distributed`. | ||
_access_lock = threading.RLock() | ||
|
||
|
||
def _normflags(flags): | ||
"""Normalize tuple/list/str of flags into str.""" | ||
if not isinstance(flags, str): | ||
flags = " ".join(flags) | ||
return " ".join(" ".join([line.split("#")[0] for line in flags.split("\n")]).split()) | ||
|
||
|
||
def with_lock(func): | ||
"""Function decorator that protects access to rosetta internals.""" | ||
@functools.wraps(func) | ||
|
@@ -71,3 +87,10 @@ def fwrap(*args, **kwargs): | |
return func(*args, **kwargs) | ||
|
||
return fwrap | ||
|
||
|
||
def init(options=None, **kwargs): | ||
"""Initialize PyRosetta with command line options.""" | ||
if options and ("extra_options" not in kwargs): | ||
kwargs["extra_options"] = _normflags(options) | ||
maybe_init(**kwargs) |
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