Mercurial > repos > goeckslab > ludwig_render_config
annotate ludwig_render_config.py @ 6:dd663701df49 draft default tip
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit 59a0f37fed961b3ba4c55f8205e7cf4ebd551767
| author | goeckslab | 
|---|---|
| date | Sat, 06 Sep 2025 01:52:15 +0000 | 
| parents | e3c63770083d | 
| children | 
| rev | line source | 
|---|---|
| 
0
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
1 import json | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
2 import logging | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
3 import sys | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
4 | 
| 
4
 
e3c63770083d
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit 4dc221b2fa9717552787f0985ad3fc3df4460158
 
goeckslab 
parents: 
0 
diff
changeset
 | 
5 import yaml | 
| 
0
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
6 from ludwig.constants import ( | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
7 COMBINER, | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
8 HYPEROPT, | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
9 INPUT_FEATURES, | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
10 MODEL_TYPE, | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
11 OUTPUT_FEATURES, | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
12 PROC_COLUMN, | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
13 TRAINER, | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
14 ) | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
15 from ludwig.schema.model_types.utils import merge_with_defaults | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
16 | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
17 | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
18 logging.basicConfig(level=logging.DEBUG) | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
19 LOG = logging.getLogger(__name__) | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
20 inputs = sys.argv[1] | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
21 with open(inputs, 'r') as handler: | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
22 params = json.load(handler) | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
23 | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
24 config = {} | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
25 # input features | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
26 config[INPUT_FEATURES] = [] | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
27 for ftr in params[INPUT_FEATURES]['input_feature']: | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
28 config[INPUT_FEATURES].append(ftr['input_feature_selector']) | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
29 | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
30 # output features | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
31 config[OUTPUT_FEATURES] = [] | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
32 for ftr in params[OUTPUT_FEATURES]['output_feature']: | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
33 config[OUTPUT_FEATURES].append(ftr['output_feature_selector']) | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
34 | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
35 # combiner | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
36 config[COMBINER] = params[COMBINER] | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
37 | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
38 # training | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
39 config[TRAINER] = params[TRAINER][TRAINER] | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
40 config[MODEL_TYPE] = config[TRAINER].pop(MODEL_TYPE) | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
41 | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
42 # hyperopt | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
43 if params[HYPEROPT]['do_hyperopt'] == 'true': | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
44 config[HYPEROPT] = params[HYPEROPT][HYPEROPT] | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
45 | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
46 with open('./pre_config.yml', 'w') as f: | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
47 yaml.safe_dump(config, f, allow_unicode=True, default_flow_style=False) | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
48 | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
49 output = sys.argv[2] | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
50 output_config = merge_with_defaults(config) | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
51 | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
52 | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
53 def clean_proc_column(config: dict) -> None: | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
54 for ftr in config[INPUT_FEATURES]: | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
55 ftr.pop(PROC_COLUMN, None) | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
56 for ftr in config[OUTPUT_FEATURES]: | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
57 ftr.pop(PROC_COLUMN, None) | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
58 | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
59 | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
60 clean_proc_column(output_config) | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
61 | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
62 with open(output, "w") as f: | 
| 
 
ed8a9ea5bc73
planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
 
goeckslab 
parents:  
diff
changeset
 | 
63 yaml.safe_dump(output_config, f, sort_keys=False) | 
