diff ludwig_render_config.py @ 0:f0be10937f5c draft default tip

planemo upload for repository https://github.com/goeckslab/Galaxy-Ludwig.git commit bdea9430787658783a51cc6c2ae951a01e455bb4
author goeckslab
date Tue, 07 Jan 2025 22:44:09 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ludwig_render_config.py	Tue Jan 07 22:44:09 2025 +0000
@@ -0,0 +1,63 @@
+import json
+import logging
+import sys
+
+from ludwig.constants import (
+    COMBINER,
+    HYPEROPT,
+    INPUT_FEATURES,
+    MODEL_TYPE,
+    OUTPUT_FEATURES,
+    PROC_COLUMN,
+    TRAINER,
+)
+from ludwig.schema.model_types.utils import merge_with_defaults
+
+import yaml
+
+logging.basicConfig(level=logging.DEBUG)
+LOG = logging.getLogger(__name__)
+inputs = sys.argv[1]
+with open(inputs, 'r') as handler:
+    params = json.load(handler)
+
+config = {}
+# input features
+config[INPUT_FEATURES] = []
+for ftr in params[INPUT_FEATURES]['input_feature']:
+    config[INPUT_FEATURES].append(ftr['input_feature_selector'])
+
+# output features
+config[OUTPUT_FEATURES] = []
+for ftr in params[OUTPUT_FEATURES]['output_feature']:
+    config[OUTPUT_FEATURES].append(ftr['output_feature_selector'])
+
+# combiner
+config[COMBINER] = params[COMBINER]
+
+# training
+config[TRAINER] = params[TRAINER][TRAINER]
+config[MODEL_TYPE] = config[TRAINER].pop(MODEL_TYPE)
+
+# hyperopt
+if params[HYPEROPT]['do_hyperopt'] == 'true':
+    config[HYPEROPT] = params[HYPEROPT][HYPEROPT]
+
+with open('./pre_config.yml', 'w') as f:
+    yaml.safe_dump(config, f, allow_unicode=True, default_flow_style=False)
+
+output = sys.argv[2]
+output_config = merge_with_defaults(config)
+
+
+def clean_proc_column(config: dict) -> None:
+    for ftr in config[INPUT_FEATURES]:
+        ftr.pop(PROC_COLUMN, None)
+    for ftr in config[OUTPUT_FEATURES]:
+        ftr.pop(PROC_COLUMN, None)
+
+
+clean_proc_column(output_config)
+
+with open(output, "w") as f:
+    yaml.safe_dump(output_config, f, sort_keys=False)