Пример #1
0
    def _init_model(self, param):
        super()._init_model(param)
        self.param = param

        self.transfer_variable = HomoTransferVariable()
        secure_aggregate = param.secure_aggregate
        self.aggregator = aggregator.with_role(role=self.role,
                                               transfer_variable=self.transfer_variable,
                                               enable_secure_aggregate=secure_aggregate)
        self.max_iter = param.max_iter
        self.aggregator_iter = 0
Пример #2
0
 def setUp(self) -> None:
     self.transfer_variable = HomoTransferVariable()
     self.job_id = str(uuid.uuid1())
     self.transfer_variable.set_flowid(self.job_id)
Пример #3
0
class TestSyncBase(unittest.TestCase):

    def clean_tables(self):
        from fate_arch.session import computing_session as session
        session.init(job_id=self.job_id)
        try:
            session.cleanup("*", self.job_id, True)
        except EnvironmentError:
            pass
        try:
            session.cleanup("*", self.job_id, False)
        except EnvironmentError:
            pass

    def setUp(self) -> None:
        self.transfer_variable = HomoTransferVariable()
        self.job_id = str(uuid.uuid1())
        self.transfer_variable.set_flowid(self.job_id)

    def tearDown(self) -> None:
        pass
        # self.clean_tables()

    @classmethod
    def _call(cls, job_id, role, transfer_variable, num_hosts, ind, *args):
        role_id = {
            "host": [
                10000 + i for i in range(num_hosts)
            ],
            "guest": [
                9999
            ],
            "arbiter": [
                9999
            ]
        }
        with Session() as session:
            session.init_computing(job_id, computing_type=ComputingType.STANDALONE)
            session.init_federation(job_id,
                                    runtime_conf={
                                        "local": {
                                            "role": role,
                                            "party_id": role_id[role][0] if role != "host" else role_id[role][ind]
                                        },
                                        "role": role_id
                                    })

            return cls.call(role, transfer_variable, ind, *args)

    @classmethod
    def call(cls, role, transfer_variable, ind, *args):
        pass

    @classmethod
    def results(cls, job_id, transfer_variable, num_hosts, *args):
        tasks = []
        with Pool(num_hosts + 2) as p:
            tasks.append(p.apply_async(func=cls._call,
                                       args=(job_id, consts.ARBITER, transfer_variable, num_hosts, 0, *args)))
            tasks.append(p.apply_async(func=cls._call,
                                       args=(job_id, consts.GUEST, transfer_variable, num_hosts, 0, *args)))
            for i in range(num_hosts):
                tasks.append(
                    p.apply_async(func=cls._call,
                                  args=(job_id, consts.HOST, transfer_variable, num_hosts, i, *args)))

            left = list(range(len(tasks)))
            while len(left) > 0:
                time.sleep(0.1)
                tmp = []
                for i in left:
                    if tasks[i].ready():
                        tasks[i] = tasks[i].get()
                    else:
                        tmp.append(i)
                left = tmp

            return tasks

    def run_results(self, num_hosts, *args):
        return self.results(self.job_id, self.transfer_variable, num_hosts, *args)