# Deterministic client sampling

**URL:** <https://discuss.flower.ai/t/deterministic-client-sampling/431>\
**Category:** Flower Help - Beginners\
**Created:** [November 19, 2024, 10:46am UTC](https://discuss.flower.ai/t/deterministic-client-sampling/431 "2024-11-19T10:46:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mistersunshine](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@mistersunshine](https://discuss.flower.ai/u/mistersunshine)\
**Post date:** [November 19, 2024, 10:46am UTC](https://discuss.flower.ai/t/deterministic-client-sampling/431/1 "2024-11-19T10:46:22Z")

</div>

Hi,

I wanted to samples each rounds clients by id’s, meaning that if i’m using 20% of clients and i have 100 clients i want to start with 0 to 19 first clients and so on. I’m not sure if it should be on the configure\_fit function on my custom strategy or it should be on the client manager… Do you have already made examples with my problem ?

Kind regards,  
Mr. Sunshine.

---

<div class="post-metadata">

**Author:** ![mistersunshine](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@mistersunshine](https://discuss.flower.ai/u/mistersunshine)\
**Post date:** [November 19, 2024, 11:29am UTC](https://discuss.flower.ai/t/deterministic-client-sampling/431/2 "2024-11-19T11:29:52Z")

</div>

Okay, i think i’ve answered my self.

The function configure\_fit strategy side calls on the client\_manager.sample(), this function can take a criteron that invalidate clients.

I’ve implemented my own criteron for having a deterministic layout.

```auto
class DeterministicCriteron(Criterion):
    def __init__ (self):
        self.round = 0
        self.num_clients = 100
        self.ids = 0
        self.mapping = {}

    def select(self, client: ClientProxy) -> bool:
        """Decide whether a client should be eligible for sampling or not."""
        plage_min = self.round * 20
        plage_max = plage_min + 19

        if client.cid not in self.mapping:
            identifiant = self.ids
            self.mapping[client.cid] = identifiant
            self.ids += 1

        eligible = plage_min <= self.mapping[client.cid] <= plage_max

        return eligible
    
    def update(self):
        self.round = (self.round + 1) % 5

```

It’s only a draft right now. I should have more variable in my init to be compatible with more than my fraction fit

Hope it can be usefull to anyone reading.

---

<div class="post-metadata">

**Author:** ![adam-narozniak](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/adam-narozniak/32/33_2.png) [@adam-narozniak](https://discuss.flower.ai/u/adam-narozniak)\
**Post date:** [November 20, 2024, 9:28am UTC](https://discuss.flower.ai/t/deterministic-client-sampling/431/3 "2024-11-20T09:28:46Z")

</div>

Hi, yes, that should work, assuming that the clients have `cid`s attributes.

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/flower/original/1X/bc7fe36843c391cbd0b4e8b6f48275961d356abc.png) [@system](https://discuss.flower.ai/u/system)\
**Post date:** [November 27, 2024, 9:28am UTC](https://discuss.flower.ai/t/deterministic-client-sampling/431/4 "2024-11-27T09:28:49Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
