# How to execute each experiment once?

**URL:** <https://discuss.ray.io/t/how-to-execute-each-experiment-once/889>\
**Category:** Ray Tune\
**Created:** [February 15, 2021, 1:47pm UTC](https://discuss.ray.io/t/how-to-execute-each-experiment-once/889 "2021-02-15T13:47:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brix](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/brix/32/463_2.png) [@Brix](https://discuss.ray.io/u/Brix)\
**Post date:** [February 15, 2021, 1:47pm UTC](https://discuss.ray.io/t/how-to-execute-each-experiment-once/889/1 "2021-02-15T13:47:52Z")

</div>

Hi,  
I would like to execute each possible experiment from a list exactly once.

Running the MWE following, experiments with an “exp” value of 0,1,2,3,4 should be done.  
However, tune randomly picks numbers from the “exp” list and repeats them.

What am I doing wrong?

```
from ray import tune
from functools import partial

config = {
    "exp": tune.choice([0,1,2,3,4]), 
}

def dummy(config, checkpoint_dir=None, data_dir=None, workers=5):    
    print("Experiment: ",config["exp"])
    
    
def main(trainable, num_samples=10, max_num_epochs=10, gpus_per_trial=0.5, cpus_per_trial=10, name="testrun"):
    
    global result
    result = tune.run(partial(tune.with_parameters(trainable, workers=cpus_per_trial)),
                      config=config,
                      num_samples=num_samples,
                      name=name,
                      verbose=True,
                      local_dir="/ray_results"
                     )
   
if __name__ == " __main__":
     main(trainable=dummy,num_samples=5, max_num_epochs=1, name="dummy")
     # This should execute each experiment (0 to 4) once, but it randomly executes experiments with replacement.
```

---

<div class="post-metadata">

**Author:** ![rliaw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/rliaw/32/24_2.png) [@rliaw](https://discuss.ray.io/u/rliaw)\
**Post date:** [February 15, 2021, 5:22pm UTC](https://discuss.ray.io/t/how-to-execute-each-experiment-once/889/2 "2021-02-15T17:22:12Z")

</div>

For your example, you could try:

```auto
config = {
    "exp": tune.grid_search([0,1,2,3,4]), 
}
...
...

if __name__ == " __main__":
     # we set num_samples = 1 here because it will repeat the grid.
     main(trainable=dummy, num_samples=1, max_num_epochs=1, name="dummy")
```

---

<div class="post-metadata">

**Author:** ![Brix](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/brix/32/463_2.png) [@Brix](https://discuss.ray.io/u/Brix)\
**Post date:** [February 15, 2021, 7:32pm UTC](https://discuss.ray.io/t/how-to-execute-each-experiment-once/889/3 "2021-02-15T19:32:08Z")

</div>

> [@rliaw](#):
>
> ` "exp": tune.grid_search([0,1,2,3,4]),`

Thank you very much, this is great!
