Repository: Lightning-Universe/Training-Studio_app (language: python)

Issue:
Random search only works with low-high ranges, but errors out with choices, so it’s not possible to mix choices and intervals.
## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->

### To Reproduce

Steps to reproduce the behavior:

1. Go to '...'
1. Run '....'
1. Scroll down to '....'
1. See error

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

#### Code sample

<!-- Ideally attach a minimal code sample to reproduce the decried issue.
Minimal means having the shortest code but still preserving the bug. -->

### Expected behavior

<!-- A clear and concise description of what you expected to happen. -->

### Environment

- PyTorch Version (e.g., 1.0):
- OS (e.g., Linux):
- How you installed PyTorch (`conda`, `pip`, source):
- Build command you used (if compiling from source):
- Python version:
- CUDA/cuDNN version:
- GPU models and configuration:
- Any other relevant information:

### Additional context

<!-- Add any other context about the problem here. -->



Discussion / hints:

Fix patch:
diff --git a/lightning_hpo/commands/sweep/run.py b/lightning_hpo/commands/sweep/run.py
index b370d9ff..158fbeb0 100644
--- a/lightning_hpo/commands/sweep/run.py
+++ b/lightning_hpo/commands/sweep/run.py
@@ -270,13 +270,8 @@ def parse_random_search(script_args, args):
         if RANGE_REGEX.match(value):
             expected_value = parse_range_to_categorical(value)
         else:
-            expected_value = _parse_list(value)
-            if expected_value:
-                if len(expected_value) != 2:
-                    raise ValueError(f"We are expecting `low` and `high` values for argument {key}. Found {value}.")
-                low, high = expected_value
-                expected_value = {"distribution": "uniform", "params": {"low": float(low), "high": float(high)}}
-            else:
+            expected_value = parse_list_to_categorical(value)
+            if not expected_value:
                 for p in [UniformDistributionParser, LogUniformDistributionParser, CategoricalDistributionParser]:
                     if p.is_distribution(value):
                         try:


Test patch:
diff --git a/tests/commands/sweep/test_run.py b/tests/commands/sweep/test_run.py
index 9cb2d449..f1f21f32 100644
--- a/tests/commands/sweep/test_run.py
+++ b/tests/commands/sweep/test_run.py
@@ -69,10 +69,6 @@ def check_0(config):
     argv = ["python", __file__, "--lr", "[0, 1, 2]", "--gamma", "[0.0, 1.0, 2.0]"]
     run_sweep_command(monkeypatch, argv, check_0)
 
-    with pytest.raises(ValueError, match="We are expecting `low` and `high` values for argument"):
-        argv = ["python", __file__, "--lr", "[0, 1, 2]", "--algorithm", "random_search"]
-        run_sweep_command(monkeypatch, argv, None)
-
 
 def test_sweep_run_parsing_file_list_and_script_arguments(monkeypatch):
 
@@ -130,13 +126,28 @@ def check_0(config):
     ]
     run_sweep_command(monkeypatch, argv, check_0)
 
-    with pytest.raises(ValueError, match="[0, 1, 2]"):
-        argv = ["python", __file__, "--lr", "[0, 1, 2]", "--data", "something", "--algorithm", "random_search"]
-        run_sweep_command(monkeypatch, argv, None)
-
     def check_1(config):
         assert config.distributions == {
-            "lr": Distributions(distribution="uniform", params={"low": 0.0, "high": 2.0}),
+            "lr": Distributions(distribution="categorical", params={"choices": [0.0, 1.0, 2.0]}),
+        }
+
+    argv = [
+        "python",
+        __file__,
+        "--lr",
+        "[0, 1, 2]",
+        "--data",
+        "something",
+        "--algorithm",
+        "random_search",
+        "--total_experiments",
+        "3",
+    ]
+    run_sweep_command(monkeypatch, argv, check_1)
+
+    def check_2(config):
+        assert {
+            "lr": Distributions(distribution="categorical", params={"choices": [0.0, 2.0]}),
             "batch_size": Distributions(
                 distribution="categorical", params={"choices": [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]}
             ),
@@ -157,7 +168,7 @@ def check_1(config):
         "--total_experiments",
         "10",
     ]
-    run_sweep_command(monkeypatch, argv, check_1)
+    run_sweep_command(monkeypatch, argv, check_2)
 
 
 def test_sweep_run_parsing_random_search_further_distributions(monkeypatch):
@@ -166,7 +177,7 @@ def test_sweep_run_parsing_random_search_further_distributions(monkeypatch):
 
     def check_1(config):
         assert config.distributions == {
-            "lr": Distributions(distribution="uniform", params={"low": 0.0, "high": 2.0}),
+            "lr": Distributions(distribution="categorical", params={"choices": [0.0, 2.0]}),
             "batch_size": Distributions(
                 distribution="categorical", params={"choices": [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]}
             ),