converge_sync.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright 2019 The FATE Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. #
  15. from federatedml.util import consts
  16. class Arbiter(object):
  17. # noinspection PyAttributeOutsideInit
  18. def _register_convergence(self, is_stopped_transfer):
  19. self._is_stopped_transfer = is_stopped_transfer
  20. def sync_converge_info(self, is_converged, suffix=tuple()):
  21. self._is_stopped_transfer.remote(obj=is_converged, role=consts.HOST, idx=-1, suffix=suffix)
  22. self._is_stopped_transfer.remote(obj=is_converged, role=consts.GUEST, idx=-1, suffix=suffix)
  23. class _Client(object):
  24. # noinspection PyAttributeOutsideInit
  25. def _register_convergence(self, is_stopped_transfer):
  26. self._is_stopped_transfer = is_stopped_transfer
  27. def sync_converge_info(self, suffix=tuple()):
  28. is_converged = self._is_stopped_transfer.get(idx=0, suffix=suffix)
  29. return is_converged
  30. Host = _Client
  31. Guest = _Client