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
robert/curate.py ADDED
@@ -0,0 +1,217 @@
1
+ """
2
+ Parameters
3
+ ----------
4
+
5
+ csv_name : str, default=''
6
+ Name of the CSV file containing the database. A path can be provided (i.e. 'C:/Users/FOLDER/FILE.csv').
7
+ y : str, default=''
8
+ Name of the column containing the response variable in the input CSV file (i.e. 'solubility').
9
+ discard : list, default=[]
10
+ List containing the columns of the input CSV file that will not be included as descriptors
11
+ in the curated CSV file (i.e. "['name','SMILES']").
12
+ ignore : list, default=[]
13
+ List containing the columns of the input CSV file that will be ignored during the curation process
14
+ (i.e. "['name','SMILES']"). The descriptors will be included in the curated CSV file. The y value
15
+ is automatically ignored.
16
+ names : str, default=''
17
+ Column of the names for each datapoint. Names are used to print outliers.
18
+ destination : str, default=None,
19
+ Directory to create the output file(s).
20
+ varfile : str, default=None
21
+ Option to parse the variables using a yaml file (specify the filename, i.e. varfile=FILE.yaml).
22
+ categorical : str, default='onehot'
23
+ Mode to convert data from columns with categorical variables. As an example, a variable containing 4
24
+ types of C atoms (i.e. primary, secondary, tertiary, quaternary) will be converted into categorical
25
+ variables. Options:
26
+ 1. 'onehot' (for one-hot encoding, ROBERT will create a descriptor for each type of
27
+ C atom using 0s and 1s to indicate whether the C type is present)
28
+ 2. 'numbers' (to describe the C atoms with numbers: 1, 2, 3, 4).
29
+ corr_filter_x : bool, default=True
30
+ Activate the correlation filters of descriptors, based on the correlation
31
+ of the descriptors with other descriptors (x filter).
32
+ corr_filter_y : bool, default=False
33
+ Activate the correlation filters of descriptors, based on the correlation
34
+ of the descriptors with the y values (y filter, for noise). This filter is only
35
+ suggested for MVL.
36
+ rfecv_filter : bool, default=True
37
+ Activate RFECV/PFI descriptor selection, used when descriptors still outnumber
38
+ one-third of the datapoints after the correlation filter(s) above. Runs independently
39
+ of corr_filter_x/corr_filter_y, so either filter can be used on its own (e.g. disable
40
+ rfecv_filter to keep only the correlation filter, or disable corr_filter_x/y to rely
41
+ only on RFECV/PFI).
42
+ thres_x : float, default=0.7
43
+ Thresolhold to discard descriptors based on high R**2 correlation with other descriptors (i.e.
44
+ if thres_x=0.7, variables that show R**2 > 0.7 will be discarded).
45
+ thres_y : float, default=0.001
46
+ Thresolhold to discard descriptors with poor correlation with the y values based on R**2 (i.e.
47
+ if thres_y=0.001, variables that show R**2 < 0.001 will be discarded).
48
+ seed : int, default=0
49
+ Random seed used in RFECV feature selector and other protocols.
50
+ kfold : int, default=5
51
+ Number of random data splits for the cross-validation of the RFECV feature selector.
52
+ repeat_kfolds : int, default=10
53
+ Number of repetitions for the k-fold cross-validation of the RFECV feature selector.
54
+ auto_type : bool, default=True
55
+ If there are only two y values, the program automatically changes the type of problem to classification.
56
+ auto_fill : bool, default = True
57
+ Complete missing values in columns with descriptors of "float" type using a KNN imputer
58
+
59
+ """
60
+ #####################################################.
61
+ # This file stores the CURATE class #
62
+ # used in data curation #
63
+ #####################################################.
64
+
65
+ import time
66
+ import os
67
+ import json
68
+ import pandas as pd
69
+ from robert.utils import (load_variables, finish_print, load_database, pearson_map,
70
+ check_clas_problem, categorical_transform, correlation_filter)
71
+
72
+
73
+ class curate:
74
+ """
75
+ Class containing all the functions from the CURATE module.
76
+
77
+ Parameters
78
+ ----------
79
+ kwargs : argument class
80
+ Specify any arguments from the CURATE module (for a complete list of variables, visit the ROBERT documentation)
81
+ """
82
+
83
+ def __init__(self, **kwargs):
84
+
85
+ start_time = time.time()
86
+
87
+ # load default and user-specified variables
88
+ self.args = load_variables(kwargs, "curate")
89
+
90
+ # load database, discard user-defined descriptors and perform data checks
91
+ csv_df,_,_ = load_database(self,self.args.csv_name,"curate")
92
+
93
+ # adjust options of classification problems and detects whether the right type of problem was used
94
+ self = check_clas_problem(self,csv_df)
95
+
96
+ if not self.args.checkml:
97
+ # transform categorical descriptors
98
+ csv_df = categorical_transform(self,csv_df,'curate')
99
+
100
+ # apply duplicate filters (i.e., duplication of datapoints or descriptors)
101
+ csv_df = self.dup_filter(csv_df)
102
+
103
+ # apply the correlation filters and returns the database without correlated descriptors
104
+ if self.args.corr_filter_x or self.args.corr_filter_y:
105
+ csv_df_result = correlation_filter(self,csv_df)
106
+ # Check if result is a tuple (model-specific CSVs) or single dataframe
107
+ if isinstance(csv_df_result, tuple):
108
+ csv_df, csv_df_per_model = csv_df_result
109
+ else:
110
+ csv_df = csv_df_result
111
+ csv_df_per_model = None
112
+ else:
113
+ csv_df_per_model = None
114
+
115
+ # save the curated CSVs (one per model if RFECV is applied)
116
+ if csv_df_per_model is not None:
117
+ _ = self.save_curate((csv_df, csv_df_per_model))
118
+ else:
119
+ _ = self.save_curate(csv_df)
120
+
121
+ # create Pearson heatmap (use the general filtered dataframe)
122
+ _ = pearson_map(self,csv_df,'curate')
123
+
124
+ # finish the printing of the CURATE info file
125
+ _ = finish_print(self,start_time,'CURATE')
126
+
127
+
128
+ def dup_filter(self,csv_df_dup):
129
+ '''
130
+ Removes duplicated datapoints (rows). Duplicate descriptor columns are not deduplicated
131
+ here - they're caught separately by the correlation filter (R**2 ~= 1) when
132
+ corr_filter_x/corr_filter_y are enabled.
133
+ '''
134
+
135
+ txt_dup = f'\no Duplication filters activated'
136
+ txt_dup += f'\n Excluded datapoints:'
137
+
138
+ # remove duplicated entries (by position, so it also works when the index of the
139
+ # dataframe isn't 0..n-1, i.e. after rows were removed in load_database())
140
+ duplicated = csv_df_dup.duplicated().to_numpy()
141
+ datapoint_drop = [i for i,is_dup in enumerate(duplicated) if is_dup]
142
+ for datapoint in datapoint_drop:
143
+ txt_dup += f'\n - Datapoint number {datapoint}'
144
+
145
+ if len(datapoint_drop) == 0:
146
+ txt_dup += f'\n - No datapoints were removed'
147
+
148
+ csv_df_dup = csv_df_dup[~duplicated]
149
+
150
+ csv_df_dup = csv_df_dup.reset_index(drop=True)
151
+ self.args.log.write(txt_dup)
152
+
153
+ return csv_df_dup
154
+
155
+
156
+ def save_curate(self,csv_df):
157
+ '''
158
+ Saves the curated database and options used in CURATE
159
+ '''
160
+
161
+ csv_basename = os.path.basename(f'{self.args.csv_name}').split('.')[0]
162
+
163
+ # Check if csv_df is a tuple (csv_df_filtered, csv_df_per_model) from correlation_filter
164
+ if isinstance(csv_df, tuple):
165
+ csv_df_filtered, csv_df_per_model = csv_df
166
+
167
+ # Save model-specific curated databases (sorted for reproducibility)
168
+ for model in csv_df_per_model:
169
+ csv_curate_name = f'{csv_basename}_CURATE_{model}.csv'
170
+ csv_curate_name = self.args.destination.joinpath(csv_curate_name)
171
+ # Sort rows by y value for reproducibility
172
+ csv_df_to_save = csv_df_per_model[model].reset_index(drop=True).sort_values(by=self.args.y).reset_index(drop=True)
173
+ _ = csv_df_to_save.to_csv(f'{csv_curate_name}', index=None, header=True)
174
+
175
+ # y values to predict, considering that ROBERT will work with multiple values of y in future versions
176
+ if not isinstance(self.args.y,list):
177
+ count_y = 1
178
+ else:
179
+ count_y = len(self.args.y)
180
+
181
+ txt_csv = f'\n o Model {model}: {len(csv_df_per_model[model].columns)-len(self.args.ignore)-count_y} descriptors remaining:\n'
182
+ txt_csv += ' ' + ', '.join(f'{var}' for var in csv_df_per_model[model].columns if var not in self.args.ignore and var != self.args.y)
183
+ self.args.log.write(txt_csv)
184
+
185
+ self.args.log.write(f'\no Model-specific curated databases were stored in {self.args.destination}')
186
+
187
+ # Save general curated database (for reference/Pearson map, sorted for reproducibility)
188
+ csv_curate_name_general = f'{csv_basename}_CURATE.csv'
189
+ csv_curate_name_general = self.args.destination.joinpath(csv_curate_name_general)
190
+ csv_df_to_save_general = csv_df_filtered.reset_index(drop=True).sort_values(by=self.args.y).reset_index(drop=True)
191
+ _ = csv_df_to_save_general.to_csv(f'{csv_curate_name_general}', index=None, header=True)
192
+
193
+ else:
194
+ # Original behavior: save single curated database
195
+ csv_curate_name_general = f'{csv_basename}_CURATE.csv'
196
+ csv_curate_name_general = self.args.destination.joinpath(csv_curate_name_general)
197
+ _ = csv_df.to_csv(f'{csv_curate_name_general}', index=None, header=True)
198
+ path_reduced = '/'.join(f'{csv_curate_name_general}'.replace('\\','/').split('/')[-2:])
199
+ self.args.log.write(f'\no The curated database was stored in {path_reduced}.')
200
+
201
+ # Save important options used in CURATE
202
+ options_name = f'CURATE_options.csv'
203
+ options_name = self.args.destination.joinpath(options_name)
204
+ options_df = pd.DataFrame()
205
+ options_df['y'] = [self.args.y]
206
+ options_df['ignore'] = [self.args.ignore]
207
+ options_df['names'] = [self.args.names]
208
+ options_df['csv_name'] = [csv_curate_name_general]
209
+
210
+ # Save class label mapping if it exists (for classification with string labels)
211
+ if hasattr(self.args, 'class_mapping_reverse'):
212
+ options_df['class_mapping_reverse'] = [json.dumps(self.args.class_mapping_reverse)]
213
+ if hasattr(self.args, 'class_0_label'):
214
+ options_df['class_0_label'] = [self.args.class_0_label]
215
+ options_df['class_1_label'] = [self.args.class_1_label]
216
+
217
+ _ = options_df.to_csv(f'{options_name}', index=None, header=True)
@@ -0,0 +1,125 @@
1
+ """Measure robBOT evidence retrieval without provider calls.
2
+
3
+ Cases name acceptable evidence by stable entity ID or chunk ID. The report
4
+ includes ranked candidates so failures can be reviewed individually.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import argparse
10
+ import json
11
+ from pathlib import Path
12
+ from typing import Mapping, Sequence
13
+
14
+ from gui_easyrob.bot.bot_context import GuiSnapshot
15
+ from gui_easyrob.bot.bot_engine import BotEngine
16
+ from gui_easyrob.bot.question_intent import (
17
+ classify_question_intent,
18
+ is_generic_question,
19
+ select_inference_history,
20
+ )
21
+
22
+
23
+ def _snapshot(case: Mapping[str, object]) -> GuiSnapshot:
24
+ return GuiSnapshot(
25
+ active_tab=str(case.get("active_tab", "")),
26
+ workflow=str(case.get("workflow", "")),
27
+ main_csv_path="",
28
+ test_csv_path="",
29
+ target_column="",
30
+ prediction_type="",
31
+ process_running=False,
32
+ run_enabled=False,
33
+ stop_enabled=False,
34
+ recent_console="",
35
+ console_terms=[],
36
+ )
37
+
38
+
39
+ def _metrics(cases: Sequence[Mapping[str, object]]) -> dict[str, float | int]:
40
+ count = len(cases)
41
+ hits = sum(isinstance(case["rank"], int) and case["rank"] <= 3 for case in cases)
42
+ first_hits = sum(case["rank"] == 1 for case in cases)
43
+ reciprocal_sum = sum(
44
+ 1 / case["rank"] for case in cases if isinstance(case["rank"], int)
45
+ )
46
+ return {
47
+ "count": count,
48
+ "hits_at_3": hits,
49
+ "hit_rate_at_1": first_hits / count if count else 0.0,
50
+ "hit_rate_at_3": hits / count if count else 0.0,
51
+ "mrr_at_5": reciprocal_sum / count if count else 0.0,
52
+ }
53
+
54
+
55
+ def evaluate_cases(cases: Sequence[Mapping[str, object]]) -> dict[str, object]:
56
+ """Rank packaged evidence for each labeled question and follow-up."""
57
+ engine = BotEngine()
58
+ rows: list[dict[str, object]] = []
59
+ for case in cases:
60
+ question = str(case["question"])
61
+ language = str(case["language"])
62
+ expected = {str(value) for value in case["expected_evidence"]}
63
+ history = case.get("history", [])
64
+ selected_history = select_inference_history(question, history)
65
+ intent = classify_question_intent(question, selected_history)
66
+ generic = is_generic_question(question, intent)
67
+ retrieval_question = engine._retrieval_question(question, selected_history)
68
+ snapshot = _snapshot(case)
69
+ candidates = engine._retrieve_candidates(retrieval_question, snapshot, intent, generic)
70
+ rank = next(
71
+ (
72
+ index for index, candidate in enumerate(candidates, start=1)
73
+ if expected & {candidate.chunk.id, candidate.chunk.entity_id}
74
+ ),
75
+ None,
76
+ )
77
+ rows.append({
78
+ "id": str(case["id"]),
79
+ "language": language,
80
+ "intent": intent,
81
+ "rank": rank,
82
+ "matched_at_1": rank == 1,
83
+ "matched_at_3": rank is not None and rank <= 3,
84
+ "expected_evidence": sorted(expected),
85
+ "top_evidence": [
86
+ {
87
+ "id": candidate.chunk.id,
88
+ "entity_id": candidate.chunk.entity_id,
89
+ "title": candidate.chunk.title,
90
+ "score": round(candidate.score, 3),
91
+ }
92
+ for candidate in candidates
93
+ ],
94
+ })
95
+ return {
96
+ "summary": _metrics(rows),
97
+ "by_language": {
98
+ language: _metrics([row for row in rows if row["language"] == language])
99
+ for language in sorted({row["language"] for row in rows})
100
+ },
101
+ "cases": rows,
102
+ }
103
+
104
+
105
+ def main() -> None:
106
+ parser = argparse.ArgumentParser(description=__doc__)
107
+ parser.add_argument(
108
+ "--cases", type=Path,
109
+ default=Path(__file__).parent / "tests/fixtures/bot_retrieval_cases.json",
110
+ )
111
+ parser.add_argument("--output", type=Path, help="Optional JSON report path.")
112
+ args = parser.parse_args()
113
+ cases = json.loads(args.cases.read_text(encoding="utf-8"))
114
+ report = evaluate_cases(cases)
115
+ if args.output:
116
+ args.output.parent.mkdir(parents=True, exist_ok=True)
117
+ args.output.write_text(json.dumps(report, indent=2, ensure_ascii=False), encoding="utf-8")
118
+ print(json.dumps({"summary": report["summary"], "by_language": report["by_language"]}, indent=2))
119
+ for case in report["cases"]:
120
+ if not case["matched_at_1"]:
121
+ print(f"Miss: {case['id']} (rank={case['rank']})")
122
+
123
+
124
+ if __name__ == "__main__":
125
+ main()
@@ -0,0 +1,102 @@
1
+ """Run bounded support conversations and export reviewable answers and formatting.
2
+
3
+ Offline mode exercises the heuristic backend. --live uses the real cloud backend,
4
+ requires GROQ_API_KEY (or --saved-key), and can incur provider charges.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import argparse
10
+ import getpass
11
+ from dataclasses import asdict
12
+ from html import escape
13
+ import json
14
+ import os
15
+ from pathlib import Path
16
+ import time
17
+
18
+ from gui_easyrob.bot.bot_context import GuiSnapshot
19
+ from gui_easyrob.bot.bot_engine import BotEngine
20
+ from gui_easyrob.bot.bot_panel import _render_markdown
21
+
22
+
23
+ def main() -> None:
24
+ parser = argparse.ArgumentParser(description=__doc__)
25
+ parser.add_argument("--live", action="store_true")
26
+ parser.add_argument("--web", action="store_true", help="Enable provider-billed web search for documentation evaluations.")
27
+ parser.add_argument("--key-stdin", action="store_true", help="Read a transient provider key without saving it.")
28
+ parser.add_argument("--saved-key", action="store_true", help="Use the API key saved in easyROB settings.")
29
+ parser.add_argument("--output", type=Path, default=Path("benchmark_results/bot_support"))
30
+ parser.add_argument("--interval", type=float, default=25.0, help="Seconds between live calls to respect provider limits.")
31
+ parser.add_argument("--cases", type=Path, help="Alternative conversation fixture.")
32
+ args = parser.parse_args()
33
+ key = os.environ.get("GROQ_API_KEY", "") if args.live else ""
34
+ if args.live and args.key_stdin:
35
+ key = getpass.getpass("Groq API key: ").strip()
36
+ if args.live and args.saved_key:
37
+ from PySide6.QtCore import QSettings
38
+ settings = QSettings("easyROB", "easyROB")
39
+ saved_provider = str(settings.value("bot/provider", "Groq"))
40
+ if saved_provider != "Groq":
41
+ parser.error("The saved provider is not Groq; use GROQ_API_KEY instead.")
42
+ key = str(settings.value("bot/api_key", ""))
43
+ if args.live and not key:
44
+ parser.error("Set GROQ_API_KEY or use --saved-key after saving a Groq key in easyROB.")
45
+ cases_path = args.cases or Path(__file__).parent / "tests/fixtures/bot_support_conversations.json"
46
+ cases = json.loads(cases_path.read_text(encoding="utf-8"))
47
+ engine = BotEngine()
48
+ rows = []
49
+ for case in cases:
50
+ history = []
51
+ snapshot = GuiSnapshot(
52
+ "ROBERT", "Full Workflow", "train.csv", "", "yield", "regression",
53
+ False, True, False, case.get("failure", ""), [],
54
+ failure_message=case.get("failure", ""),
55
+ )
56
+ for question in case["questions"]:
57
+ if args.live and rows:
58
+ time.sleep(max(0, args.interval))
59
+ started = time.perf_counter()
60
+ answer = engine.answer_with_metadata(
61
+ question, snapshot, "Cloud AI" if args.live else "Heuristic", "Groq", key,
62
+ conversation_history=history, web_search_enabled=args.web,
63
+ )
64
+ elapsed = time.perf_counter() - started
65
+ text = answer.text.replace(key, "[redacted]") if key else answer.text
66
+ warnings = []
67
+ if not answer.memory_eligible:
68
+ warnings.append("Request failed or answer excluded from memory; inspect manually.")
69
+ if any(len(paragraph.split()) > 120 for paragraph in text.split("\n\n")):
70
+ warnings.append("Long paragraph: consider shorter prose or numbered actions.")
71
+ if "<script" in text.lower():
72
+ warnings.append("Raw HTML returned; verify escaped rendering.")
73
+ rows.append(dict(case=case["id"], question=question, answer=text,
74
+ seconds=round(elapsed, 3), usage=asdict(answer.usage), metadata=asdict(answer.metadata),
75
+ warnings=warnings, review=case["review"]))
76
+ history += [dict(role="user", content=question),
77
+ dict(role="assistant", content=text, memory_eligible=answer.memory_eligible)]
78
+ print(f"{case['id']}: {len(text.split())} words, {elapsed:.2f}s, {len(warnings)} review flags", flush=True)
79
+ args.output.mkdir(parents=True, exist_ok=True)
80
+ mode = "live-groq" if args.live else "offline-heuristic"
81
+ (args.output / f"{mode}.json").write_text(json.dumps(rows, indent=2, ensure_ascii=False), encoding="utf-8")
82
+ cards = []
83
+ for row in rows:
84
+ sources = " ".join(
85
+ f'<a href="{escape(source["url"], quote=True)}">{escape(source["title"])}</a>'
86
+ for source in row.get("metadata", {}).get("sources", [])
87
+ )
88
+ cards.append(f"<article><h2>{escape(row['case'])}</h2><p><b>User:</b> {escape(row['question'])}</p>"
89
+ f"<section>{_render_markdown(row['answer'])}</section>"
90
+ f"<aside>Sources: {sources}<br>Review: {escape(row['review'])}<br>{escape('; '.join(row['warnings']))}</aside></article>")
91
+ html = ('<!doctype html><meta charset="utf-8"><title>robBOT support evaluation</title>'
92
+ '<style>body{font:16px/1.5 system-ui;max-width:850px;margin:40px auto;background:#f5f7fa;color:#172033}'
93
+ 'article{background:white;padding:24px;margin:20px 0;border:1px solid #dce2e9;border-radius:12px}'
94
+ 'aside{color:#596579;font-size:13px;margin-top:20px}pre{white-space:pre-wrap;background:#edf1f5;padding:16px}'
95
+ 'li{margin:6px 0}h2{font-size:16px}</style>'
96
+ f'<h1>robBOT: {mode}</h1><p>Human review required: automated flags do not establish factual correctness.</p>'
97
+ + "".join(cards))
98
+ (args.output / f"{mode}.html").write_text(html, encoding="utf-8")
99
+
100
+
101
+ if __name__ == "__main__":
102
+ main()
@@ -0,0 +1,87 @@
1
+ """Evaluate real workflow answers using a saved or transient Groq key.
2
+
3
+ Provider calls are billed to the configured account. Credentials are never exported.
4
+ """
5
+
6
+ import argparse
7
+ from dataclasses import asdict
8
+ import json
9
+ from pathlib import Path
10
+ import time
11
+ import sys
12
+ import getpass
13
+
14
+ from PySide6.QtCore import QSettings
15
+ from gui_easyrob.bot.bot_context import GuiSnapshot
16
+ from gui_easyrob.bot.bot_engine import BotEngine
17
+ from gui_easyrob.bot.workflow_results import WorkflowResultStore, render_workflow_evidence
18
+
19
+
20
+ def main():
21
+ parser = argparse.ArgumentParser(description=__doc__)
22
+ parser.add_argument("--output", type=Path, required=True)
23
+ parser.add_argument("--interval", type=float, default=20)
24
+ parser.add_argument("--key-stdin", action="store_true", help="Read a transient key from standard input.")
25
+ parser.add_argument("--only", type=int, help="Run one numbered evaluation case.")
26
+ parser.add_argument("--diagnose", action="store_true", help="Print provider error metadata without credentials.")
27
+ args = parser.parse_args()
28
+ settings = QSettings("easyROB", "easyROB")
29
+ key = (
30
+ (getpass.getpass("Groq API key (not saved): ") if sys.stdin.isatty() else sys.stdin.readline()).strip()
31
+ if args.key_stdin else str(settings.value("bot/api_key", ""))
32
+ )
33
+ if not key or (not args.key_stdin and str(settings.value("bot/provider", "Groq")) != "Groq"):
34
+ raise SystemExit("Save a Groq key in EasyROB Settings before this evaluation.")
35
+ cases = (
36
+ ("robert", "Summarize the ROBERT report for a beginner. Explain what needs attention, why it matters and what to check next."),
37
+ ("robert", "Did all VERIFY checks pass? Can I trust this model?"),
38
+ ("robert", "Resume el informe de ROBERT para una persona sin experiencia. Explica los resultados y donde poner atencion."),
39
+ ("aqme", "Summarize this workflow for a beginner. What was generated and are there molecule failures?"),
40
+ ("aqme", "What is the test R2 of this workflow?"),
41
+ ("robert", "Which variant should I examine first, PFI or No PFI, and why?"),
42
+ )
43
+ roots = {
44
+ "robert": Path("benchmark_results/workflow_results_real_20260917").resolve(),
45
+ "aqme": Path("benchmark_results/workflow_results_aqme_real_20260917").resolve(),
46
+ }
47
+ engine, store, history, rows = BotEngine(), WorkflowResultStore(), [], []
48
+ if args.diagnose:
49
+ adapter = engine._provider_registry["Groq"]
50
+ original_generate = adapter.generate_answer_with_usage
51
+
52
+ def diagnosed_generate(**kwargs):
53
+ try:
54
+ return original_generate(**kwargs)
55
+ except Exception as exc:
56
+ print(
57
+ f"Provider error: {type(exc).__name__}, "
58
+ f"kind={getattr(exc, 'kind', None)}, status={getattr(exc, 'status_code', None)}",
59
+ file=sys.stderr, flush=True,
60
+ )
61
+ raise
62
+
63
+ adapter.generate_answer_with_usage = diagnosed_generate
64
+ args.output.mkdir(parents=True, exist_ok=True)
65
+ for index, (kind, question) in enumerate(cases):
66
+ if args.only is not None and args.only != index + 1:
67
+ continue
68
+ if index:
69
+ time.sleep(max(0, args.interval))
70
+ result = store.refresh(str(roots[kind]), "")
71
+ snapshot = GuiSnapshot("ROBERT", "Full Workflow", "input.csv", "", "", "regression",
72
+ False, True, False, "", [], workflow_results=result)
73
+ started = time.monotonic()
74
+ answer = engine.answer_with_metadata(question, snapshot, "Cloud AI", "Groq", key,
75
+ conversation_history=history, web_search_enabled=False)
76
+ text = answer.text.replace(key, "[redacted]")
77
+ rows.append(dict(case=index + 1, workflow=kind, question=question, answer=text,
78
+ provider_answer=answer.usage.total_tokens > 0,
79
+ seconds=round(time.monotonic()-started, 2), usage=asdict(answer.usage),
80
+ evidence=render_workflow_evidence(result, question, full=True, max_chars=16000)))
81
+ history.extend([dict(role="user", content=question), dict(role="assistant", content=text)])
82
+ (args.output / "answers.json").write_text(json.dumps(rows, ensure_ascii=False, indent=2), encoding="utf-8")
83
+ print(f"Case {index+1}: {kind}, {len(text.split())} words, {answer.usage.total_tokens} tokens", flush=True)
84
+
85
+
86
+ if __name__ == "__main__":
87
+ main()