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.
Files changed (261) hide show
  1. robert/__init__.py +9 -0
  2. robert/__main__.py +20 -0
  3. robert/_version.py +3 -0
  4. robert/api.py +646 -0
  5. robert/aqme.py +280 -0
  6. robert/argument_parser.py +98 -0
  7. robert/checkml.py +433 -0
  8. robert/checkml_score.py +50 -0
  9. robert/curate.py +217 -0
  10. robert/evaluate_bot_retrieval.py +125 -0
  11. robert/evaluate_bot_support.py +102 -0
  12. robert/evaluate_workflow_summaries.py +87 -0
  13. robert/export_bot_docs_knowledge.py +1632 -0
  14. robert/generate.py +249 -0
  15. robert/generate_utils.py +311 -0
  16. robert/gui_easyrob/__init__.py +0 -0
  17. robert/gui_easyrob/assets/gif_easyrob.gif +0 -0
  18. robert/gui_easyrob/bot/__init__.py +47 -0
  19. robert/gui_easyrob/bot/answer_metadata.py +198 -0
  20. robert/gui_easyrob/bot/bot_context.py +679 -0
  21. robert/gui_easyrob/bot/bot_engine.py +1100 -0
  22. robert/gui_easyrob/bot/bot_panel.py +1231 -0
  23. robert/gui_easyrob/bot/bot_rag.py +1178 -0
  24. robert/gui_easyrob/bot/bot_window.py +39 -0
  25. robert/gui_easyrob/bot/bot_worker.py +149 -0
  26. robert/gui_easyrob/bot/credential_store.py +143 -0
  27. robert/gui_easyrob/bot/error_parser.py +105 -0
  28. robert/gui_easyrob/bot/evidence_policy.py +164 -0
  29. robert/gui_easyrob/bot/heuristics.py +859 -0
  30. robert/gui_easyrob/bot/icons.py +56 -0
  31. robert/gui_easyrob/bot/input_csv_audit.py +212 -0
  32. robert/gui_easyrob/bot/knowledge/aqme_context.json +5907 -0
  33. robert/gui_easyrob/bot/knowledge/robert_context.json +4817 -0
  34. robert/gui_easyrob/bot/knowledge/ui_context.json +8293 -0
  35. robert/gui_easyrob/bot/knowledge_schema.py +1252 -0
  36. robert/gui_easyrob/bot/knowledge_sources/aqme_user_guidance.json +442 -0
  37. robert/gui_easyrob/bot/knowledge_sources/coverage_manifest.json +95 -0
  38. robert/gui_easyrob/bot/knowledge_sources/robert_user_guidance.json +471 -0
  39. robert/gui_easyrob/bot/knowledge_sources/ui_user_guidance.json +1312 -0
  40. robert/gui_easyrob/bot/llm_providers.py +1573 -0
  41. robert/gui_easyrob/bot/online_docs.py +105 -0
  42. robert/gui_easyrob/bot/prompt_policy.py +575 -0
  43. robert/gui_easyrob/bot/question_intent.py +562 -0
  44. robert/gui_easyrob/bot/response_quality.py +104 -0
  45. robert/gui_easyrob/bot/result_insights.py +225 -0
  46. robert/gui_easyrob/bot/token_usage.py +75 -0
  47. robert/gui_easyrob/bot/workflow_results.py +1396 -0
  48. robert/gui_easyrob/checkml_launcher.py +15 -0
  49. robert/gui_easyrob/easyrob.py +29 -0
  50. robert/gui_easyrob/easyrob_launcher.py +113 -0
  51. robert/gui_easyrob/main/__init__.py +9 -0
  52. robert/gui_easyrob/main/window.py +5152 -0
  53. robert/gui_easyrob/result_navigation.py +14 -0
  54. robert/gui_easyrob/tabs/__init__.py +23 -0
  55. robert/gui_easyrob/tabs/advanced_options.py +370 -0
  56. robert/gui_easyrob/tabs/aqme.py +1234 -0
  57. robert/gui_easyrob/tabs/checkml.py +898 -0
  58. robert/gui_easyrob/tabs/images.py +427 -0
  59. robert/gui_easyrob/tabs/interactive_predictions.py +555 -0
  60. robert/gui_easyrob/tabs/molssi.py +447 -0
  61. robert/gui_easyrob/tabs/predictions.py +484 -0
  62. robert/gui_easyrob/tabs/result_catalog.py +170 -0
  63. robert/gui_easyrob/tabs/results.py +490 -0
  64. robert/gui_easyrob/tabs/results_workspace.py +120 -0
  65. robert/gui_easyrob/test_bot_input_csv_audit.py +152 -0
  66. robert/gui_easyrob/test_bot_question_routing.py +383 -0
  67. robert/gui_easyrob/test_bot_result_analysis.py +356 -0
  68. robert/gui_easyrob/test_bot_retrieval_evaluation.py +110 -0
  69. robert/gui_easyrob/test_bot_ui_integration.py +278 -0
  70. robert/gui_easyrob/test_checkml_app_mode.py +124 -0
  71. robert/gui_easyrob/test_checkml_completion.py +57 -0
  72. robert/gui_easyrob/test_checkml_defaults.py +37 -0
  73. robert/gui_easyrob/test_checkml_result_summary.py +113 -0
  74. robert/gui_easyrob/test_checkml_web_mode.py +57 -0
  75. robert/gui_easyrob/test_dialog_layout.py +33 -0
  76. robert/gui_easyrob/test_gui_bot_regressions.py +320 -0
  77. robert/gui_easyrob/test_molssi_auto.py +569 -0
  78. robert/gui_easyrob/test_tutorial_view.py +215 -0
  79. robert/gui_easyrob/tutorials/check_model.md +25 -0
  80. robert/gui_easyrob/tutorials/chemdraw.md +49 -0
  81. robert/gui_easyrob/tutorials/csv.md +53 -0
  82. robert/gui_easyrob/tutorials/descriptors.md +21 -0
  83. robert/gui_easyrob/tutorials/overview.md +65 -0
  84. robert/gui_easyrob/tutorials/predictions.md +25 -0
  85. robert/gui_easyrob/tutorials/robbot.md +29 -0
  86. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_1.png +0 -0
  87. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_2.png +0 -0
  88. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_3.png +0 -0
  89. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_4.png +0 -0
  90. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_5.png +0 -0
  91. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_6.png +0 -0
  92. robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_7.png +0 -0
  93. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_1.png +0 -0
  94. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_10.png +0 -0
  95. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_11.png +0 -0
  96. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_12.png +0 -0
  97. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_13.png +0 -0
  98. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_2.png +0 -0
  99. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_3.png +0 -0
  100. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_4.png +0 -0
  101. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_5.png +0 -0
  102. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_6.png +0 -0
  103. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_7.png +0 -0
  104. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_8.png +0 -0
  105. robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_9.png +0 -0
  106. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1.png +0 -0
  107. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_1.png +0 -0
  108. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_2.png +0 -0
  109. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_3.png +0 -0
  110. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_4.png +0 -0
  111. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_5.png +0 -0
  112. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_2.png +0 -0
  113. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_3.png +0 -0
  114. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_4.png +0 -0
  115. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_5.png +0 -0
  116. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_6.png +0 -0
  117. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_7.png +0 -0
  118. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_8.png +0 -0
  119. robert/gui_easyrob/tutorials/tutorial_images/csv/csv_9.png +0 -0
  120. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_1.png +0 -0
  121. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_2.png +0 -0
  122. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_3.png +0 -0
  123. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_4.png +0 -0
  124. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_5.png +0 -0
  125. robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_6.png +0 -0
  126. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1.png +0 -0
  127. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_1.png +0 -0
  128. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_2.png +0 -0
  129. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_3.png +0 -0
  130. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_4.png +0 -0
  131. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_5.png +0 -0
  132. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_6.png +0 -0
  133. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_7.png +0 -0
  134. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_8.png +0 -0
  135. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_2.png +0 -0
  136. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_3.png +0 -0
  137. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_4.png +0 -0
  138. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5.png +0 -0
  139. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_1.png +0 -0
  140. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_2.png +0 -0
  141. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_3.png +0 -0
  142. robert/gui_easyrob/tutorials/tutorial_images/overview/overview_6.png +0 -0
  143. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1.png +0 -0
  144. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1_1.png +0 -0
  145. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_2.png +0 -0
  146. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_3.png +0 -0
  147. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_4.png +0 -0
  148. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_5.png +0 -0
  149. robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_6.png +0 -0
  150. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_1.png +0 -0
  151. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_2.png +0 -0
  152. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_3.png +0 -0
  153. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_4.png +0 -0
  154. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_5.png +0 -0
  155. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_6.png +0 -0
  156. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_7.png +0 -0
  157. robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_8.png +0 -0
  158. robert/gui_easyrob/utils/__init__.py +0 -0
  159. robert/gui_easyrob/utils/aqme_utils.py +238 -0
  160. robert/gui_easyrob/utils/molssi_utils.py +584 -0
  161. robert/gui_easyrob/utils/predictions_utils.py +985 -0
  162. robert/gui_easyrob/utils/utils_gui.py +738 -0
  163. robert/gui_easyrob/version.py +68 -0
  164. robert/gui_easyrob/web/app.css +484 -0
  165. robert/gui_easyrob/web/app.html +134 -0
  166. robert/gui_easyrob/web/app.js +764 -0
  167. robert/gui_easyrob/web/checkml_brand.png +0 -0
  168. robert/gui_easyrob/web/easyrob_background.gif +0 -0
  169. robert/gui_easyrob/web/easyrob_background.png +0 -0
  170. robert/gui_easyrob/web/images.css +89 -0
  171. robert/gui_easyrob/web/images.html +39 -0
  172. robert/gui_easyrob/web/images.js +101 -0
  173. robert/gui_easyrob/web/results.js +499 -0
  174. robert/gui_easyrob/web/robert_brand.png +0 -0
  175. robert/gui_easyrob/web_dialogs.py +64 -0
  176. robert/gui_easyrob/web_results.py +253 -0
  177. robert/gui_easyrob/web_shell.py +684 -0
  178. robert/gui_easyrob/workflow_progress.py +89 -0
  179. robert/gui_easyrob/workflow_run_lock.py +27 -0
  180. robert/icons/CheckML_icon.png +0 -0
  181. robert/icons/Robert_icon.png +0 -0
  182. robert/icons/Robert_logo.jpg +0 -0
  183. robert/icons/Robert_logo_transparent.png +0 -0
  184. robert/icons/documentation_icon.png +0 -0
  185. robert/icons/info_icon.png +0 -0
  186. robert/icons/pdf_icon.png +0 -0
  187. robert/icons/play_icon.png +0 -0
  188. robert/icons/stop_icon.png +0 -0
  189. robert/icons/youtube_icon.ico +0 -0
  190. robert/predict.py +193 -0
  191. robert/predict_utils.py +410 -0
  192. robert/report/CheckML_logo.jpg +0 -0
  193. robert/report/GENERATE.png +0 -0
  194. robert/report/Robert_icon.ico +0 -0
  195. robert/report/Robert_logo.jpg +0 -0
  196. robert/report/Robert_logo1.jpg +0 -0
  197. robert/report/abbrev.png +0 -0
  198. robert/report/adv_anal.png +0 -0
  199. robert/report/checkml_pass.svg +3 -0
  200. robert/report/checkml_unclear.svg +3 -0
  201. robert/report/checkml_warning.svg +3 -0
  202. robert/report/features.png +0 -0
  203. robert/report/outliers.png +0 -0
  204. robert/report/pred.png +0 -0
  205. robert/report/repro.png +0 -0
  206. robert/report/robust_x.png +0 -0
  207. robert/report/robust_y_high.png +0 -0
  208. robert/report/robust_y_low.png +0 -0
  209. robert/report/score.png +0 -0
  210. robert/report/score_0.jpg +0 -0
  211. robert/report/score_1.jpg +0 -0
  212. robert/report/score_10.jpg +0 -0
  213. robert/report/score_2.jpg +0 -0
  214. robert/report/score_3.jpg +0 -0
  215. robert/report/score_4.jpg +0 -0
  216. robert/report/score_5.jpg +0 -0
  217. robert/report/score_6.jpg +0 -0
  218. robert/report/score_7.jpg +0 -0
  219. robert/report/score_8.jpg +0 -0
  220. robert/report/score_9.jpg +0 -0
  221. robert/report/score_gray_0.jpg +0 -0
  222. robert/report/score_gray_1.jpg +0 -0
  223. robert/report/score_gray_10.jpg +0 -0
  224. robert/report/score_gray_2.jpg +0 -0
  225. robert/report/score_gray_3.jpg +0 -0
  226. robert/report/score_gray_4.jpg +0 -0
  227. robert/report/score_gray_5.jpg +0 -0
  228. robert/report/score_gray_6.jpg +0 -0
  229. robert/report/score_gray_7.jpg +0 -0
  230. robert/report/score_gray_8.jpg +0 -0
  231. robert/report/score_gray_9.jpg +0 -0
  232. robert/report/score_w_1_0.jpg +0 -0
  233. robert/report/score_w_1_1.jpg +0 -0
  234. robert/report/score_w_2_0.jpg +0 -0
  235. robert/report/score_w_2_1.jpg +0 -0
  236. robert/report/score_w_2_2.jpg +0 -0
  237. robert/report/score_w_2_gray_0.jpg +0 -0
  238. robert/report/score_w_2_gray_1.jpg +0 -0
  239. robert/report/score_w_2_gray_2.jpg +0 -0
  240. robert/report/score_w_3_0.jpg +0 -0
  241. robert/report/score_w_3_1.jpg +0 -0
  242. robert/report/score_w_3_2.jpg +0 -0
  243. robert/report/score_w_3_3.jpg +0 -0
  244. robert/report/score_w_4_0.jpg +0 -0
  245. robert/report/score_w_4_1.JPG +0 -0
  246. robert/report/score_w_4_2.jpg +0 -0
  247. robert/report/score_w_4_3.jpg +0 -0
  248. robert/report/score_w_4_4.jpg +0 -0
  249. robert/report/transpa.png +0 -0
  250. robert/report/y_distrib.png +0 -0
  251. robert/report.py +2880 -0
  252. robert/report_utils.py +2270 -0
  253. robert/robert.py +181 -0
  254. robert/utils.py +4763 -0
  255. robert/verify.py +606 -0
  256. robert-2.2.0.dist-info/METADATA +55 -0
  257. robert-2.2.0.dist-info/RECORD +261 -0
  258. robert-2.2.0.dist-info/WHEEL +5 -0
  259. robert-2.2.0.dist-info/entry_points.txt +3 -0
  260. robert-2.2.0.dist-info/licenses/LICENSE +21 -0
  261. robert-2.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,356 @@
1
+ """Regression tests for grounded analysis of user workflow results."""
2
+
3
+ import sys
4
+ from pathlib import Path
5
+ from types import SimpleNamespace
6
+
7
+ sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
8
+
9
+ from gui_easyrob.bot.result_insights import (
10
+ extract_aqme_insight,
11
+ extract_dataset_overlap,
12
+ extract_log_insights,
13
+ extract_prediction_insight,
14
+ )
15
+ from gui_easyrob.bot.workflow_results import (
16
+ WorkflowResultStore,
17
+ render_workflow_answer,
18
+ render_workflow_evidence,
19
+ scope_workflow_result_snapshot,
20
+ )
21
+ from gui_easyrob.bot.bot_context import GuiSnapshot
22
+ from gui_easyrob.bot.bot_engine import BotEngine
23
+ from gui_easyrob.bot.bot_rag import KnowledgeBase
24
+ from gui_easyrob.bot.result_insights import ResultInsight
25
+ from gui_easyrob.bot.workflow_results import WorkflowResultSnapshot
26
+ from gui_easyrob.bot.workflow_results import WorkflowReportAssessment
27
+ from gui_easyrob.bot.workflow_results import WorkflowStageResult
28
+ from gui_easyrob.bot.prompt_policy import _is_workflow_result_question
29
+ from gui_easyrob.bot.question_intent import is_generic_question
30
+ from gui_easyrob.bot.llm_providers import ProviderAnswer, TokenUsage, _response_language
31
+
32
+
33
+ def test_log_insights_keep_feature_values_and_variants_separate():
34
+ log = """------- Starting model with all variables (No PFI) -------
35
+ o SHAP plot saved in PREDICT/SHAP_GB_No_PFI.png
36
+ - Fukui+ = min: -2.1, max: 2.6
37
+ o PFI plot saved in PREDICT/PFI_GB_No_PFI.png
38
+ Influence on RMSE
39
+ - Fukui+ = 1.9 +- 0.21
40
+ ------- Starting model with PFI filter (only important descriptors used) -------
41
+ o PFI plot saved in PREDICT/PFI_GB_PFI.png
42
+ Influence on RMSE
43
+ - Dipole = 0.8 +- 0.10
44
+ """
45
+
46
+ insights = extract_log_insights(log, "GB", "PREDICT/PREDICT_GB_data.dat")
47
+
48
+ assert [(item.variant, item.category) for item in insights] == [
49
+ ("No_PFI", "shap"), ("No_PFI", "pfi"), ("PFI", "pfi")
50
+ ]
51
+ assert "Fukui+" in insights[0].summary and "-2.1" in insights[0].summary
52
+ assert "1.9 ± 0.21" in insights[1].summary
53
+ assert "for RMSE" in insights[1].summary
54
+ assert "Dipole" not in insights[1].summary
55
+
56
+
57
+ def test_prediction_insight_reports_observed_errors_and_missing_targets(tmp_path):
58
+ path = tmp_path / "GB_No_PFI.csv"
59
+ path.write_text(
60
+ "code_name,target,target_pred,target_pred_sd,Set\n"
61
+ "acid-a,1,2,0.4,Test\n"
62
+ "acid-b,3,1,0.5,Test\n"
63
+ "acid-c,,4,0.6,Test\n"
64
+ "acid-d,4,nan,0.3,Test\n",
65
+ encoding="utf-8",
66
+ )
67
+
68
+ insight = extract_prediction_insight(path, "GB", "No_PFI", "PREDICT/GB_No_PFI.csv")
69
+
70
+ assert insight.model == "GB" and insight.variant == "No_PFI"
71
+ assert "2 evaluated" in insight.summary
72
+ assert "MAE=1.5" in insight.summary
73
+ assert "acid-b" in insight.summary and "absolute error=2" in insight.summary
74
+ assert "2 rows without comparable observed/predicted values" in insight.summary
75
+ assert "acid-c" not in insight.summary
76
+
77
+
78
+ def test_prediction_insight_without_observations_does_not_invent_errors(tmp_path):
79
+ path = tmp_path / "new_acids.csv"
80
+ path.write_text(
81
+ "code_name,target_pred,target_pred_sd\nnew-a,2.0,0.4\nnew-b,5.0,0.7\n",
82
+ encoding="utf-8",
83
+ )
84
+
85
+ insight = extract_prediction_insight(path, "GB", "PFI", "PREDICT/csv_test/new_acids.csv")
86
+
87
+ assert "2 finite predictions" in insight.summary
88
+ assert "predicted value range=2 to 5" in insight.summary
89
+ assert "observed target column absent" in insight.summary
90
+ assert "MAE" not in insight.summary
91
+
92
+
93
+ def test_workflow_evidence_scopes_feature_and_error_insights(tmp_path):
94
+ input_path = tmp_path / "acids.csv"
95
+ input_path.write_text("code_name,target\na,1\n", encoding="utf-8")
96
+ predict_dir = tmp_path / "PREDICT"
97
+ predict_dir.mkdir()
98
+ for model, feature in (("GB", "Fukui+"), ("RF", "Dipole")):
99
+ (predict_dir / f"PREDICT_{model}_data.dat").write_text(
100
+ "------- Starting model with all variables (No PFI) -------\n"
101
+ f" o PFI plot saved in PREDICT/PFI_{model}_No_PFI.png\n"
102
+ " Influence on RMSE\n"
103
+ f" - {feature} = 1.9 +- 0.21\n"
104
+ " - Test : R2 = 0.5, RMSE = 1.2\n",
105
+ encoding="utf-8",
106
+ )
107
+ (predict_dir / f"{model}_No_PFI.csv").write_text(
108
+ "code_name,target,target_pred,Set\n"
109
+ f"{model.lower()}-acid,1,3,Test\n",
110
+ encoding="utf-8",
111
+ )
112
+
113
+ snapshot = WorkflowResultStore().refresh(str(input_path), "")
114
+ scoped = scope_workflow_result_snapshot(
115
+ snapshot, "GB No_PFI descriptor importance and errors",
116
+ available_models=("GB", "RF"),
117
+ )
118
+ evidence = render_workflow_evidence(scoped, "GB No_PFI descriptor importance and errors", max_chars=5000)
119
+ answer = render_workflow_answer(scoped, "GB No_PFI descriptor importance and errors")
120
+
121
+ assert len(snapshot.insights) == 4
122
+ assert len(scoped.insights) == 2
123
+ assert "Fukui+" in evidence and "gb-acid" in evidence
124
+ assert "Dipole" not in evidence and "rf-acid" not in evidence
125
+ assert "Fukui+" in answer and "gb-acid" in answer
126
+
127
+
128
+ def test_external_prediction_question_excludes_internal_rows(tmp_path):
129
+ input_path = tmp_path / "acids.csv"
130
+ input_path.write_text("code_name,target\na,1\n", encoding="utf-8")
131
+ predict_dir = tmp_path / "PREDICT"
132
+ external_dir = predict_dir / "csv_test"
133
+ external_dir.mkdir(parents=True)
134
+ (predict_dir / "PREDICT_GB_data.dat").write_text(
135
+ "------- Starting model with all variables (No PFI) -------\n"
136
+ " - Test : R2 = 0.5, RMSE = 1.2\n"
137
+ " o SHAP plot saved in PREDICT/SHAP_GB_No_PFI.png\n"
138
+ " - Fukui+ = min: -2.1, max: 2.6\n",
139
+ encoding="utf-8",
140
+ )
141
+ (predict_dir / "GB_No_PFI.csv").write_text(
142
+ "code_name,target,target_pred,Set\ninternal-acid,1,3,Test\n", encoding="utf-8"
143
+ )
144
+ (external_dir / "input_GB_No_PFI.csv").write_text(
145
+ "code_name,target,target_pred\nexternal-acid,1,4\n", encoding="utf-8"
146
+ )
147
+
148
+ snapshot = WorkflowResultStore().refresh(str(input_path), "")
149
+ question = "GB No_PFI: analiza las predicciones externas"
150
+ evidence = render_workflow_evidence(snapshot, question)
151
+ answer = render_workflow_answer(snapshot, question)
152
+
153
+ assert "external-acid" in evidence and "internal-acid" not in evidence
154
+ assert "external-acid" in answer and "internal-acid" not in answer
155
+ assert "Fukui+" not in evidence and "Fukui+" not in answer
156
+
157
+
158
+ def test_aqme_insight_counts_missing_descriptor_values(tmp_path):
159
+ path = tmp_path / "AQME-ROBERT_full_acids.csv"
160
+ path.write_text(
161
+ "SMILES,code_name,target,charge,dipole\n"
162
+ "CCO,a,1,0.1,2.0\n"
163
+ "CCC,b,2,,nan\n"
164
+ "CCN,c,3,0.2,3.0\n",
165
+ encoding="utf-8",
166
+ )
167
+
168
+ insight = extract_aqme_insight(path, 3, path.name)
169
+
170
+ assert insight.category == "aqme_completeness"
171
+ assert "3 rows" in insight.summary
172
+ assert "2 descriptor columns" in insight.summary
173
+ assert "charge: 1/3 missing" in insight.summary
174
+ assert "dipole: 1/3 missing" in insight.summary
175
+
176
+
177
+ def test_aqme_question_prioritizes_original_descriptor_output(tmp_path):
178
+ input_path = tmp_path / "acids.csv"
179
+ input_path.write_text("code_name,target\na,1\n", encoding="utf-8")
180
+ (tmp_path / "AQME-ROBERT_full_acids.csv").write_text(
181
+ "code_name,target,charge\na,1,\n", encoding="utf-8"
182
+ )
183
+ predict_dir = tmp_path / "PREDICT"
184
+ predict_dir.mkdir()
185
+ (predict_dir / "PREDICT_GB_data.dat").write_text(
186
+ "------- Starting model with all variables (No PFI) -------\n"
187
+ " o SHAP plot saved in PREDICT/SHAP_GB_No_PFI.png\n"
188
+ " - Fukui+ = min: -2.1, max: 2.6\n",
189
+ encoding="utf-8",
190
+ )
191
+ (predict_dir / "csv_test").mkdir()
192
+ (predict_dir / "csv_test" / "AQME-ROBERT_full_acids_GB_No_PFI.csv").write_text(
193
+ "code_name,target,target_pred\na,1,2\n", encoding="utf-8"
194
+ )
195
+
196
+ snapshot = WorkflowResultStore().refresh(str(input_path), "")
197
+ evidence = render_workflow_evidence(snapshot, "Que valores AQME faltan en los descriptores?", max_chars=1200)
198
+
199
+ assert len([item for item in snapshot.insights if item.category == "aqme_completeness"]) == 1
200
+ assert "charge: 1/1 missing" in evidence
201
+ assert "Fukui+" not in evidence
202
+
203
+
204
+ def test_identical_train_and_external_smiles_are_flagged(tmp_path):
205
+ train = tmp_path / "acids.csv"
206
+ external = tmp_path / "error.csv"
207
+ train.write_text("SMILES,code_name,target\nCCO,a,1\nCCC,b,2\n", encoding="utf-8")
208
+ external.write_text("SMILES,code_name,target\nCCO,x,9\nCCC,y,8\n", encoding="utf-8")
209
+ (tmp_path / "PREDICT").mkdir()
210
+ (tmp_path / "PREDICT" / "PREDICT_data.dat").write_text("PREDICT completed\n", encoding="utf-8")
211
+
212
+ insight = extract_dataset_overlap(train, external)
213
+ snapshot = WorkflowResultStore().refresh(str(train), str(external))
214
+ evidence = render_workflow_evidence(snapshot, "Are external predictions independent?", max_chars=1500)
215
+
216
+ assert "2/2 external rows" in insight.summary
217
+ assert "not independent by exact SMILES" in insight.summary
218
+ assert "2/2 external rows" in evidence
219
+
220
+
221
+ def test_heuristic_bot_routes_feature_and_overlap_questions_to_user_results():
222
+ workflow = WorkflowResultSnapshot(
223
+ kind="AQME+ROBERT", status="completed", root_name="acids", summary_available=True,
224
+ insights=(
225
+ ResultInsight("GB", "No_PFI", "shap", "Fukui+: min=-2.1, max=2.6", "PREDICT/PREDICT_GB_data.dat"),
226
+ ResultInsight("", "", "dataset_overlap", "19/19 external rows match the main input", "acids.csv, error.csv"),
227
+ ),
228
+ )
229
+ snapshot = GuiSnapshot(
230
+ "Results", "Full Workflow", "acids.csv", "error.csv", "target", "regression",
231
+ False, True, False, "", [], workflow_results=workflow,
232
+ )
233
+ engine = BotEngine(knowledge_base=KnowledgeBase([]))
234
+
235
+ shap_answer = engine.answer("¿Qué muestra SHAP para GB?", snapshot, "Heuristic", "", "")
236
+ overlap_answer = engine.answer("¿Hay solapamiento entre mis CSV?", snapshot, "Heuristic", "", "")
237
+
238
+ assert "Fukui+" in shap_answer
239
+ assert "19/19 external rows" in overlap_answer
240
+
241
+
242
+ def test_cloud_result_questions_keep_workflow_context():
243
+ assert _is_workflow_result_question("¿Qué muestra SHAP para GB?")
244
+ assert _is_workflow_result_question("¿Hay solapamiento entre mis CSV?")
245
+ assert not is_generic_question("¿Qué valores AQME faltan en los descriptores?")
246
+
247
+
248
+ def test_cloud_bot_marks_shap_question_as_local_results():
249
+ class RecordingProvider:
250
+ spec = SimpleNamespace(supports_web_search=True)
251
+
252
+ def __init__(self):
253
+ self.calls = []
254
+
255
+ def generate_answer_with_usage(self, **kwargs):
256
+ self.calls.append(kwargs)
257
+ return ProviderAnswer("The SHAP values are in the workflow files.", TokenUsage())
258
+
259
+ provider = RecordingProvider()
260
+ workflow = WorkflowResultSnapshot(
261
+ kind="ROBERT", status="completed", root_name="acids", summary_available=True,
262
+ insights=(ResultInsight("GB", "No_PFI", "shap", "Fukui+: min=-2.1, max=2.6", "PREDICT/PREDICT_GB_data.dat"),),
263
+ )
264
+ snapshot = GuiSnapshot(
265
+ "Results", "Full Workflow", "acids.csv", "", "target", "regression",
266
+ False, True, False, "", [], workflow_results=workflow,
267
+ )
268
+ engine = BotEngine(knowledge_base=KnowledgeBase([]), provider_registry={"Test": provider})
269
+
270
+ engine.answer_with_metadata("¿Qué muestra SHAP para GB?", snapshot, "Cloud AI", "Test", "test-key")
271
+
272
+ assert len(provider.calls) == 1
273
+ assert provider.calls[0]["question_intent"] == "results"
274
+
275
+
276
+ def test_spanish_scientific_result_question_keeps_spanish_response_language():
277
+ question = (
278
+ "Con GB No_PFI, analiza el test externo de acids: "
279
+ "¿es independiente del conjunto principal? Da los errores observados más grandes "
280
+ "y cita los archivos de origen. No inventes puntuaciones."
281
+ )
282
+
283
+ assert _response_language(question) == "Spanish"
284
+
285
+
286
+ def test_result_discovery_survives_optional_report_scoring_error(tmp_path, monkeypatch):
287
+ from gui_easyrob.bot import workflow_results
288
+
289
+ input_path = tmp_path / "input.csv"
290
+ input_path.write_text("target,descriptor\n1,2\n", encoding="utf-8")
291
+ predict_dir = tmp_path / "PREDICT"
292
+ verify_dir = tmp_path / "VERIFY"
293
+ predict_dir.mkdir()
294
+ verify_dir.mkdir()
295
+ (predict_dir / "PREDICT_GB_data.dat").write_text(
296
+ "------- Starting model with all variables (No PFI) -------\n"
297
+ " - Test : R2 = 0.5, RMSE = 1.2\n",
298
+ encoding="utf-8",
299
+ )
300
+ (verify_dir / "VERIFY_GB_data.dat").write_text(
301
+ "------- Starting model with all variables (No PFI) -------\n"
302
+ " Original RMSE (10x 5-fold CV) 1.2 + 15% & 30% threshold = 1.4 & 1.6\n",
303
+ encoding="utf-8",
304
+ )
305
+
306
+ def broken_score(*_args):
307
+ raise UnboundLocalError("legacy score field missing")
308
+
309
+ monkeypatch.setattr(workflow_results, "_report_score_function", lambda: broken_score)
310
+
311
+ snapshot = WorkflowResultStore().refresh(str(input_path), "")
312
+
313
+ assert snapshot is not None
314
+ assert len(snapshot.report_assessments) == 1
315
+ assert snapshot.report_assessments[0].interpolation_score is None
316
+ assert snapshot.report_assessments[0].score_unavailable_reason == "scoring_error"
317
+
318
+
319
+ def test_external_error_evidence_prioritizes_external_metric_over_report_score():
320
+ snapshot = WorkflowResultSnapshot(
321
+ kind="ROBERT", status="completed", root_name="acids", summary_available=True,
322
+ metrics=(("RMSE", "2.3", "External test (No_PFI)", "PREDICT/PREDICT_GB_data.dat"),),
323
+ report_assessments=(WorkflowReportAssessment(
324
+ variant="No PFI", model="GB", prediction_type="regression",
325
+ interpolation_score=None, boundary_score=None, score_unavailable_reason="incomplete_log",
326
+ ),),
327
+ insights=(ResultInsight(
328
+ "GB", "No_PFI", "prediction_errors", "19 evaluated; MAE=1.65", "PREDICT/csv_test/input_GB_No_PFI.csv"
329
+ ),),
330
+ )
331
+
332
+ evidence = render_workflow_evidence(
333
+ snapshot, "GB No_PFI: analiza los errores del test externo", max_chars=1500
334
+ )
335
+
336
+ assert "Metric External test (No_PFI) RMSE=2.3" in evidence
337
+ assert "Report-derived assessment" not in evidence
338
+
339
+
340
+ def test_focused_prediction_evidence_omits_unrelated_stage_details():
341
+ snapshot = WorkflowResultSnapshot(
342
+ kind="AQME+ROBERT", status="completed", root_name="acids", summary_available=True,
343
+ stages=tuple(WorkflowStageResult(
344
+ name=name, status="completed", source=f"{name}/{name}_data.dat"
345
+ ) for name in ("CURATE", "GENERATE", "VERIFY", "PREDICT", "AQME", "CSEARCH", "QDESCP")),
346
+ metrics=(("RMSE", "2.3", "External test (No_PFI)", "PREDICT/PREDICT_GB_data.dat"),),
347
+ insights=(ResultInsight(
348
+ "GB", "No_PFI", "prediction_errors", "19 evaluated; MAE=1.65", "PREDICT/csv_test/input_GB_No_PFI.csv"
349
+ ),),
350
+ )
351
+
352
+ evidence = render_workflow_evidence(snapshot, "GB No_PFI: analiza los errores externos", max_chars=1000)
353
+
354
+ assert "Stage CURATE" not in evidence
355
+ assert "Stage PREDICT" in evidence
356
+ assert "Metric External test (No_PFI) RMSE=2.3" in evidence
@@ -0,0 +1,110 @@
1
+ """Tests for the offline evidence retrieval benchmark."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from pathlib import Path
7
+ import subprocess
8
+ import sys
9
+
10
+ from evaluate_bot_retrieval import evaluate_cases
11
+ from gui_easyrob.bot.bot_engine import BotEngine
12
+ from gui_easyrob.bot.bot_rag import KnowledgeChunk, SearchResult
13
+
14
+
15
+ def test_evaluation_reports_ranked_cases_and_language_metrics():
16
+ cases = [
17
+ {
18
+ "id": "english-hit",
19
+ "language": "en",
20
+ "question": "What does QDESCP do in AQME?",
21
+ "expected_evidence": ["module-aqme-qdescp"],
22
+ },
23
+ {
24
+ "id": "spanish-hit",
25
+ "language": "es",
26
+ "question": "¿Qué hace QDESCP en AQME?",
27
+ "expected_evidence": ["module-aqme-qdescp"],
28
+ },
29
+ {
30
+ "id": "unmatched",
31
+ "language": "en",
32
+ "question": "What does QDESCP do in AQME?",
33
+ "expected_evidence": ["intentionally-missing-evidence"],
34
+ },
35
+ ]
36
+
37
+ report = evaluate_cases(cases)
38
+
39
+ assert report["summary"]["count"] == 3
40
+ assert report["summary"]["hits_at_3"] == 2
41
+ assert report["summary"]["hit_rate_at_3"] == 2 / 3
42
+ assert report["summary"]["hit_rate_at_1"] == 2 / 3
43
+ assert report["by_language"]["es"]["hit_rate_at_3"] == 1.0
44
+ assert report["cases"][0]["rank"] == 1
45
+ assert report["cases"][2]["rank"] is None
46
+ assert report["cases"][0]["top_evidence"]
47
+
48
+
49
+ def test_cli_writes_reviewable_results_without_provider_configuration(tmp_path):
50
+ root = Path(__file__).resolve().parents[1]
51
+ cases = root / "tests" / "fixtures" / "bot_retrieval_cases.json"
52
+ output = tmp_path / "retrieval.json"
53
+
54
+ completed = subprocess.run(
55
+ [sys.executable, str(root / "evaluate_bot_retrieval.py"), "--cases", str(cases), "--output", str(output)],
56
+ cwd=root,
57
+ capture_output=True,
58
+ text=True,
59
+ check=False,
60
+ )
61
+
62
+ assert completed.returncode == 0, completed.stderr
63
+ report = json.loads(output.read_text(encoding="utf-8"))
64
+ assert report["summary"]["count"] == 27
65
+ assert set(report["by_language"]) == {"en", "es"}
66
+ assert {case["id"] for case in report["cases"]} == {
67
+ case["id"] for case in json.loads(cases.read_text(encoding="utf-8"))
68
+ }
69
+
70
+
71
+ def test_strong_technical_match_is_not_discarded_by_generic_curated_evidence():
72
+ technical = SearchResult(
73
+ KnowledgeChunk("technical", "code_docstrings", "technical", "AQME", (), "Descriptor algorithm"),
74
+ score=64.0,
75
+ )
76
+ generic = SearchResult(
77
+ KnowledgeChunk("generic", "curated_overrides", "concept", "AQME", (), "AQME overview"),
78
+ score=41.0,
79
+ )
80
+
81
+ ordered = BotEngine._prioritize_candidates([technical, generic], "tutorial")
82
+
83
+ assert ordered[0].chunk.id == "technical"
84
+
85
+
86
+ def test_near_tied_curated_evidence_keeps_priority():
87
+ technical = SearchResult(
88
+ KnowledgeChunk("technical", "code_docstrings", "technical", "AQME", (), "Descriptor algorithm"),
89
+ score=44.0,
90
+ )
91
+ curated = SearchResult(
92
+ KnowledgeChunk("curated", "curated_overrides", "concept", "AQME", (), "Descriptor guidance"),
93
+ score=41.0,
94
+ )
95
+
96
+ ordered = BotEngine._prioritize_candidates([technical, curated], "tutorial")
97
+
98
+ assert ordered[0].chunk.id == "curated"
99
+
100
+
101
+ def test_labeled_retrieval_cases_rank_relevant_evidence_first():
102
+ root = Path(__file__).resolve().parents[1]
103
+ cases = json.loads(
104
+ (root / "tests" / "fixtures" / "bot_retrieval_cases.json").read_text(encoding="utf-8")
105
+ )
106
+
107
+ report = evaluate_cases(cases)
108
+
109
+ misses = [case["id"] for case in report["cases"] if not case["matched_at_1"]]
110
+ assert misses == []