Skip to content

Commit

Permalink
docs: add api doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouaihui committed Jan 9, 2024
1 parent 9dfe4c9 commit 8022b48
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 9 deletions.
21 changes: 17 additions & 4 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
API
===
===========

.. autosummary::
:toctree: generated
fed.api module
--------------

RayFed
.. automodule:: fed
:members: init, remote, get, shutdown, kill

fed.config module
-----------------

.. automodule:: fed.config
:members: ClusterConfig, CrossSiloMessageConfig, GrpcCrossSiloMessageConfig

.. Module contents
.. ---------------
.. .. automodule:: fed
.. :members:
4 changes: 1 addition & 3 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ To use RayFed, first install it using pip:
Starting RayFed
---------------

To start a RayFed application, you can use ``fed.init()`` function:

.. autofunction:: fed.init
To start a RayFed application, you can use ``fed.init`` function:

For example:

Expand Down
68 changes: 68 additions & 0 deletions fed/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def init(
addresses: optional; a dict describes the addresses configurations. E.g.
.. code:: python
{
# The address that can be connected to `alice` by other parties.
'alice': '127.0.0.1:10001',
Expand Down Expand Up @@ -111,6 +112,7 @@ def init(
Example:
.. code:: python
{
"cross_silo_comm": {
"messages_max_size_in_bytes": 500*1024,
Expand All @@ -125,6 +127,7 @@ def init(
For alice,
.. code:: python
{
"ca_cert": "root ca cert of other parties.",
"cert": "alice's server cert",
Expand All @@ -134,6 +137,7 @@ def init(
For bob,
.. code:: python
{
"ca_cert": "root ca cert of other parties.",
"cert": "bob's server cert",
Expand Down Expand Up @@ -419,6 +423,63 @@ def remote(self, *cls_args, **cls_kwargs):

# This is the decorator `@fed.remote`
def remote(*args, **kwargs):
"""Defines a remote function or an actor class.
This function can be used as a decorator with no arguments
to define a remote function or actor as follows:
.. testcode::
import fed
@fed.remote
def f(a, b, c):
return a + b + c
object_ref = f.part('alice').remote(1, 2, 3)
result = fed.get(object_ref)
assert result == (1 + 2 + 3)
@fed.remote
class Foo:
def __init__(self, arg):
self.x = arg
def method(self, a):
return self.x + a
actor_handle = Foo.party('alice').remote(123)
object_ref = actor_handle.method.remote(321)
result = fed.get(object_ref)
assert result == (123 + 321)
Equivalently, use a function call to create a remote function or actor.
.. testcode::
def g(a, b, c):
return a + b + c
remote_g = fed.remote(g)
object_ref = remote_g.party('alice').remote(1, 2, 3)
assert fed.get(object_ref) == (1 + 2 + 3)
class Bar:
def __init__(self, arg):
self.x = arg
def method(self, a):
return self.x + a
RemoteBar = fed.remote(Bar)
actor_handle = RemoteBar.party('alice').remote(123)
object_ref = actor_handle.method.remote(321)
result = fed.get(object_ref)
assert result == (123 + 321)
It can also be used with specific keyword arguments just same as ray options.
"""
def _make_fed_remote(function_or_class, **options):
if inspect.isfunction(function_or_class) or fed_utils.is_cython(
function_or_class
Expand Down Expand Up @@ -518,6 +579,13 @@ def get(


def kill(actor: FedActorHandle, *, no_restart=True):
"""Kill an actor forcefully.
Args:
actor: Handle to the actor to kill.
no_restart: Whether or not this actor should be restarted if
it's a restartable actor.
"""
job_name = get_global_context().get_job_name()
current_party = _get_party(job_name)
if actor._node_party == current_party:
Expand Down
7 changes: 5 additions & 2 deletions fed/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class GrpcCrossSiloMessageConfig(CrossSiloMessageConfig):
`retry-policy <https://github.com/grpc/proposal/blob/master/A6-client-retries.md#retry-policy>`_. # noqa
.. code:: python
{
"maxAttempts": 4,
"initialBackoff": "0.1s",
Expand All @@ -167,8 +168,10 @@ class GrpcCrossSiloMessageConfig(CrossSiloMessageConfig):
"UNAVAILABLE"
]
}
grpc_channel_options: A list of tuples to store GRPC channel options,
e.g. [
grpc_channel_options: A list of tuples to store GRPC channel options, e.g.
.. code:: python
[
('grpc.enable_retries', 1),
('grpc.max_send_message_length', 50 * 1024 * 1024)
]
Expand Down

0 comments on commit 8022b48

Please sign in to comment.