Skip to content

declearn.communication.messaging.InitRequest

Bases: Message

Server-emitted request to initialize local model and optimizer.

Source code in declearn/communication/messaging/_messages.py
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
@dataclasses.dataclass
class InitRequest(Message):
    """Server-emitted request to initialize local model and optimizer."""

    typekey = "init_request"

    model: Model
    optim: Optimizer
    metrics: List[MetricInputType] = dataclasses.field(default_factory=list)
    dpsgd: bool = False

    def to_string(self) -> str:
        data = {"typekey": self.typekey}  # type: Dict[str, Any]
        data["model"] = serialize_object(self.model, group="Model").to_dict()
        data["optim"] = self.optim.get_config()
        data["metrics"] = self.metrics
        data["dpsgd"] = self.dpsgd
        return json.dumps(data, default=json_pack)

    @classmethod
    def from_kwargs(cls, **kwargs: Any) -> Self:
        kwargs["model"] = deserialize_object(kwargs["model"])
        kwargs["optim"] = Optimizer.from_config(kwargs["optim"])
        return cls(**kwargs)