robert 2.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- robert/__init__.py +9 -0
- robert/__main__.py +20 -0
- robert/_version.py +3 -0
- robert/api.py +646 -0
- robert/aqme.py +280 -0
- robert/argument_parser.py +98 -0
- robert/checkml.py +433 -0
- robert/checkml_score.py +50 -0
- robert/curate.py +217 -0
- robert/evaluate_bot_retrieval.py +125 -0
- robert/evaluate_bot_support.py +102 -0
- robert/evaluate_workflow_summaries.py +87 -0
- robert/export_bot_docs_knowledge.py +1632 -0
- robert/generate.py +249 -0
- robert/generate_utils.py +311 -0
- robert/gui_easyrob/__init__.py +0 -0
- robert/gui_easyrob/assets/gif_easyrob.gif +0 -0
- robert/gui_easyrob/bot/__init__.py +47 -0
- robert/gui_easyrob/bot/answer_metadata.py +198 -0
- robert/gui_easyrob/bot/bot_context.py +679 -0
- robert/gui_easyrob/bot/bot_engine.py +1100 -0
- robert/gui_easyrob/bot/bot_panel.py +1231 -0
- robert/gui_easyrob/bot/bot_rag.py +1178 -0
- robert/gui_easyrob/bot/bot_window.py +39 -0
- robert/gui_easyrob/bot/bot_worker.py +149 -0
- robert/gui_easyrob/bot/credential_store.py +143 -0
- robert/gui_easyrob/bot/error_parser.py +105 -0
- robert/gui_easyrob/bot/evidence_policy.py +164 -0
- robert/gui_easyrob/bot/heuristics.py +859 -0
- robert/gui_easyrob/bot/icons.py +56 -0
- robert/gui_easyrob/bot/input_csv_audit.py +212 -0
- robert/gui_easyrob/bot/knowledge/aqme_context.json +5907 -0
- robert/gui_easyrob/bot/knowledge/robert_context.json +4817 -0
- robert/gui_easyrob/bot/knowledge/ui_context.json +8293 -0
- robert/gui_easyrob/bot/knowledge_schema.py +1252 -0
- robert/gui_easyrob/bot/knowledge_sources/aqme_user_guidance.json +442 -0
- robert/gui_easyrob/bot/knowledge_sources/coverage_manifest.json +95 -0
- robert/gui_easyrob/bot/knowledge_sources/robert_user_guidance.json +471 -0
- robert/gui_easyrob/bot/knowledge_sources/ui_user_guidance.json +1312 -0
- robert/gui_easyrob/bot/llm_providers.py +1573 -0
- robert/gui_easyrob/bot/online_docs.py +105 -0
- robert/gui_easyrob/bot/prompt_policy.py +575 -0
- robert/gui_easyrob/bot/question_intent.py +562 -0
- robert/gui_easyrob/bot/response_quality.py +104 -0
- robert/gui_easyrob/bot/result_insights.py +225 -0
- robert/gui_easyrob/bot/token_usage.py +75 -0
- robert/gui_easyrob/bot/workflow_results.py +1396 -0
- robert/gui_easyrob/checkml_launcher.py +15 -0
- robert/gui_easyrob/easyrob.py +29 -0
- robert/gui_easyrob/easyrob_launcher.py +113 -0
- robert/gui_easyrob/main/__init__.py +9 -0
- robert/gui_easyrob/main/window.py +5152 -0
- robert/gui_easyrob/result_navigation.py +14 -0
- robert/gui_easyrob/tabs/__init__.py +23 -0
- robert/gui_easyrob/tabs/advanced_options.py +370 -0
- robert/gui_easyrob/tabs/aqme.py +1234 -0
- robert/gui_easyrob/tabs/checkml.py +898 -0
- robert/gui_easyrob/tabs/images.py +427 -0
- robert/gui_easyrob/tabs/interactive_predictions.py +555 -0
- robert/gui_easyrob/tabs/molssi.py +447 -0
- robert/gui_easyrob/tabs/predictions.py +484 -0
- robert/gui_easyrob/tabs/result_catalog.py +170 -0
- robert/gui_easyrob/tabs/results.py +490 -0
- robert/gui_easyrob/tabs/results_workspace.py +120 -0
- robert/gui_easyrob/test_bot_input_csv_audit.py +152 -0
- robert/gui_easyrob/test_bot_question_routing.py +383 -0
- robert/gui_easyrob/test_bot_result_analysis.py +356 -0
- robert/gui_easyrob/test_bot_retrieval_evaluation.py +110 -0
- robert/gui_easyrob/test_bot_ui_integration.py +278 -0
- robert/gui_easyrob/test_checkml_app_mode.py +124 -0
- robert/gui_easyrob/test_checkml_completion.py +57 -0
- robert/gui_easyrob/test_checkml_defaults.py +37 -0
- robert/gui_easyrob/test_checkml_result_summary.py +113 -0
- robert/gui_easyrob/test_checkml_web_mode.py +57 -0
- robert/gui_easyrob/test_dialog_layout.py +33 -0
- robert/gui_easyrob/test_gui_bot_regressions.py +320 -0
- robert/gui_easyrob/test_molssi_auto.py +569 -0
- robert/gui_easyrob/test_tutorial_view.py +215 -0
- robert/gui_easyrob/tutorials/check_model.md +25 -0
- robert/gui_easyrob/tutorials/chemdraw.md +49 -0
- robert/gui_easyrob/tutorials/csv.md +53 -0
- robert/gui_easyrob/tutorials/descriptors.md +21 -0
- robert/gui_easyrob/tutorials/overview.md +65 -0
- robert/gui_easyrob/tutorials/predictions.md +25 -0
- robert/gui_easyrob/tutorials/robbot.md +29 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_10.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_11.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_12.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_13.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_9.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_9.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_8.png +0 -0
- robert/gui_easyrob/utils/__init__.py +0 -0
- robert/gui_easyrob/utils/aqme_utils.py +238 -0
- robert/gui_easyrob/utils/molssi_utils.py +584 -0
- robert/gui_easyrob/utils/predictions_utils.py +985 -0
- robert/gui_easyrob/utils/utils_gui.py +738 -0
- robert/gui_easyrob/version.py +68 -0
- robert/gui_easyrob/web/app.css +484 -0
- robert/gui_easyrob/web/app.html +134 -0
- robert/gui_easyrob/web/app.js +764 -0
- robert/gui_easyrob/web/checkml_brand.png +0 -0
- robert/gui_easyrob/web/easyrob_background.gif +0 -0
- robert/gui_easyrob/web/easyrob_background.png +0 -0
- robert/gui_easyrob/web/images.css +89 -0
- robert/gui_easyrob/web/images.html +39 -0
- robert/gui_easyrob/web/images.js +101 -0
- robert/gui_easyrob/web/results.js +499 -0
- robert/gui_easyrob/web/robert_brand.png +0 -0
- robert/gui_easyrob/web_dialogs.py +64 -0
- robert/gui_easyrob/web_results.py +253 -0
- robert/gui_easyrob/web_shell.py +684 -0
- robert/gui_easyrob/workflow_progress.py +89 -0
- robert/gui_easyrob/workflow_run_lock.py +27 -0
- robert/icons/CheckML_icon.png +0 -0
- robert/icons/Robert_icon.png +0 -0
- robert/icons/Robert_logo.jpg +0 -0
- robert/icons/Robert_logo_transparent.png +0 -0
- robert/icons/documentation_icon.png +0 -0
- robert/icons/info_icon.png +0 -0
- robert/icons/pdf_icon.png +0 -0
- robert/icons/play_icon.png +0 -0
- robert/icons/stop_icon.png +0 -0
- robert/icons/youtube_icon.ico +0 -0
- robert/predict.py +193 -0
- robert/predict_utils.py +410 -0
- robert/report/CheckML_logo.jpg +0 -0
- robert/report/GENERATE.png +0 -0
- robert/report/Robert_icon.ico +0 -0
- robert/report/Robert_logo.jpg +0 -0
- robert/report/Robert_logo1.jpg +0 -0
- robert/report/abbrev.png +0 -0
- robert/report/adv_anal.png +0 -0
- robert/report/checkml_pass.svg +3 -0
- robert/report/checkml_unclear.svg +3 -0
- robert/report/checkml_warning.svg +3 -0
- robert/report/features.png +0 -0
- robert/report/outliers.png +0 -0
- robert/report/pred.png +0 -0
- robert/report/repro.png +0 -0
- robert/report/robust_x.png +0 -0
- robert/report/robust_y_high.png +0 -0
- robert/report/robust_y_low.png +0 -0
- robert/report/score.png +0 -0
- robert/report/score_0.jpg +0 -0
- robert/report/score_1.jpg +0 -0
- robert/report/score_10.jpg +0 -0
- robert/report/score_2.jpg +0 -0
- robert/report/score_3.jpg +0 -0
- robert/report/score_4.jpg +0 -0
- robert/report/score_5.jpg +0 -0
- robert/report/score_6.jpg +0 -0
- robert/report/score_7.jpg +0 -0
- robert/report/score_8.jpg +0 -0
- robert/report/score_9.jpg +0 -0
- robert/report/score_gray_0.jpg +0 -0
- robert/report/score_gray_1.jpg +0 -0
- robert/report/score_gray_10.jpg +0 -0
- robert/report/score_gray_2.jpg +0 -0
- robert/report/score_gray_3.jpg +0 -0
- robert/report/score_gray_4.jpg +0 -0
- robert/report/score_gray_5.jpg +0 -0
- robert/report/score_gray_6.jpg +0 -0
- robert/report/score_gray_7.jpg +0 -0
- robert/report/score_gray_8.jpg +0 -0
- robert/report/score_gray_9.jpg +0 -0
- robert/report/score_w_1_0.jpg +0 -0
- robert/report/score_w_1_1.jpg +0 -0
- robert/report/score_w_2_0.jpg +0 -0
- robert/report/score_w_2_1.jpg +0 -0
- robert/report/score_w_2_2.jpg +0 -0
- robert/report/score_w_2_gray_0.jpg +0 -0
- robert/report/score_w_2_gray_1.jpg +0 -0
- robert/report/score_w_2_gray_2.jpg +0 -0
- robert/report/score_w_3_0.jpg +0 -0
- robert/report/score_w_3_1.jpg +0 -0
- robert/report/score_w_3_2.jpg +0 -0
- robert/report/score_w_3_3.jpg +0 -0
- robert/report/score_w_4_0.jpg +0 -0
- robert/report/score_w_4_1.JPG +0 -0
- robert/report/score_w_4_2.jpg +0 -0
- robert/report/score_w_4_3.jpg +0 -0
- robert/report/score_w_4_4.jpg +0 -0
- robert/report/transpa.png +0 -0
- robert/report/y_distrib.png +0 -0
- robert/report.py +2880 -0
- robert/report_utils.py +2270 -0
- robert/robert.py +181 -0
- robert/utils.py +4763 -0
- robert/verify.py +606 -0
- robert-2.2.0.dist-info/METADATA +55 -0
- robert-2.2.0.dist-info/RECORD +261 -0
- robert-2.2.0.dist-info/WHEEL +5 -0
- robert-2.2.0.dist-info/entry_points.txt +3 -0
- robert-2.2.0.dist-info/licenses/LICENSE +21 -0
- robert-2.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,898 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CHECKML tab for easyROB.
|
|
3
|
+
|
|
4
|
+
Lets a user evaluate their own scikit-learn model (regression or classification) under
|
|
5
|
+
ROBERT's standard rigor - repeated CV, VERIFY's flawed-model tests, boundary robustness (for
|
|
6
|
+
regression), outliers, SHAP, and a scored PDF report - without going through GENERATE's
|
|
7
|
+
Bayesian hyperparameter search.
|
|
8
|
+
|
|
9
|
+
Responsibilities:
|
|
10
|
+
- Collect a CSV plus the y/names columns and prediction type - the train/internal-test split
|
|
11
|
+
uses CheckML's standard protocol, unless the CSV has a 'Set' column marking 'Test' rows (then
|
|
12
|
+
the report has no score); there is no "ignore columns" option, only SMILES is excluded
|
|
13
|
+
- Optionally collect a separate external test CSV (--csv_test), for a model already evaluated
|
|
14
|
+
against a held-out set the user manages themselves
|
|
15
|
+
- Collect the model to evaluate: ROBERT's own default (MVL, no tuning), a CSV naming a
|
|
16
|
+
scikit-learn class and its hyperparameters, or a pre-fitted model saved with joblib/pickle
|
|
17
|
+
- Score the model as-is on the descriptors already present in the input CSV - ROBERT never
|
|
18
|
+
re-curates them, so the model is evaluated on exactly what the user provided
|
|
19
|
+
- Build the equivalent "python -m robert --checkml ..." command and run it with the same
|
|
20
|
+
RobertWorker used by the main ROBERT tab, streaming output live
|
|
21
|
+
- Refresh the Reports/Predictions/Images tabs once the run finishes successfully
|
|
22
|
+
|
|
23
|
+
Import strategy mirrors the rest of gui_easyrob/tabs: a local (portable) import path is tried
|
|
24
|
+
first, falling back to the installed-package path.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
from utils.utils_gui import (
|
|
29
|
+
AssetLibrary,
|
|
30
|
+
DropLabel,
|
|
31
|
+
NoScrollComboBox,
|
|
32
|
+
QFileDialog,
|
|
33
|
+
QFormLayout,
|
|
34
|
+
QGroupBox,
|
|
35
|
+
QHBoxLayout,
|
|
36
|
+
QIcon,
|
|
37
|
+
QLabel,
|
|
38
|
+
QLineEdit,
|
|
39
|
+
QListWidget,
|
|
40
|
+
QListWidgetItem,
|
|
41
|
+
QMessageBox,
|
|
42
|
+
QProgressBar,
|
|
43
|
+
QPushButton,
|
|
44
|
+
QScrollArea,
|
|
45
|
+
QSizePolicy,
|
|
46
|
+
QTextEdit,
|
|
47
|
+
QVBoxLayout,
|
|
48
|
+
QWidget,
|
|
49
|
+
Qt,
|
|
50
|
+
RobertWorker,
|
|
51
|
+
smart_read_csv,
|
|
52
|
+
warn_if_csv_name_has_spaces,
|
|
53
|
+
)
|
|
54
|
+
except ImportError:
|
|
55
|
+
from robert.gui_easyrob.utils.utils_gui import (
|
|
56
|
+
AssetLibrary,
|
|
57
|
+
DropLabel,
|
|
58
|
+
NoScrollComboBox,
|
|
59
|
+
QFileDialog,
|
|
60
|
+
QFormLayout,
|
|
61
|
+
QGroupBox,
|
|
62
|
+
QHBoxLayout,
|
|
63
|
+
QIcon,
|
|
64
|
+
QLabel,
|
|
65
|
+
QLineEdit,
|
|
66
|
+
QListWidget,
|
|
67
|
+
QListWidgetItem,
|
|
68
|
+
QMessageBox,
|
|
69
|
+
QProgressBar,
|
|
70
|
+
QPushButton,
|
|
71
|
+
QScrollArea,
|
|
72
|
+
QSizePolicy,
|
|
73
|
+
QTextEdit,
|
|
74
|
+
QVBoxLayout,
|
|
75
|
+
QWidget,
|
|
76
|
+
Qt,
|
|
77
|
+
RobertWorker,
|
|
78
|
+
smart_read_csv,
|
|
79
|
+
warn_if_csv_name_has_spaces,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
import csv
|
|
83
|
+
import pandas as pd
|
|
84
|
+
import inspect
|
|
85
|
+
import os
|
|
86
|
+
import sys
|
|
87
|
+
import tempfile
|
|
88
|
+
from pathlib import Path
|
|
89
|
+
|
|
90
|
+
try:
|
|
91
|
+
from workflow_run_lock import WorkflowRunLock
|
|
92
|
+
except ImportError:
|
|
93
|
+
from robert.gui_easyrob.workflow_run_lock import WorkflowRunLock
|
|
94
|
+
|
|
95
|
+
# shared style for section group boxes, matching the "Advanced Options" tab's convention
|
|
96
|
+
BOX_STYLE = "QGroupBox { font-weight: bold; }"
|
|
97
|
+
|
|
98
|
+
MODEL_PARAMS_EXAMPLE = """\
|
|
99
|
+
<p>A CSV with two columns: <b>param</b> and <b>value</b>.</p>
|
|
100
|
+
<p>One row must have <code>param = model</code>, naming any scikit-learn regressor/classifier \
|
|
101
|
+
class exactly (e.g. <code>RandomForestRegressor</code>). Every other row is one \
|
|
102
|
+
hyperparameter for that class.</p>
|
|
103
|
+
<p><b>Example:</b></p>
|
|
104
|
+
<table cellpadding="3" border="1" style="border-collapse:collapse;">
|
|
105
|
+
<tr><th>param</th><th>value</th></tr>
|
|
106
|
+
<tr><td>model</td><td>RandomForestRegressor</td></tr>
|
|
107
|
+
<tr><td>n_estimators</td><td>200</td></tr>
|
|
108
|
+
<tr><td>max_depth</td><td>5</td></tr>
|
|
109
|
+
</table>
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _make_info_icon(label, rich_text):
|
|
114
|
+
"""A Help button matching the "Advanced Options" tab's own help-button style (icon + text
|
|
115
|
+
on a normal bordered button), with a tooltip and a click-to-open popup with details."""
|
|
116
|
+
|
|
117
|
+
icon = QPushButton(label)
|
|
118
|
+
with AssetLibrary.Info_icon.get_path() as icon_path:
|
|
119
|
+
icon.setIcon(QIcon(str(icon_path)))
|
|
120
|
+
icon.setCursor(Qt.PointingHandCursor)
|
|
121
|
+
icon.setStyleSheet("padding: 4px; font-weight: bold;")
|
|
122
|
+
icon.setToolTip(rich_text)
|
|
123
|
+
|
|
124
|
+
def _show_popup():
|
|
125
|
+
box = QMessageBox()
|
|
126
|
+
box.setWindowTitle("Hyperparameters CSV format")
|
|
127
|
+
box.setTextFormat(Qt.RichText)
|
|
128
|
+
box.setText(rich_text)
|
|
129
|
+
box.exec()
|
|
130
|
+
|
|
131
|
+
icon.clicked.connect(_show_popup)
|
|
132
|
+
return icon
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
# Estimators excluded from the picker - verified empirically (instantiate + fit + predict on a
|
|
136
|
+
# small single-target dataset shaped like ROBERT's typical input) rather than guessed. Two
|
|
137
|
+
# failure patterns account for all of them:
|
|
138
|
+
# 1. Meta-estimators whose one required constructor argument IS another model (estimator/
|
|
139
|
+
# estimators) - there's no way to express "another scikit-learn model" as plain CSV text, so
|
|
140
|
+
# these fail immediately at instantiation (missing required positional argument)
|
|
141
|
+
# 2. Multi-task/multi-component models that reject a single-column y or need more components
|
|
142
|
+
# than ROBERT ever has features for single-target regression - these fail at fit() instead
|
|
143
|
+
_INCOMPATIBLE_REGRESSORS = {
|
|
144
|
+
'CCA', 'IsotonicRegression', 'MultiOutputRegressor', 'MultiTaskElasticNet',
|
|
145
|
+
'MultiTaskElasticNetCV', 'MultiTaskLasso', 'MultiTaskLassoCV', 'PLSCanonical',
|
|
146
|
+
'RegressorChain', 'StackingRegressor', 'VotingRegressor',
|
|
147
|
+
}
|
|
148
|
+
_INCOMPATIBLE_CLASSIFIERS = {
|
|
149
|
+
'ClassifierChain', 'FixedThresholdClassifier', 'MultiOutputClassifier',
|
|
150
|
+
'OneVsOneClassifier', 'OneVsRestClassifier', 'OutputCodeClassifier',
|
|
151
|
+
'SelfTrainingClassifier', 'StackingClassifier', 'TunedThresholdClassifierCV',
|
|
152
|
+
'VotingClassifier',
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _sklearn_estimators(pred_type):
|
|
157
|
+
"""(name, class) pairs for every scikit-learn regressor/classifier registered via
|
|
158
|
+
sklearn.utils.all_estimators() - imported lazily so sklearn's own import cost is only paid
|
|
159
|
+
once the user actually opens this model-source option. Excludes the models in
|
|
160
|
+
_INCOMPATIBLE_REGRESSORS/_INCOMPATIBLE_CLASSIFIERS above, which can't work with CHECKML's
|
|
161
|
+
plain param=value interface regardless of what the user fills in."""
|
|
162
|
+
|
|
163
|
+
from sklearn.utils import all_estimators
|
|
164
|
+
|
|
165
|
+
key = 'regressor' if pred_type == 'reg' else 'classifier'
|
|
166
|
+
excluded = _INCOMPATIBLE_REGRESSORS if pred_type == 'reg' else _INCOMPATIBLE_CLASSIFIERS
|
|
167
|
+
try:
|
|
168
|
+
pairs = all_estimators(type_filter=key)
|
|
169
|
+
return sorted((p for p in pairs if p[0] not in excluded), key=lambda pair: pair[0])
|
|
170
|
+
except Exception:
|
|
171
|
+
return []
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _constructor_params(model_cls):
|
|
175
|
+
"""(param_name, default_repr) pairs for a class's __init__, skipping self/*args/**kwargs.
|
|
176
|
+
default_repr is only a display hint (placeholder text) - never parsed back, so any
|
|
177
|
+
representation is fine."""
|
|
178
|
+
|
|
179
|
+
try:
|
|
180
|
+
signature = inspect.signature(model_cls.__init__)
|
|
181
|
+
except (TypeError, ValueError):
|
|
182
|
+
return []
|
|
183
|
+
|
|
184
|
+
params = []
|
|
185
|
+
for name, parameter in signature.parameters.items():
|
|
186
|
+
if name == 'self':
|
|
187
|
+
continue
|
|
188
|
+
if parameter.kind in (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD):
|
|
189
|
+
continue
|
|
190
|
+
default_repr = '' if parameter.default is inspect.Parameter.empty else repr(parameter.default)
|
|
191
|
+
params.append((name, default_repr))
|
|
192
|
+
return params
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
class CheckMLTab(QWidget):
|
|
196
|
+
"""Tab dedicated to running CHECKML."""
|
|
197
|
+
|
|
198
|
+
def __init__(self, parent=None):
|
|
199
|
+
super().__init__(parent)
|
|
200
|
+
|
|
201
|
+
self.worker = None
|
|
202
|
+
self._workflow_run_lock = WorkflowRunLock()
|
|
203
|
+
self.csv_path = None
|
|
204
|
+
self.csv_test_path = None
|
|
205
|
+
self.csv_columns = []
|
|
206
|
+
self.text_columns = []
|
|
207
|
+
self.model_params_path = None
|
|
208
|
+
self.model_file_path = None
|
|
209
|
+
self.manual_stop = False
|
|
210
|
+
self._report_before_run = None
|
|
211
|
+
|
|
212
|
+
self._build_ui()
|
|
213
|
+
|
|
214
|
+
# ------------------------------------------------------------------
|
|
215
|
+
# UI construction
|
|
216
|
+
# ------------------------------------------------------------------
|
|
217
|
+
def _build_ui(self):
|
|
218
|
+
outer = QVBoxLayout(self)
|
|
219
|
+
outer.setContentsMargins(14, 14, 14, 14)
|
|
220
|
+
outer.setSpacing(18)
|
|
221
|
+
|
|
222
|
+
title = QLabel("Evaluate your own model with ROBERT's standard rigor")
|
|
223
|
+
title.setStyleSheet("font-weight:600; font-size:16px;")
|
|
224
|
+
outer.addWidget(title)
|
|
225
|
+
|
|
226
|
+
subtitle = QLabel(
|
|
227
|
+
"Runs repeated cross-validation, VERIFY's flawed-model tests, boundary robustness "
|
|
228
|
+
"(regression), outliers, SHAP, and a scored PDF - for a model you already chose, "
|
|
229
|
+
"instead of ROBERT's own Bayesian hyperparameter search."
|
|
230
|
+
)
|
|
231
|
+
subtitle.setWordWrap(True)
|
|
232
|
+
subtitle.setStyleSheet("color: gray; font-size: 12px;")
|
|
233
|
+
outer.addWidget(subtitle)
|
|
234
|
+
|
|
235
|
+
# --- Input data group ---
|
|
236
|
+
input_box = QGroupBox("INPUT DATA")
|
|
237
|
+
input_box.setStyleSheet(BOX_STYLE)
|
|
238
|
+
input_layout = QVBoxLayout(input_box)
|
|
239
|
+
input_layout.setSpacing(10)
|
|
240
|
+
input_layout.setContentsMargins(12, 16, 12, 12)
|
|
241
|
+
|
|
242
|
+
# main CSV (left) and optional external test CSV (right), side by side - same layout
|
|
243
|
+
# as the main "ROBERT" tab's own CSV pickers, to save vertical space
|
|
244
|
+
csv_row = QHBoxLayout()
|
|
245
|
+
csv_row.setSpacing(16)
|
|
246
|
+
|
|
247
|
+
left_col = QVBoxLayout()
|
|
248
|
+
left_col.setSpacing(4)
|
|
249
|
+
left_title = QLabel("Input CSV")
|
|
250
|
+
left_title.setAlignment(Qt.AlignCenter)
|
|
251
|
+
left_title.setStyleSheet("font-weight:600; font-size:12px;")
|
|
252
|
+
left_col.addWidget(left_title)
|
|
253
|
+
self.csv_label = DropLabel(
|
|
254
|
+
"Drag & Drop a CSV file here",
|
|
255
|
+
self,
|
|
256
|
+
file_filter="CSV Files (*.csv)",
|
|
257
|
+
extensions=(".csv",),
|
|
258
|
+
)
|
|
259
|
+
self.csv_label.set_callback(self.set_csv_path)
|
|
260
|
+
left_col.addWidget(self.csv_label)
|
|
261
|
+
csv_row.addLayout(left_col)
|
|
262
|
+
|
|
263
|
+
right_col = QVBoxLayout()
|
|
264
|
+
right_col.setSpacing(4)
|
|
265
|
+
right_title = QLabel("Already had an external test set for this model? (optional)")
|
|
266
|
+
right_title.setAlignment(Qt.AlignCenter)
|
|
267
|
+
right_title.setWordWrap(True)
|
|
268
|
+
right_title.setStyleSheet("font-weight:600; font-size:12px;")
|
|
269
|
+
right_col.addWidget(right_title)
|
|
270
|
+
self.csv_test_label = DropLabel(
|
|
271
|
+
"Drag & Drop an external test CSV here (optional)",
|
|
272
|
+
self,
|
|
273
|
+
file_filter="CSV Files (*.csv)",
|
|
274
|
+
extensions=(".csv",),
|
|
275
|
+
)
|
|
276
|
+
self.csv_test_label.set_callback(self.set_csv_test_path)
|
|
277
|
+
right_col.addWidget(self.csv_test_label)
|
|
278
|
+
self.clear_csv_test_button = QPushButton("Clear external test CSV")
|
|
279
|
+
self.clear_csv_test_button.setEnabled(False)
|
|
280
|
+
self.clear_csv_test_button.clicked.connect(self.clear_csv_test_path)
|
|
281
|
+
right_col.addWidget(self.clear_csv_test_button)
|
|
282
|
+
csv_row.addLayout(right_col)
|
|
283
|
+
|
|
284
|
+
input_layout.addLayout(csv_row)
|
|
285
|
+
|
|
286
|
+
split_info = QLabel(
|
|
287
|
+
"The train / internal-test split uses CheckML's standard protocol (~20% of the "
|
|
288
|
+
"data, evenly spread across the y range). Optional: to analyze your own split, add "
|
|
289
|
+
"a 'Set' column with 'Test' on the test rows; the report then shows all the "
|
|
290
|
+
"analyses but no CheckML score."
|
|
291
|
+
)
|
|
292
|
+
split_info.setWordWrap(True)
|
|
293
|
+
split_info.setStyleSheet("color: gray; font-size: 11px;")
|
|
294
|
+
input_layout.addWidget(split_info)
|
|
295
|
+
|
|
296
|
+
row1 = QHBoxLayout()
|
|
297
|
+
row1.setSpacing(16)
|
|
298
|
+
|
|
299
|
+
y_col = QVBoxLayout()
|
|
300
|
+
y_col.setSpacing(4)
|
|
301
|
+
y_col.addWidget(QLabel("y (target column)"))
|
|
302
|
+
self.y_dropdown = NoScrollComboBox()
|
|
303
|
+
y_col.addWidget(self.y_dropdown)
|
|
304
|
+
row1.addLayout(y_col)
|
|
305
|
+
|
|
306
|
+
names_col = QVBoxLayout()
|
|
307
|
+
names_col.setSpacing(4)
|
|
308
|
+
names_col.addWidget(QLabel("names (ID column)"))
|
|
309
|
+
self.names_dropdown = NoScrollComboBox()
|
|
310
|
+
names_col.addWidget(self.names_dropdown)
|
|
311
|
+
row1.addLayout(names_col)
|
|
312
|
+
|
|
313
|
+
type_col = QVBoxLayout()
|
|
314
|
+
type_col.setSpacing(4)
|
|
315
|
+
type_col.addWidget(QLabel("Prediction type"))
|
|
316
|
+
self.type_dropdown = NoScrollComboBox()
|
|
317
|
+
self.type_dropdown.addItems(["Regression", "Classification"])
|
|
318
|
+
type_col.addWidget(self.type_dropdown)
|
|
319
|
+
row1.addLayout(type_col)
|
|
320
|
+
|
|
321
|
+
input_layout.addLayout(row1)
|
|
322
|
+
|
|
323
|
+
# no "ignore columns" option (see the CheckML publication and docs/Report/checkml_database.rst):
|
|
324
|
+
# the CSV must contain only the names, target and descriptors used by the model, plus an
|
|
325
|
+
# optional SMILES column that is excluded from the descriptors automatically. Every other
|
|
326
|
+
# column is used as a descriptor, and text columns stop the run (see _validate())
|
|
327
|
+
columns_info = QLabel(
|
|
328
|
+
"Include ONLY the names, target and descriptors used by the model. A SMILES column is "
|
|
329
|
+
"optional and is excluded from the descriptors automatically. Any other column is used "
|
|
330
|
+
"as a descriptor."
|
|
331
|
+
)
|
|
332
|
+
columns_info.setWordWrap(True)
|
|
333
|
+
columns_info.setStyleSheet("color: gray; font-size: 11px;")
|
|
334
|
+
input_layout.addWidget(columns_info)
|
|
335
|
+
|
|
336
|
+
outer.addWidget(input_box)
|
|
337
|
+
|
|
338
|
+
# --- Model source group ---
|
|
339
|
+
model_box = QGroupBox("MODEL TO CHECKML")
|
|
340
|
+
model_box.setStyleSheet(BOX_STYLE)
|
|
341
|
+
model_layout = QVBoxLayout(model_box)
|
|
342
|
+
model_layout.setSpacing(10)
|
|
343
|
+
model_layout.setContentsMargins(12, 16, 12, 12)
|
|
344
|
+
|
|
345
|
+
source_row = QHBoxLayout()
|
|
346
|
+
source_row.setSpacing(8)
|
|
347
|
+
self.model_source_dropdown = NoScrollComboBox()
|
|
348
|
+
self.model_source_dropdown.addItems([
|
|
349
|
+
"Default (MVL, no hyperparameters to tune)",
|
|
350
|
+
"Pick a scikit-learn model (fill in hyperparameters)",
|
|
351
|
+
"From a hyperparameters CSV (param,value)",
|
|
352
|
+
"From a saved model file (joblib/pickle)",
|
|
353
|
+
])
|
|
354
|
+
self.model_source_dropdown.currentIndexChanged.connect(self._on_model_source_changed)
|
|
355
|
+
source_row.addWidget(self.model_source_dropdown, stretch=1)
|
|
356
|
+
|
|
357
|
+
self.model_params_info = _make_info_icon("Help CSV format", MODEL_PARAMS_EXAMPLE)
|
|
358
|
+
self.model_params_info.hide()
|
|
359
|
+
source_row.addWidget(self.model_params_info)
|
|
360
|
+
|
|
361
|
+
model_layout.addLayout(source_row)
|
|
362
|
+
|
|
363
|
+
# --- "Pick a scikit-learn model" picker: a model dropdown (filtered by Prediction
|
|
364
|
+
# type) plus a scrollable form of that class's own constructor hyperparameters, each
|
|
365
|
+
# pre-filled with its scikit-learn default as a placeholder. Blank fields simply aren't
|
|
366
|
+
# sent, so scikit-learn's own default applies - only touched fields override it
|
|
367
|
+
self.sklearn_picker_container = QWidget()
|
|
368
|
+
sklearn_picker_layout = QVBoxLayout(self.sklearn_picker_container)
|
|
369
|
+
sklearn_picker_layout.setContentsMargins(0, 0, 0, 0)
|
|
370
|
+
sklearn_picker_layout.setSpacing(8)
|
|
371
|
+
|
|
372
|
+
self.sklearn_model_dropdown = NoScrollComboBox()
|
|
373
|
+
self.sklearn_model_dropdown.currentIndexChanged.connect(self._rebuild_sklearn_param_form)
|
|
374
|
+
sklearn_picker_layout.addWidget(self.sklearn_model_dropdown)
|
|
375
|
+
|
|
376
|
+
self.sklearn_param_fields = {}
|
|
377
|
+
sklearn_params_widget = QWidget()
|
|
378
|
+
self.sklearn_params_form = QFormLayout(sklearn_params_widget)
|
|
379
|
+
sklearn_params_scroll = QScrollArea()
|
|
380
|
+
sklearn_params_scroll.setWidgetResizable(True)
|
|
381
|
+
sklearn_params_scroll.setMaximumHeight(240)
|
|
382
|
+
sklearn_params_scroll.setWidget(sklearn_params_widget)
|
|
383
|
+
sklearn_picker_layout.addWidget(sklearn_params_scroll)
|
|
384
|
+
|
|
385
|
+
self.sklearn_picker_container.hide()
|
|
386
|
+
model_layout.addWidget(self.sklearn_picker_container)
|
|
387
|
+
|
|
388
|
+
self.model_params_label = DropLabel(
|
|
389
|
+
"Drag & Drop a CSV with 'param,value' rows (one row must be param='model', "
|
|
390
|
+
"e.g. value='RandomForestRegressor') - click the info icon above for an example",
|
|
391
|
+
self,
|
|
392
|
+
file_filter="CSV Files (*.csv)",
|
|
393
|
+
extensions=(".csv",),
|
|
394
|
+
)
|
|
395
|
+
self.model_params_label.set_callback(self.set_model_params_path)
|
|
396
|
+
self.model_params_label.hide()
|
|
397
|
+
model_layout.addWidget(self.model_params_label)
|
|
398
|
+
|
|
399
|
+
self.model_file_label = DropLabel(
|
|
400
|
+
"Drag & Drop a pre-fitted scikit-learn model saved with joblib/pickle",
|
|
401
|
+
self,
|
|
402
|
+
file_filter="Model files (*.joblib *.pkl *.pickle);;All files (*)",
|
|
403
|
+
extensions=(".joblib", ".pkl", ".pickle"),
|
|
404
|
+
)
|
|
405
|
+
self.model_file_label.set_callback(self.set_model_file_path)
|
|
406
|
+
self.model_file_label.hide()
|
|
407
|
+
model_layout.addWidget(self.model_file_label)
|
|
408
|
+
|
|
409
|
+
outer.addWidget(model_box)
|
|
410
|
+
|
|
411
|
+
# refreshes the sklearn model list when Prediction type changes (only matters while the
|
|
412
|
+
# "Pick a scikit-learn model" source is active - regressors vs classifiers differ)
|
|
413
|
+
self.type_dropdown.currentIndexChanged.connect(self._on_type_changed)
|
|
414
|
+
|
|
415
|
+
# Note: k-fold/CV repetitions/seed aren't exposed here - this tab always uses ROBERT's
|
|
416
|
+
# own defaults for those.
|
|
417
|
+
|
|
418
|
+
# --- Run / Stop (centered) ---
|
|
419
|
+
run_row = QHBoxLayout()
|
|
420
|
+
run_row.addStretch(1)
|
|
421
|
+
|
|
422
|
+
self.run_button = QPushButton(" Run CHECKML")
|
|
423
|
+
self.run_button.setFixedSize(200, 40)
|
|
424
|
+
self.run_button.setCursor(Qt.PointingHandCursor)
|
|
425
|
+
with AssetLibrary.Play_icon.get_path() as icon_play_path:
|
|
426
|
+
self.run_button.setIcon(QIcon(str(icon_play_path)))
|
|
427
|
+
self.run_button.setStyleSheet("""
|
|
428
|
+
QPushButton {
|
|
429
|
+
font-weight: bold;
|
|
430
|
+
font-size: 14px;
|
|
431
|
+
padding: 8px;
|
|
432
|
+
border-radius: 10px;
|
|
433
|
+
background-color: #6A0DAD;
|
|
434
|
+
color: white;
|
|
435
|
+
border: 2px solid #7B2CBF;
|
|
436
|
+
}
|
|
437
|
+
QPushButton:hover {
|
|
438
|
+
background-color: #7B2CBF;
|
|
439
|
+
border: 2px solid #9D4EDD;
|
|
440
|
+
}
|
|
441
|
+
QPushButton:pressed {
|
|
442
|
+
background-color: #4B0082;
|
|
443
|
+
border: 2px solid #5A189A;
|
|
444
|
+
}
|
|
445
|
+
QPushButton:disabled {
|
|
446
|
+
background-color: #3A2A4D;
|
|
447
|
+
border: 2px solid #3A2A4D;
|
|
448
|
+
color: #AAA;
|
|
449
|
+
}
|
|
450
|
+
""")
|
|
451
|
+
self.run_button.clicked.connect(self.run_checkml)
|
|
452
|
+
run_row.addWidget(self.run_button)
|
|
453
|
+
|
|
454
|
+
run_row.addSpacing(16)
|
|
455
|
+
|
|
456
|
+
self.stop_button = QPushButton(" Stop")
|
|
457
|
+
self.stop_button.setFixedSize(200, 40)
|
|
458
|
+
self.stop_button.setCursor(Qt.PointingHandCursor)
|
|
459
|
+
with AssetLibrary.Stop_icon.get_path() as icon_stop_path:
|
|
460
|
+
self.stop_button.setIcon(QIcon(str(icon_stop_path)))
|
|
461
|
+
self.stop_button.setStyleSheet("""
|
|
462
|
+
QPushButton {
|
|
463
|
+
font-weight: bold;
|
|
464
|
+
font-size: 14px;
|
|
465
|
+
padding: 8px;
|
|
466
|
+
border-radius: 10px;
|
|
467
|
+
background-color: #C62828;
|
|
468
|
+
color: white;
|
|
469
|
+
border: 2px solid #B71C1C;
|
|
470
|
+
}
|
|
471
|
+
QPushButton:hover {
|
|
472
|
+
background-color: #D32F2F;
|
|
473
|
+
border: 2px solid #C62828;
|
|
474
|
+
}
|
|
475
|
+
QPushButton:pressed {
|
|
476
|
+
background-color: #8E0000;
|
|
477
|
+
border: 2px solid #5F0000;
|
|
478
|
+
}
|
|
479
|
+
QPushButton:disabled {
|
|
480
|
+
background-color: #C62828;
|
|
481
|
+
border: 2px solid #B71C1C;
|
|
482
|
+
color: rgba(255, 255, 255, 120);
|
|
483
|
+
}
|
|
484
|
+
""")
|
|
485
|
+
self.stop_button.setDisabled(True)
|
|
486
|
+
self.stop_button.clicked.connect(self.stop_run)
|
|
487
|
+
run_row.addWidget(self.stop_button)
|
|
488
|
+
|
|
489
|
+
run_row.addStretch(1)
|
|
490
|
+
outer.addLayout(run_row)
|
|
491
|
+
|
|
492
|
+
self.progress = QProgressBar()
|
|
493
|
+
self.progress.setRange(0, 100)
|
|
494
|
+
self.progress.setValue(0)
|
|
495
|
+
self.progress.hide()
|
|
496
|
+
outer.addWidget(self.progress)
|
|
497
|
+
|
|
498
|
+
self.console_output = QTextEdit()
|
|
499
|
+
self.console_output.setReadOnly(True)
|
|
500
|
+
self.console_output.setStyleSheet(
|
|
501
|
+
"background-color: black; color: white; font-family: monospace; border-radius: 4px;"
|
|
502
|
+
)
|
|
503
|
+
self.console_output.setMinimumHeight(220)
|
|
504
|
+
outer.addWidget(self.console_output)
|
|
505
|
+
|
|
506
|
+
# ------------------------------------------------------------------
|
|
507
|
+
# Input handling
|
|
508
|
+
# ------------------------------------------------------------------
|
|
509
|
+
def _warn_if_spaces(self, file_path, what="CSV"):
|
|
510
|
+
"""ROBERT rejects CSV file names with spaces (the folders can have them), so warn as soon
|
|
511
|
+
as the file is picked instead of letting the run fail. Returns True if there are spaces."""
|
|
512
|
+
return warn_if_csv_name_has_spaces(self, file_path, what, "CHECKML")
|
|
513
|
+
|
|
514
|
+
def set_csv_path(self, file_path):
|
|
515
|
+
if self._warn_if_spaces(file_path, "input CSV"):
|
|
516
|
+
return False
|
|
517
|
+
|
|
518
|
+
df = smart_read_csv(file_path)
|
|
519
|
+
if df is None:
|
|
520
|
+
QMessageBox.warning(self, "CHECKML", f"Could not read CSV file:\n{file_path}")
|
|
521
|
+
return False
|
|
522
|
+
|
|
523
|
+
self.csv_path = file_path
|
|
524
|
+
self.csv_label.setText(f"Selected: {Path(file_path).name}")
|
|
525
|
+
self.csv_label.setToolTip(file_path)
|
|
526
|
+
|
|
527
|
+
columns = list(df.columns)
|
|
528
|
+
lower_map = {col.lower(): col for col in columns}
|
|
529
|
+
name_column = lower_map.get("code_name")
|
|
530
|
+
target_column = next(
|
|
531
|
+
(lower_map[name] for name in ("target", "y") if name in lower_map),
|
|
532
|
+
None,
|
|
533
|
+
) or next(
|
|
534
|
+
(col for col in columns if col != name_column and col.lower() not in {"set", "smiles"}
|
|
535
|
+
and pd.api.types.is_numeric_dtype(df[col])),
|
|
536
|
+
None,
|
|
537
|
+
)
|
|
538
|
+
if target_column is None:
|
|
539
|
+
target_column = next(
|
|
540
|
+
(col for col in columns if col != name_column and col.lower() not in {"set", "smiles"}),
|
|
541
|
+
None,
|
|
542
|
+
)
|
|
543
|
+
self.y_dropdown.blockSignals(True)
|
|
544
|
+
self.names_dropdown.blockSignals(True)
|
|
545
|
+
try:
|
|
546
|
+
self.y_dropdown.clear()
|
|
547
|
+
self.y_dropdown.addItems(columns)
|
|
548
|
+
self.names_dropdown.clear()
|
|
549
|
+
self.names_dropdown.addItems(columns)
|
|
550
|
+
if target_column is not None:
|
|
551
|
+
self.y_dropdown.setCurrentText(target_column)
|
|
552
|
+
else:
|
|
553
|
+
self.y_dropdown.setCurrentIndex(-1)
|
|
554
|
+
if name_column is not None:
|
|
555
|
+
self.names_dropdown.setCurrentText(name_column)
|
|
556
|
+
finally:
|
|
557
|
+
self.y_dropdown.blockSignals(False)
|
|
558
|
+
self.names_dropdown.blockSignals(False)
|
|
559
|
+
|
|
560
|
+
# text (non-numeric) columns can't be descriptors in CHECKML (no one-hot encoding); apart
|
|
561
|
+
# from names, a classification target, 'Set' and SMILES, they stop the run in _validate()
|
|
562
|
+
self.csv_columns = columns
|
|
563
|
+
self.text_columns = [
|
|
564
|
+
col for col in columns
|
|
565
|
+
if col.lower() != "set" and not pd.api.types.is_numeric_dtype(df[col])
|
|
566
|
+
]
|
|
567
|
+
self._refresh_result_summary()
|
|
568
|
+
self._refresh_sibling_tabs()
|
|
569
|
+
|
|
570
|
+
def get_ignored_columns(self):
|
|
571
|
+
"""Columns excluded automatically from the descriptors by CHECKML: only SMILES (any
|
|
572
|
+
capitalization, even if it parses as numbers). 'Set' (user-defined test set) is also
|
|
573
|
+
handled by CHECKML itself."""
|
|
574
|
+
return [col for col in self.csv_columns if col.lower() == "smiles"]
|
|
575
|
+
|
|
576
|
+
def get_extra_text_columns(self):
|
|
577
|
+
"""Text columns that would be used as descriptors (names, target, Set and SMILES excluded)."""
|
|
578
|
+
skip = {self.y_dropdown.currentText(), self.names_dropdown.currentText(), *self.get_ignored_columns()}
|
|
579
|
+
return [col for col in self.text_columns if col not in skip]
|
|
580
|
+
|
|
581
|
+
def set_csv_test_path(self, file_path):
|
|
582
|
+
if self._warn_if_spaces(file_path, "external test CSV"):
|
|
583
|
+
return False
|
|
584
|
+
if self.csv_path and Path(file_path).resolve() == Path(self.csv_path).resolve():
|
|
585
|
+
QMessageBox.warning(self, "CHECKML", "The external test CSV must differ from the input CSV.")
|
|
586
|
+
return False
|
|
587
|
+
if smart_read_csv(file_path) is None:
|
|
588
|
+
QMessageBox.warning(self, "CHECKML", f"Could not read external test CSV:\n{file_path}")
|
|
589
|
+
return False
|
|
590
|
+
self.csv_test_path = file_path
|
|
591
|
+
self.csv_test_label.setText(f"Selected: {Path(file_path).name}")
|
|
592
|
+
self.csv_test_label.setToolTip(file_path)
|
|
593
|
+
self.clear_csv_test_button.setEnabled(True)
|
|
594
|
+
self._refresh_result_summary()
|
|
595
|
+
|
|
596
|
+
def clear_csv_test_path(self):
|
|
597
|
+
self.csv_test_path = None
|
|
598
|
+
self.csv_test_label.full_file_path = None
|
|
599
|
+
self.csv_test_label.setText("Drag & Drop an external test CSV here (optional)")
|
|
600
|
+
self.csv_test_label.setToolTip("")
|
|
601
|
+
self.clear_csv_test_button.setEnabled(False)
|
|
602
|
+
self._refresh_result_summary()
|
|
603
|
+
|
|
604
|
+
def _refresh_result_summary(self):
|
|
605
|
+
"""Synchronize the bot summary action with CheckML result files."""
|
|
606
|
+
refresh = getattr(self.window(), "_refresh_workflow_result_snapshot", None)
|
|
607
|
+
if callable(refresh):
|
|
608
|
+
refresh()
|
|
609
|
+
|
|
610
|
+
def set_model_params_path(self, file_path):
|
|
611
|
+
self.model_params_path = file_path
|
|
612
|
+
self.model_params_label.setText(f"Selected: {Path(file_path).name}")
|
|
613
|
+
self.model_params_label.setToolTip(file_path)
|
|
614
|
+
|
|
615
|
+
def set_model_file_path(self, file_path):
|
|
616
|
+
self.model_file_path = file_path
|
|
617
|
+
self.model_file_label.setText(f"Selected: {Path(file_path).name}")
|
|
618
|
+
self.model_file_label.setToolTip(file_path)
|
|
619
|
+
|
|
620
|
+
def _on_model_source_changed(self, index):
|
|
621
|
+
self.sklearn_picker_container.hide()
|
|
622
|
+
self.model_params_label.hide()
|
|
623
|
+
self.model_params_info.hide()
|
|
624
|
+
self.model_file_label.hide()
|
|
625
|
+
if index == 1:
|
|
626
|
+
self.sklearn_picker_container.show()
|
|
627
|
+
self._refresh_sklearn_model_list()
|
|
628
|
+
elif index == 2:
|
|
629
|
+
self.model_params_label.show()
|
|
630
|
+
self.model_params_info.show()
|
|
631
|
+
elif index == 3:
|
|
632
|
+
self.model_file_label.show()
|
|
633
|
+
|
|
634
|
+
def _on_type_changed(self):
|
|
635
|
+
if self.model_source_dropdown.currentIndex() == 1:
|
|
636
|
+
self._refresh_sklearn_model_list()
|
|
637
|
+
|
|
638
|
+
def _current_pred_type(self):
|
|
639
|
+
return 'clas' if self.type_dropdown.currentText() == "Classification" else 'reg'
|
|
640
|
+
|
|
641
|
+
def _refresh_sklearn_model_list(self):
|
|
642
|
+
current_name = self.sklearn_model_dropdown.currentText()
|
|
643
|
+
names = [name for name, _ in _sklearn_estimators(self._current_pred_type())]
|
|
644
|
+
|
|
645
|
+
self.sklearn_model_dropdown.blockSignals(True)
|
|
646
|
+
self.sklearn_model_dropdown.clear()
|
|
647
|
+
self.sklearn_model_dropdown.addItems(names)
|
|
648
|
+
if current_name in names:
|
|
649
|
+
self.sklearn_model_dropdown.setCurrentText(current_name)
|
|
650
|
+
self.sklearn_model_dropdown.blockSignals(False)
|
|
651
|
+
|
|
652
|
+
self._rebuild_sklearn_param_form()
|
|
653
|
+
|
|
654
|
+
def _rebuild_sklearn_param_form(self):
|
|
655
|
+
while self.sklearn_params_form.rowCount() > 0:
|
|
656
|
+
self.sklearn_params_form.removeRow(0)
|
|
657
|
+
self.sklearn_param_fields = {}
|
|
658
|
+
|
|
659
|
+
model_name = self.sklearn_model_dropdown.currentText()
|
|
660
|
+
if not model_name:
|
|
661
|
+
return
|
|
662
|
+
|
|
663
|
+
estimators = dict(_sklearn_estimators(self._current_pred_type()))
|
|
664
|
+
model_cls = estimators.get(model_name)
|
|
665
|
+
if model_cls is None:
|
|
666
|
+
return
|
|
667
|
+
|
|
668
|
+
for param_name, default_repr in _constructor_params(model_cls):
|
|
669
|
+
field = QLineEdit()
|
|
670
|
+
field.setPlaceholderText(default_repr if default_repr else "(required)")
|
|
671
|
+
self.sklearn_param_fields[param_name] = field
|
|
672
|
+
self.sklearn_params_form.addRow(QLabel(param_name), field)
|
|
673
|
+
|
|
674
|
+
def _write_sklearn_params_csv(self):
|
|
675
|
+
"""Writes the picked model + any non-blank hyperparameter fields to a temp CSV, reusing
|
|
676
|
+
the exact same --model_params mechanism as the "upload a CSV" model source."""
|
|
677
|
+
|
|
678
|
+
rows = [("param", "value"), ("model", self.sklearn_model_dropdown.currentText())]
|
|
679
|
+
for param_name, field in self.sklearn_param_fields.items():
|
|
680
|
+
text = field.text().strip()
|
|
681
|
+
if text:
|
|
682
|
+
rows.append((param_name, text))
|
|
683
|
+
|
|
684
|
+
fd, path = tempfile.mkstemp(prefix="robert_gui_model_params_", suffix=".csv")
|
|
685
|
+
with os.fdopen(fd, "w", newline="", encoding="utf-8") as csv_file:
|
|
686
|
+
csv.writer(csv_file).writerows(rows)
|
|
687
|
+
return path
|
|
688
|
+
|
|
689
|
+
# ------------------------------------------------------------------
|
|
690
|
+
# Validation + command building
|
|
691
|
+
# ------------------------------------------------------------------
|
|
692
|
+
def _validate(self):
|
|
693
|
+
if not self.csv_path:
|
|
694
|
+
QMessageBox.warning(self, "CHECKML", "Please select an input CSV file (its name can't contain spaces).")
|
|
695
|
+
return False
|
|
696
|
+
|
|
697
|
+
if self.csv_test_path and Path(self.csv_test_path).resolve() == Path(self.csv_path).resolve():
|
|
698
|
+
QMessageBox.warning(self, "CHECKML", "The external test CSV must differ from the input CSV.")
|
|
699
|
+
return False
|
|
700
|
+
|
|
701
|
+
if not self.y_dropdown.currentText():
|
|
702
|
+
QMessageBox.warning(self, "CHECKML", "Please select the y (target) column.")
|
|
703
|
+
return False
|
|
704
|
+
|
|
705
|
+
if not self.names_dropdown.currentText():
|
|
706
|
+
QMessageBox.warning(self, "CHECKML", "Please select the names (ID) column.")
|
|
707
|
+
return False
|
|
708
|
+
|
|
709
|
+
if self.y_dropdown.currentText() == self.names_dropdown.currentText():
|
|
710
|
+
QMessageBox.warning(
|
|
711
|
+
self,
|
|
712
|
+
"CHECKML",
|
|
713
|
+
"The target and names columns must be different. Please select two columns.",
|
|
714
|
+
)
|
|
715
|
+
return False
|
|
716
|
+
|
|
717
|
+
extra_text_columns = self.get_extra_text_columns()
|
|
718
|
+
if extra_text_columns:
|
|
719
|
+
QMessageBox.warning(
|
|
720
|
+
self,
|
|
721
|
+
"CHECKML",
|
|
722
|
+
"These columns contain text and can't be used as descriptors: "
|
|
723
|
+
f"{', '.join(extra_text_columns)}.\n\nCheckML accepts ONLY the names, target and "
|
|
724
|
+
"descriptors used by the model (plus an optional SMILES column). Remove the other "
|
|
725
|
+
"columns from the CSV and load it again.",
|
|
726
|
+
)
|
|
727
|
+
return False
|
|
728
|
+
|
|
729
|
+
source_index = self.model_source_dropdown.currentIndex()
|
|
730
|
+
if source_index == 1 and not self.sklearn_model_dropdown.currentText():
|
|
731
|
+
QMessageBox.warning(
|
|
732
|
+
self, "CHECKML", "Please pick a scikit-learn model, or choose a "
|
|
733
|
+
"different model source."
|
|
734
|
+
)
|
|
735
|
+
return False
|
|
736
|
+
if source_index == 2 and not self.model_params_path:
|
|
737
|
+
QMessageBox.warning(
|
|
738
|
+
self, "CHECKML", "Please select a hyperparameters CSV, or choose a "
|
|
739
|
+
"different model source."
|
|
740
|
+
)
|
|
741
|
+
return False
|
|
742
|
+
if source_index == 3 and not self.model_file_path:
|
|
743
|
+
QMessageBox.warning(
|
|
744
|
+
self, "CHECKML", "Please select a saved model file, or choose a "
|
|
745
|
+
"different model source."
|
|
746
|
+
)
|
|
747
|
+
return False
|
|
748
|
+
|
|
749
|
+
return True
|
|
750
|
+
|
|
751
|
+
def _resolve_python_executable(self):
|
|
752
|
+
python_pointer = sys.executable or "python"
|
|
753
|
+
if getattr(sys, "frozen", False):
|
|
754
|
+
embedded_env = Path.cwd() / "_internal" / "robert_env"
|
|
755
|
+
if sys.platform == "win32":
|
|
756
|
+
python_pointer = embedded_env / "python.exe"
|
|
757
|
+
elif sys.platform == "darwin":
|
|
758
|
+
python_pointer = embedded_env / "bin" / "python3"
|
|
759
|
+
else:
|
|
760
|
+
python_pointer = embedded_env / "bin" / "python"
|
|
761
|
+
return str(python_pointer)
|
|
762
|
+
|
|
763
|
+
def _build_command(self):
|
|
764
|
+
python_pointer = self._resolve_python_executable()
|
|
765
|
+
|
|
766
|
+
command = (
|
|
767
|
+
f'"{python_pointer}" -u -m robert --checkml '
|
|
768
|
+
f'--csv_name "{os.path.basename(self.csv_path)}" '
|
|
769
|
+
f'--y "{self.y_dropdown.currentText()}" '
|
|
770
|
+
f'--names "{self.names_dropdown.currentText()}"'
|
|
771
|
+
)
|
|
772
|
+
|
|
773
|
+
if self.type_dropdown.currentText() == "Classification":
|
|
774
|
+
command += ' --type "clas"'
|
|
775
|
+
|
|
776
|
+
# no --ignore: CHECKML doesn't accept it and excludes SMILES columns by itself
|
|
777
|
+
|
|
778
|
+
if self.csv_test_path:
|
|
779
|
+
command += f' --csv_test "{self.csv_test_path}"'
|
|
780
|
+
|
|
781
|
+
source_index = self.model_source_dropdown.currentIndex()
|
|
782
|
+
if source_index == 1:
|
|
783
|
+
temp_params_csv = self._write_sklearn_params_csv()
|
|
784
|
+
command += f' --model_params "{temp_params_csv}"'
|
|
785
|
+
elif source_index == 2:
|
|
786
|
+
command += f' --model_params "{self.model_params_path}"'
|
|
787
|
+
elif source_index == 3:
|
|
788
|
+
command += f' --model_file "{self.model_file_path}"'
|
|
789
|
+
|
|
790
|
+
return command
|
|
791
|
+
|
|
792
|
+
# ------------------------------------------------------------------
|
|
793
|
+
# Run / stop
|
|
794
|
+
# ------------------------------------------------------------------
|
|
795
|
+
def run_checkml(self):
|
|
796
|
+
if not self._validate():
|
|
797
|
+
return
|
|
798
|
+
|
|
799
|
+
if not self._workflow_run_lock.try_acquire():
|
|
800
|
+
QMessageBox.warning(
|
|
801
|
+
self, "Workflow already running",
|
|
802
|
+
"ROBERT or CheckML is already running. Wait for it to finish before starting another run.",
|
|
803
|
+
)
|
|
804
|
+
return
|
|
805
|
+
|
|
806
|
+
command = self._build_command()
|
|
807
|
+
run_dir = os.path.dirname(self.csv_path)
|
|
808
|
+
report_path = Path(run_dir) / "ROBERT_report_No_PFI.pdf"
|
|
809
|
+
report_stat = report_path.stat() if report_path.is_file() else None
|
|
810
|
+
self._report_before_run = (
|
|
811
|
+
(report_stat.st_mtime_ns, report_stat.st_size) if report_stat else None
|
|
812
|
+
)
|
|
813
|
+
|
|
814
|
+
self.run_button.setDisabled(True)
|
|
815
|
+
self.stop_button.setDisabled(False)
|
|
816
|
+
self.manual_stop = False
|
|
817
|
+
|
|
818
|
+
self.console_output.clear()
|
|
819
|
+
self.console_output.append(
|
|
820
|
+
"<b><span style='color:purple;'>Running CHECKML...</span></b><br>"
|
|
821
|
+
)
|
|
822
|
+
self.progress.show()
|
|
823
|
+
self.progress.setRange(0, 0)
|
|
824
|
+
|
|
825
|
+
self.worker = RobertWorker(command, run_dir)
|
|
826
|
+
self.worker.output_received.connect(self.console_output.append)
|
|
827
|
+
self.worker.error_received.connect(self.console_output.append)
|
|
828
|
+
self.worker.process_finished.connect(self._on_process_finished)
|
|
829
|
+
self.worker.start()
|
|
830
|
+
self._refresh_result_summary()
|
|
831
|
+
|
|
832
|
+
def stop_run(self):
|
|
833
|
+
if self.worker:
|
|
834
|
+
self.manual_stop = True
|
|
835
|
+
self.worker.stop()
|
|
836
|
+
|
|
837
|
+
def _reset_ui_after_process(self):
|
|
838
|
+
self._workflow_run_lock.release()
|
|
839
|
+
self.run_button.setDisabled(False)
|
|
840
|
+
self.stop_button.setDisabled(True)
|
|
841
|
+
self.progress.setRange(0, 100)
|
|
842
|
+
self.progress.setValue(0)
|
|
843
|
+
self.progress.hide()
|
|
844
|
+
self._refresh_result_summary()
|
|
845
|
+
|
|
846
|
+
def _on_process_finished(self, exit_code):
|
|
847
|
+
if self.worker:
|
|
848
|
+
if self.worker.process and self.worker.process.poll() is None:
|
|
849
|
+
self.worker.stop()
|
|
850
|
+
self.worker = None
|
|
851
|
+
|
|
852
|
+
if self.manual_stop or exit_code == -1:
|
|
853
|
+
self.manual_stop = False
|
|
854
|
+
self._reset_ui_after_process()
|
|
855
|
+
QMessageBox.information(self, "CHECKML", "CHECKML has been stopped.")
|
|
856
|
+
return
|
|
857
|
+
|
|
858
|
+
self._reset_ui_after_process()
|
|
859
|
+
|
|
860
|
+
# ROBERT also exits with code 0 when it stops on a bad input (i.e. an invalid option or a
|
|
861
|
+
# CSV name with spaces), so success also needs the report the run is supposed to produce
|
|
862
|
+
run_dir = os.path.dirname(self.csv_path) if self.csv_path else ""
|
|
863
|
+
report_path = Path(run_dir) / "ROBERT_report_No_PFI.pdf"
|
|
864
|
+
report_stat = report_path.stat() if report_path.is_file() else None
|
|
865
|
+
report_created = report_stat is not None and (
|
|
866
|
+
self._report_before_run is None
|
|
867
|
+
or (report_stat.st_mtime_ns, report_stat.st_size) != self._report_before_run
|
|
868
|
+
)
|
|
869
|
+
if exit_code == 0 and not report_created:
|
|
870
|
+
message = "CHECKML did not create a new report. Check the log above."
|
|
871
|
+
self.console_output.append(
|
|
872
|
+
f"<b><span style='color:red;'>{message}</span></b>"
|
|
873
|
+
)
|
|
874
|
+
QMessageBox.warning(self, "CHECKML", message)
|
|
875
|
+
elif exit_code == 0:
|
|
876
|
+
self.console_output.append(
|
|
877
|
+
"<b><span style='color:green;'>CHECKML finished successfully.</span></b>"
|
|
878
|
+
)
|
|
879
|
+
self._refresh_sibling_tabs()
|
|
880
|
+
QMessageBox.information(
|
|
881
|
+
self, "CHECKML",
|
|
882
|
+
"CHECKML finished successfully.\n\n"
|
|
883
|
+
"Check the 'Results' tab for the PDF and prediction dashboard."
|
|
884
|
+
)
|
|
885
|
+
else:
|
|
886
|
+
message = f"CHECKML finished with errors (exit code {exit_code}). Check the log above."
|
|
887
|
+
self.console_output.append(
|
|
888
|
+
f"<b><span style='color:red;'>{message}</span></b>"
|
|
889
|
+
)
|
|
890
|
+
QMessageBox.warning(self, "CHECKML", message)
|
|
891
|
+
|
|
892
|
+
def _refresh_sibling_tabs(self):
|
|
893
|
+
"""Refreshes the Reports/Predictions/Images tabs, mirroring the main ROBERT tab."""
|
|
894
|
+
main_window = self.window()
|
|
895
|
+
if not self.csv_path or not hasattr(main_window, "refresh_tabs"):
|
|
896
|
+
return
|
|
897
|
+
main_window.refresh_tabs(self.csv_path, source_kind="CHECKML")
|
|
898
|
+
self._refresh_result_summary()
|