Stateful/Persistent clients in simulation context

Hello everybody.

I am trying to implement stateful clients together with the flwr.simulation.start_simulation function. I have seen that in the Release Notes 1.7 it mentions the RecordSet data structure as a way of doing this. I also see that it is still experimental. Is there already a way of using this together with simulations?

Background
I am using flower for my master thesis to explore purification strategies for benign clients. Some of the strategies to be implemented will require stateful clients that are able to retain data across multiple rounds. Instead of writing this data to the disk, I was wondering whether there already exists a way in flower for clients to retain data across multiple rounds in the simulation context.

What I have discovered
The class flwr.client.Client contains an uninitialized parameter context: Context which is supposed to contain the RecordSet. However, when I try to access it in my inherited clients it is uninitialized. Furthermore, if I set it in the constructor of my inherited client class, I am able to use the object for that round but it doesn’t persists into the next round or even next function call (as described in Persisting client class attributes within a single FL round - #2 by yan).
My suspicion is that the framework expects some external component to handle this object (in order for it to be persistent) and in using start_simulation, this doesn’t happen.
I have also seen that in the current flower git repository, there are examples (like ./app-pytorch/server_custom.py) that are using the flwr.common.Context object. However, there it seems to be used in a different use-case, so I wasn’t able to figure out how to use it.

Versions used
I am currently using flwr 1.8.0.

3 Likes

Ran into the same problem.

Solved this by writing stateful data to disk after training and loading it again before training. This is done per client.

Yeah. I ended up doing the same.