Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance the value error when missing a reqiured param. #145

Merged
merged 4 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fed/_private/fed_call_holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def options(self, **options):
return self

def internal_remote(self, *args, **kwargs):
if not self._node_party:
raise ValueError("You should specify a party name on the fed actor.")

# Generate a new fed task id for this call.
fed_task_id = get_global_context().next_seq_id()
if self._party == self._node_party:
Expand Down
6 changes: 3 additions & 3 deletions fed/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ def options(self, **options):
return self

def remote(self, *args, **kwargs):
assert (
self._node_party is not None
), "A fed function should be specified within a party to execute."
if not self._node_party:
raise ValueError("You should specify a party name on the fed function.")

return self._fed_call_holder.internal_remote(*args, **kwargs)

def _execute_impl(self, args, kwargs):
Expand Down
24 changes: 24 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,30 @@ def test_fed_apis():
assert p_alice.exitcode == 0


def test_miss_party_name_on_actor():
def run():
compatible_utils.init_ray(address='local')
cluster = {
'alice': {'address': '127.0.0.1:11012'},
}
fed.init(cluster=cluster, party="alice")

@fed.remote
class MyActor:
pass

with pytest.raises(ValueError):
MyActor.remote()

fed.shutdown()
ray.shutdown()

p_alice = multiprocessing.Process(target=run)
p_alice.start()
p_alice.join()
assert p_alice.exitcode == 0


if __name__ == "__main__":
import sys

Expand Down