-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
starting work on providing a ray protocol for distributed composites/…
…processes
- Loading branch information
1 parent
bd873d3
commit 98ff5e7
Showing
5 changed files
with
139 additions
and
2 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
Empty file.
File renamed without changes.
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,66 @@ | ||
""" | ||
=============================================== | ||
Protocols for retrieving processes from address | ||
=============================================== | ||
""" | ||
|
||
import importlib | ||
import sys | ||
from process_bigraph.composite import Process | ||
from process_bigraph.registry import protocol_registry | ||
|
||
import ray | ||
|
||
|
||
def local_lookup_module(address): | ||
"""Local Module Protocol | ||
Retrieves local module | ||
""" | ||
if '.' in address: | ||
module_name, class_name = address.rsplit('.', 1) | ||
module = importlib.import_module(module_name) | ||
return getattr(module, class_name) | ||
else: | ||
return getattr(sys.modules[__name__], address) | ||
|
||
|
||
def local_lookup_registry(address): | ||
"""Process Registry Protocol | ||
Retrieves from the process registry | ||
""" | ||
return process_registry.access(address) | ||
|
||
|
||
@ray.remote | ||
class RayProcess(Process): | ||
pass | ||
|
||
|
||
class RayProcessFactory: | ||
def __init__(self, instantiate): | ||
self.instantiate = instantiate | ||
|
||
|
||
def __call__(self, config): | ||
self.instantiate(config) | ||
|
||
|
||
def ray_lookup(address): | ||
"""Ray Lookup Protocol | ||
Retrieves processes that operate through Ray's distributed actor system, from the process registry or from a local module | ||
""" | ||
if address[0] == '!': | ||
instantiate = local_lookup_module(address[1:]) | ||
else: | ||
instantiate = local_lookup_registry(address) | ||
|
||
factory = RayProcessFactory(instantiate) | ||
return factory | ||
|
||
|
||
protocol_registry.register('ray', ray_lookup) | ||
|
||
|
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