# Limiting the number of runs for a sweep of method 'bayes'

**URL:** <https://community.wandb.ai/t/limiting-the-number-of-runs-for-a-sweep-of-method-bayes/3137>\
**Category:** W&B Help\
**Tags:** sweeps\
**Created:** [September 18, 2022, 7:52am UTC](https://community.wandb.ai/t/limiting-the-number-of-runs-for-a-sweep-of-method-bayes/3137 "2022-09-18T07:52:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomjur](https://avatars.discourse-cdn.com/v4/letter/t/e68b1a/32.png) [@tomjur](https://community.wandb.ai/u/tomjur)\
**Post date:** [September 18, 2022, 7:52am UTC](https://community.wandb.ai/t/limiting-the-number-of-runs-for-a-sweep-of-method-bayes/3137/1 "2022-09-18T07:52:41Z")

</div>

Hi,

Is there a way to limit in advance the number of configs a sweep is going to use?  
Currently, I need to follow the progress and stop the sweep manually.

Moreover, if there is such a setting, could it also be configured dynamically on-the-fly?

Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![udaylunawat](https://avatars.discourse-cdn.com/v4/letter/u/97f17d/32.png) [@udaylunawat](https://community.wandb.ai/u/udaylunawat)\
**Post date:** [September 18, 2022, 3:48pm UTC](https://community.wandb.ai/t/limiting-the-number-of-runs-for-a-sweep-of-method-bayes/3137/2 "2022-09-18T15:48:20Z")

</div>

[wandb agent](https://docs.wandb.ai/ref/python/agent) has a parameter count with which you can set the number of trials to run.

You can use wandb python agent to dynamically set it.

---

<div class="post-metadata">

**Author:** ![tomjur](https://avatars.discourse-cdn.com/v4/letter/t/e68b1a/32.png) [@tomjur](https://community.wandb.ai/u/tomjur)\
**Post date:** [September 18, 2022, 4:48pm UTC](https://community.wandb.ai/t/limiting-the-number-of-runs-for-a-sweep-of-method-bayes/3137/3 "2022-09-18T16:48:59Z")

</div>

Thank you, but I was asking if the sweep has a count (for instance if I have several agents and don’t know in advance which agent will finish first)

---

<div class="post-metadata">

**Author:** ![nathank](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nathank](https://community.wandb.ai/u/nathank)\
**Post date:** [September 22, 2022, 2:16pm UTC](https://community.wandb.ai/t/limiting-the-number-of-runs-for-a-sweep-of-method-bayes/3137/4 "2022-09-22T14:16:17Z")

</div>

Hi @tomjur, there isn’t really a way to set this explicitly. As @udaylunawat pointed out you could make the sum of the agent counts equal the number of runs you would like but this wouldn’t allow you to dynamically change this as you mentioned.

Probably the closest thing you could do is access the sweep via the API and introduce some logic to shut the sweep if it reaches the number of runs you are looking for. For example:

```auto
import wandb
import os
api = wandb.Api()
sweep = api.sweep(path/to/sweep)
if len(sweep.runs) >= max_runs:
    command = f'wandb sweep --stop {sweep_id}'
    os.system(command)

```

---

<div class="post-metadata">

**Author:** ![tomjur](https://avatars.discourse-cdn.com/v4/letter/t/e68b1a/32.png) [@tomjur](https://community.wandb.ai/u/tomjur)\
**Post date:** [September 22, 2022, 2:37pm UTC](https://community.wandb.ai/t/limiting-the-number-of-runs-for-a-sweep-of-method-bayes/3137/5 "2022-09-22T14:37:55Z")

</div>

Thanks, that could work for now.  
It would be great if the web UI \ config were able to control this behaviour.

Thanks!  
Tom

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/1X/366b649231631dbab896843020da0056074ac79d.png) [@system](https://community.wandb.ai/u/system)\
**Post date:** [November 21, 2022, 2:38pm UTC](https://community.wandb.ai/t/limiting-the-number-of-runs-for-a-sweep-of-method-bayes/3137/6 "2022-11-21T14:38:51Z")

</div>

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