Skip to content

Commit

Permalink
chore: add test script
Browse files Browse the repository at this point in the history
Signed-off-by: weiwee <wbwmat@gmail.com>
  • Loading branch information
sagewe committed Sep 22, 2022
1 parent c0f071a commit c81cb71
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Empty file removed python/fate/__init__.py
Empty file.
43 changes: 43 additions & 0 deletions python/test/test_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
def host(federation_id, local_party, parties):
from fate.arch.context import Context

ctx = Context("guest")
ctx.init_computing()
ctx.init_federation(federation_id, local_party=local_party, parties=parties)
with ctx.sub_ctx("predict") as sub_ctx:
sub_ctx.log.debug("ctx inited")
loss = 0.2
sub_ctx.guest.push("loss", loss)
guest_loss = sub_ctx.guest.pull("loss").unwrap()
sub_ctx.summary.add("guest_loss", guest_loss)
ctx.log.debug(f"{sub_ctx.summary.summary}")


def guest(federation_id, local_party, parties):
from fate.arch.context import Context

ctx = Context("host")
ctx.init_computing()
ctx.init_federation(federation_id, local_party=local_party, parties=parties)
with ctx.sub_ctx("predict") as sub_ctx:
sub_ctx.log.error("ctx inited")
loss = 0.1
sub_ctx.hosts.push("loss", loss)
host_loss = sub_ctx.hosts(0).pull("loss").unwrap()
sub_ctx.summary.add("host_loss", host_loss)
ctx.log.debug(f"{sub_ctx.summary.summary}")


if __name__ == "__main__":
from multiprocessing import Process

federation_id = "federation_id"
guest_party = ("guest", "guest_party_id")
host_party = ("host", "host_party_id")
parties = [guest_party, host_party]
p_guest = Process(target=guest, args=(federation_id, guest_party, parties))
p_host = Process(target=host, args=(federation_id, host_party, parties))
p_guest.start()
p_host.start()
p_guest.join()
p_host.join()

0 comments on commit c81cb71

Please sign in to comment.