コード例 #1
0
ファイル: combiner.py プロジェクト: ahellander/fedn
    def Report(self, control: fedn.ControlRequest, context):
        """ Descibe current state of the Combiner. """
        response = fedn.ControlResponse()
        print("\n\n\n\n\n GOT CONTROL **REPORT** from Command\n\n\n\n\n",
              flush=True)

        active_clients = self._list_active_clients(
            fedn.Channel.MODEL_UPDATE_REQUESTS)
        nr_active_clients = len(active_clients)

        p = response.parameter.add()
        p.key = "nr_active_clients"
        p.value = str(nr_active_clients)

        p = response.parameter.add()
        p.key = "model_id"
        model_id = self.get_active_model()
        if model_id == None:
            model_id = ""
        p.value = str(model_id)

        p = response.parameter.add()
        p.key = "nr_unprocessed_tasks"
        p.value = str(len(self.combiner.run_configs))

        return response
コード例 #2
0
    def Stop(self, control: fedn.ControlRequest, context):
        """

        :param control:
        :param context:
        :return:
        """
        response = fedn.ControlResponse()
        print("\n\n\n\n\n GOT CONTROL **STOP** from Command\n\n\n\n\n",
              flush=True)
        return response
コード例 #3
0
    def Configure(self, control: fedn.ControlRequest, context):
        """

        :param control:
        :param context:
        :return:
        """
        response = fedn.ControlResponse()
        for parameter in control.parameter:
            setattr(self, parameter.key, parameter.value)
        return response
コード例 #4
0
    def Report(self, control: fedn.ControlRequest, context):
        """ Descibe current state of the Combiner. """

        response = fedn.ControlResponse()
        print("\n\n\n\n\n GOT CONTROL **REPORT** from Command\n\n\n\n\n",
              flush=True)

        active_trainers = self.get_active_trainers()
        p = response.parameter.add()
        p.key = "nr_active_trainers"
        p.value = str(len(active_trainers))

        active_validators = self.get_active_validators()
        p = response.parameter.add()
        p.key = "nr_active_validators"
        p.value = str(len(active_validators))

        active_trainers_ = self.get_active_trainers()
        active_trainers = []
        for client in active_trainers_:
            active_trainers.append(client)
        p = response.parameter.add()
        p.key = "active_trainers"
        p.value = str(active_trainers)

        active_validators_ = self.get_active_validators()
        active_validators = []
        for client in active_validators_:
            active_validators.append(client)
        p = response.parameter.add()
        p.key = "active_validators"
        p.value = str(active_validators)

        p = response.parameter.add()
        p.key = "nr_active_clients"
        p.value = str(len(active_trainers) + len(active_validators))

        p = response.parameter.add()
        p.key = "model_id"
        model_id = self.get_active_model()
        if model_id == None:
            model_id = ""
        p.value = str(model_id)

        p = response.parameter.add()
        p.key = "nr_unprocessed_compute_plans"
        p.value = str(self.control.round_configs.qsize())

        p = response.parameter.add()
        p.key = "name"
        p.value = str(self.id)

        return response
コード例 #5
0
    def Start(self, control: fedn.ControlRequest, context):
        response = fedn.ControlResponse()
        print("\n\n\n GOT CONTROL **START** from Command {}\n\n\n".format(
            control.command),
              flush=True)

        config = {}
        for parameter in control.parameter:
            config.update({parameter.key: parameter.value})
        print(
            "\n\n\n\nSTARTING JOB AT COMBINER WITH {}\n\n\n\n".format(config),
            flush=True)

        job_id = self.combiner.push_run_config(config)
        return response
コード例 #6
0
    def Report(self, control: fedn.ControlRequest, context):
        """ Descibe current state of the Combiner. """

        response = fedn.ControlResponse()
        print("\n\n\n\n\n GOT CONTROL **REPORT** from Command\n\n\n\n\n",
              flush=True)

        active_clients = self._list_active_clients(
            fedn.Channel.MODEL_UPDATE_REQUESTS)
        nr_active_clients = len(active_clients)

        p = response.parameter.add()
        p.key = "nr_active_clients"
        p.value = str(nr_active_clients)

        p = response.parameter.add()
        p.key = "model_id"
        model_id = self.get_active_model()
        if model_id == None:
            model_id = ""
        p.value = str(model_id)

        p = response.parameter.add()
        p.key = "nr_unprocessed_compute_plans"
        p.value = str(len(self.combiner.run_configs))

        p = response.parameter.add()
        p.key = "name"
        p.value = str(self.id)

        # Get IP information
        #try:
        #    url = 'http://ipinfo.io/json'
        #    data = requests.get(url)
        #    combiner_location = json.loads(data.text)
        #    for key,value in combiner_location.items():
        #        p = response.parameter.add()
        #        p.key = str(key)
        #        p.value = str(value)
        #except Exception as e:
        #    print(e,flush=True)
        #    pass

        return response
コード例 #7
0
    def Start(self, control: fedn.ControlRequest, context):
        """ Push a round config to RoundControl. 

        :param control:
        :param context:
        :return:
        """
        response = fedn.ControlResponse()
        print("\n\n GOT CONTROL **START** from Command {}\n\n".format(
            control.command),
              flush=True)

        config = {}
        for parameter in control.parameter:
            config.update({parameter.key: parameter.value})
        print(
            "\n\nSTARTING ROUND AT COMBINER WITH ROUND CONFIG: {}\n\n".format(
                config),
            flush=True)

        job_id = self.control.push_round_config(config)
        return response