12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import numpy as np
- from federatedml.secureprotol.spdz.tensor.fixedpoint_numpy import FixedPointTensor
- from federatedml.secureprotol.spdz import SPDZ
- from fate_arch.session import Session
- s = Session()
- guest_party_id = 10000
- host_party_id = 10001
- guest_proxy_ip = "192.168.0.2"
- federation_id = "spdz_demo"
- session_id = "_".join([federation_id, "guest", str(guest_party_id)])
- s.init_computing(session_id)
- s.init_federation(federation_id,
- runtime_conf={
- "local": {"role": "guest", "party_id": guest_party_id},
- "role": {"guest": [guest_party_id], "host": [host_party_id]},
- },
- service_conf={"host": guest_proxy_ip, "port": 9370})
- s.as_global()
- partys = s.parties.all_parties
- data = np.array([[1, 2, 3], [4, 5, 6]])
- with SPDZ() as spdz:
- x = FixedPointTensor.from_source("x", data)
- y = FixedPointTensor.from_source("y", partys[1])
- z = (x + y).get()
- t = (x - y).get()
- print(z)
- print(t)
|