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,225 @@
|
|
|
1
|
+
"""Bounded, source-linked facts extracted from ROBERT prediction artifacts."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import csv
|
|
6
|
+
import math
|
|
7
|
+
import re
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True, slots=True)
|
|
13
|
+
class ResultInsight:
|
|
14
|
+
model: str
|
|
15
|
+
variant: str
|
|
16
|
+
category: str
|
|
17
|
+
summary: str
|
|
18
|
+
source: str
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
_SHAP_RE = re.compile(r"^\s*-\s+(.+?)\s+=\s+min:\s*([-+\deE.]+),\s*max:\s*([-+\deE.]+)\s*$")
|
|
22
|
+
_PFI_RE = re.compile(r"^\s*-\s+(.+?)\s+=\s+([-+\deE.]+)\s+\+-\s+([-+\deE.]+)\s*$")
|
|
23
|
+
_MAX_ROWS = 200_000
|
|
24
|
+
_AQME_SCAN_ROWS = 10_000
|
|
25
|
+
_MISSING_VALUES = {"", "nan", "none", "null", "n/a", "inf", "-inf"}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def extract_log_insights(text: str, model: str, source: str) -> tuple[ResultInsight, ...]:
|
|
29
|
+
"""Read logged SHAP ranges and PFI scores without interpreting chemistry."""
|
|
30
|
+
variant = ""
|
|
31
|
+
category = ""
|
|
32
|
+
groups: dict[tuple[str, str], list[str]] = {}
|
|
33
|
+
pfi_metrics: dict[str, str] = {}
|
|
34
|
+
for line in text.splitlines():
|
|
35
|
+
folded = line.casefold()
|
|
36
|
+
if "starting model with all variables" in folded:
|
|
37
|
+
variant, category = "No_PFI", ""
|
|
38
|
+
elif "starting model with pfi" in folded:
|
|
39
|
+
variant, category = "PFI", ""
|
|
40
|
+
elif "shap plot saved" in folded:
|
|
41
|
+
category = "shap"
|
|
42
|
+
elif "pfi plot saved" in folded:
|
|
43
|
+
category = "pfi"
|
|
44
|
+
elif re.match(r"\s*o\s+", line):
|
|
45
|
+
category = ""
|
|
46
|
+
if not variant or not category:
|
|
47
|
+
continue
|
|
48
|
+
influence = re.match(r"^\s*Influence on\s+([A-Za-z0-9_-]+)\s*$", line, re.IGNORECASE)
|
|
49
|
+
if category == "pfi" and influence:
|
|
50
|
+
pfi_metrics[variant] = influence.group(1).upper()
|
|
51
|
+
pattern = _SHAP_RE if category == "shap" else _PFI_RE
|
|
52
|
+
match = pattern.match(line)
|
|
53
|
+
if not match:
|
|
54
|
+
continue
|
|
55
|
+
name, first, second = match.groups()
|
|
56
|
+
name = " ".join(name.split())[:100]
|
|
57
|
+
value = (
|
|
58
|
+
f"{name}: min={first}, max={second}"
|
|
59
|
+
if category == "shap" else f"{name}: {first} ± {second}"
|
|
60
|
+
)
|
|
61
|
+
groups.setdefault((variant, category), []).append(value)
|
|
62
|
+
insights = []
|
|
63
|
+
for (variant, category), values in groups.items():
|
|
64
|
+
prefix = (
|
|
65
|
+
"Reported SHAP value ranges (not an importance ranking)"
|
|
66
|
+
if category == "shap" else (
|
|
67
|
+
f"Permutation importance for {pfi_metrics[variant]} (mean ± SD, reported order)"
|
|
68
|
+
if variant in pfi_metrics else "Permutation importance (mean ± SD, reported order)"
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
summary = f"{prefix}: {'; '.join(values[:5])}"
|
|
72
|
+
if len(values) > 5:
|
|
73
|
+
summary += f"; {len(values) - 5} more descriptors in source"
|
|
74
|
+
insights.append(ResultInsight(model, variant, category, summary, source))
|
|
75
|
+
return tuple(insights)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _finite_float(value: str | None) -> float | None:
|
|
79
|
+
try:
|
|
80
|
+
number = float(value)
|
|
81
|
+
except (TypeError, ValueError):
|
|
82
|
+
return None
|
|
83
|
+
return number if math.isfinite(number) else None
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _format_number(value: float) -> str:
|
|
87
|
+
return f"{value:.3g}"
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def extract_prediction_insight(path: Path, model: str, variant: str, source: str) -> ResultInsight | None:
|
|
91
|
+
"""Summarize regression residuals without treating prediction SD as an interval."""
|
|
92
|
+
try:
|
|
93
|
+
with path.open("r", encoding="utf-8-sig", errors="replace", newline="") as handle:
|
|
94
|
+
reader = csv.DictReader(handle)
|
|
95
|
+
fields = reader.fieldnames or []
|
|
96
|
+
prediction = next((name for name in fields if name.casefold().endswith("_pred")), None)
|
|
97
|
+
if prediction is None:
|
|
98
|
+
return None
|
|
99
|
+
observed = prediction[:-5]
|
|
100
|
+
observed_available = observed in fields
|
|
101
|
+
identifier = next((name for name in ("code_name", "point_id", "name", "id") if name in fields), None)
|
|
102
|
+
set_column = next((name for name in fields if name.casefold() == "set"), None)
|
|
103
|
+
total = evaluated = missing = 0
|
|
104
|
+
finite_predictions = 0
|
|
105
|
+
prediction_min = prediction_max = None
|
|
106
|
+
absolute_error_sum = 0.0
|
|
107
|
+
largest: list[tuple[float, int, str, float, float, str]] = []
|
|
108
|
+
set_totals: dict[str, tuple[int, float]] = {}
|
|
109
|
+
for row in reader:
|
|
110
|
+
total += 1
|
|
111
|
+
if total > _MAX_ROWS:
|
|
112
|
+
break
|
|
113
|
+
actual = _finite_float(row.get(observed))
|
|
114
|
+
predicted = _finite_float(row.get(prediction))
|
|
115
|
+
if predicted is not None:
|
|
116
|
+
finite_predictions += 1
|
|
117
|
+
prediction_min = predicted if prediction_min is None else min(prediction_min, predicted)
|
|
118
|
+
prediction_max = predicted if prediction_max is None else max(prediction_max, predicted)
|
|
119
|
+
if actual is None or predicted is None:
|
|
120
|
+
missing += 1
|
|
121
|
+
continue
|
|
122
|
+
error = abs(actual - predicted)
|
|
123
|
+
evaluated += 1
|
|
124
|
+
absolute_error_sum += error
|
|
125
|
+
label = " ".join(str(row.get(identifier) or total).split())[:80]
|
|
126
|
+
group = " ".join(str(row.get(set_column) or "").split())[:30] if set_column else ""
|
|
127
|
+
largest.append((error, total, label, actual, predicted, group))
|
|
128
|
+
largest.sort(key=lambda item: (-item[0], item[1]))
|
|
129
|
+
del largest[3:]
|
|
130
|
+
if group:
|
|
131
|
+
count, error_sum = set_totals.get(group, (0, 0.0))
|
|
132
|
+
set_totals[group] = (count + 1, error_sum + error)
|
|
133
|
+
except (OSError, csv.Error, UnicodeError):
|
|
134
|
+
return None
|
|
135
|
+
if total == 0:
|
|
136
|
+
return None
|
|
137
|
+
fragments = [f"{min(total, _MAX_ROWS)} rows, {evaluated} evaluated"]
|
|
138
|
+
if finite_predictions:
|
|
139
|
+
fragments.append(
|
|
140
|
+
f"{finite_predictions} finite predictions; predicted value range={_format_number(prediction_min)} "
|
|
141
|
+
f"to {_format_number(prediction_max)}"
|
|
142
|
+
)
|
|
143
|
+
if evaluated:
|
|
144
|
+
fragments.append(f"MAE={_format_number(absolute_error_sum / evaluated)} in target units")
|
|
145
|
+
for group, (count, error_sum) in sorted(set_totals.items()):
|
|
146
|
+
fragments.append(f"{group}: {count} evaluated, MAE={_format_number(error_sum / count)}")
|
|
147
|
+
top = "; ".join(
|
|
148
|
+
f"{label} ({group or 'unlabelled'}): observed={_format_number(actual)}, "
|
|
149
|
+
f"predicted={_format_number(predicted)}, absolute error={_format_number(error)}"
|
|
150
|
+
for error, _, label, actual, predicted, group in largest
|
|
151
|
+
)
|
|
152
|
+
fragments.append(f"largest observed errors: {top}")
|
|
153
|
+
if not observed_available:
|
|
154
|
+
fragments.append("observed target column absent; errors cannot be calculated")
|
|
155
|
+
elif missing:
|
|
156
|
+
fragments.append(f"{missing} rows without comparable observed/predicted values")
|
|
157
|
+
if total > _MAX_ROWS:
|
|
158
|
+
fragments.append(f"scan limited to first {_MAX_ROWS} rows")
|
|
159
|
+
return ResultInsight(model, variant, "prediction_errors", "; ".join(fragments), source)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def extract_aqme_insight(path: Path, input_columns: int | None, source: str) -> ResultInsight | None:
|
|
163
|
+
"""Count missing AQME descriptor cells in a bounded scan of an output CSV."""
|
|
164
|
+
if input_columns is None:
|
|
165
|
+
return None
|
|
166
|
+
try:
|
|
167
|
+
with path.open("r", encoding="utf-8-sig", errors="replace", newline="") as handle:
|
|
168
|
+
reader = csv.reader(handle)
|
|
169
|
+
header = next(reader, [])
|
|
170
|
+
if len(header) <= input_columns:
|
|
171
|
+
return None
|
|
172
|
+
missing = [0] * (len(header) - input_columns)
|
|
173
|
+
rows = 0
|
|
174
|
+
for row in reader:
|
|
175
|
+
if rows >= _AQME_SCAN_ROWS:
|
|
176
|
+
break
|
|
177
|
+
rows += 1
|
|
178
|
+
for index in range(input_columns, len(header)):
|
|
179
|
+
value = row[index].strip().casefold() if index < len(row) else ""
|
|
180
|
+
if value in _MISSING_VALUES:
|
|
181
|
+
missing[index - input_columns] += 1
|
|
182
|
+
except (OSError, csv.Error, UnicodeError):
|
|
183
|
+
return None
|
|
184
|
+
affected = [(header[input_columns + index], count) for index, count in enumerate(missing) if count]
|
|
185
|
+
affected.sort(key=lambda item: (-item[1], item[0].casefold()))
|
|
186
|
+
summary = (
|
|
187
|
+
f"{rows} rows scanned; {len(missing)} descriptor columns; "
|
|
188
|
+
f"{len(affected)} columns with missing values"
|
|
189
|
+
)
|
|
190
|
+
if affected:
|
|
191
|
+
summary += "; most missing: " + "; ".join(
|
|
192
|
+
f"{' '.join(name.split())[:80]}: {count}/{rows} missing"
|
|
193
|
+
for name, count in affected[:5]
|
|
194
|
+
)
|
|
195
|
+
if rows >= _AQME_SCAN_ROWS:
|
|
196
|
+
summary += f"; scan limited to first {_AQME_SCAN_ROWS} rows"
|
|
197
|
+
return ResultInsight("", "", "aqme_completeness", summary, source)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def extract_dataset_overlap(main_path: Path, external_path: Path) -> ResultInsight | None:
|
|
201
|
+
"""Check literal SMILES overlap between the selected main and external inputs."""
|
|
202
|
+
def read_smiles(path: Path) -> list[str] | None:
|
|
203
|
+
try:
|
|
204
|
+
with path.open("r", encoding="utf-8-sig", errors="replace", newline="") as handle:
|
|
205
|
+
reader = csv.DictReader(handle)
|
|
206
|
+
column = next((name for name in (reader.fieldnames or []) if name.casefold() == "smiles"), None)
|
|
207
|
+
if column is None:
|
|
208
|
+
return None
|
|
209
|
+
return [str(row.get(column) or "").strip() for _, row in zip(range(_MAX_ROWS), reader)]
|
|
210
|
+
except (OSError, csv.Error, UnicodeError):
|
|
211
|
+
return None
|
|
212
|
+
|
|
213
|
+
main_smiles = read_smiles(main_path)
|
|
214
|
+
external_smiles = read_smiles(external_path)
|
|
215
|
+
if main_smiles is None or not external_smiles:
|
|
216
|
+
return None
|
|
217
|
+
main_set = set(filter(None, main_smiles))
|
|
218
|
+
matches = [value for value in external_smiles if value and value in main_set]
|
|
219
|
+
summary = f"Exact SMILES overlap: {len(matches)}/{len(external_smiles)} external rows match the main input"
|
|
220
|
+
if matches:
|
|
221
|
+
summary += "; matching external rows are not independent by exact SMILES"
|
|
222
|
+
else:
|
|
223
|
+
summary += "; no exact string matches found"
|
|
224
|
+
summary += "; SMILES were not chemically canonicalized"
|
|
225
|
+
return ResultInsight("", "", "dataset_overlap", summary, f"{main_path.name}, {external_path.name}")
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Token accounting primitives shared by robBOT backends and the GUI."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
import math
|
|
7
|
+
|
|
8
|
+
__all__ = ["MAX_USER_PROMPT_TOKENS", "TokenUsage", "estimate_token_count"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
MAX_USER_PROMPT_TOKENS = 500
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def estimate_token_count(text: object) -> int:
|
|
15
|
+
"""Return a conservative tokenizer-free estimate for user-facing limits."""
|
|
16
|
+
if type(text) is not str or not text:
|
|
17
|
+
return 0
|
|
18
|
+
ascii_count = sum(1 for character in text if ord(character) < 128)
|
|
19
|
+
non_ascii = [character for character in text if ord(character) >= 128]
|
|
20
|
+
non_ascii_bytes = sum(len(character.encode("utf-8")) for character in non_ascii)
|
|
21
|
+
return math.ceil(ascii_count / 4) + max(len(non_ascii), math.ceil(non_ascii_bytes / 3))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(frozen=True, slots=True)
|
|
25
|
+
class TokenUsage:
|
|
26
|
+
prompt_tokens: int = 0
|
|
27
|
+
completion_tokens: int = 0
|
|
28
|
+
total_tokens: int = 0
|
|
29
|
+
cached_prompt_tokens: int = 0
|
|
30
|
+
estimated_cost_usd: float | None = 0.0
|
|
31
|
+
is_estimated: bool = False
|
|
32
|
+
provider: str = ""
|
|
33
|
+
model: str = ""
|
|
34
|
+
assessment_prompt_tokens: int = 0
|
|
35
|
+
assessment_completion_tokens: int = 0
|
|
36
|
+
search_content_tokens: int = 0
|
|
37
|
+
search_requests: int = 0
|
|
38
|
+
estimated_model_cost_usd: float | None = 0.0
|
|
39
|
+
estimated_search_cost_usd: float | None = 0.0
|
|
40
|
+
|
|
41
|
+
def __add__(self, other: object) -> "TokenUsage":
|
|
42
|
+
if not isinstance(other, TokenUsage):
|
|
43
|
+
return NotImplemented
|
|
44
|
+
|
|
45
|
+
def add_optional(first: float | None, second: float | None) -> float | None:
|
|
46
|
+
if first is None or second is None:
|
|
47
|
+
return None
|
|
48
|
+
return first + second
|
|
49
|
+
|
|
50
|
+
return TokenUsage(
|
|
51
|
+
prompt_tokens=self.prompt_tokens + other.prompt_tokens,
|
|
52
|
+
completion_tokens=self.completion_tokens + other.completion_tokens,
|
|
53
|
+
total_tokens=self.total_tokens + other.total_tokens,
|
|
54
|
+
cached_prompt_tokens=self.cached_prompt_tokens + other.cached_prompt_tokens,
|
|
55
|
+
assessment_prompt_tokens=(
|
|
56
|
+
self.assessment_prompt_tokens + other.assessment_prompt_tokens
|
|
57
|
+
),
|
|
58
|
+
assessment_completion_tokens=(
|
|
59
|
+
self.assessment_completion_tokens + other.assessment_completion_tokens
|
|
60
|
+
),
|
|
61
|
+
search_content_tokens=self.search_content_tokens + other.search_content_tokens,
|
|
62
|
+
search_requests=self.search_requests + other.search_requests,
|
|
63
|
+
estimated_model_cost_usd=add_optional(
|
|
64
|
+
self.estimated_model_cost_usd, other.estimated_model_cost_usd
|
|
65
|
+
),
|
|
66
|
+
estimated_search_cost_usd=add_optional(
|
|
67
|
+
self.estimated_search_cost_usd, other.estimated_search_cost_usd
|
|
68
|
+
),
|
|
69
|
+
estimated_cost_usd=add_optional(
|
|
70
|
+
self.estimated_cost_usd, other.estimated_cost_usd
|
|
71
|
+
),
|
|
72
|
+
is_estimated=self.is_estimated or other.is_estimated,
|
|
73
|
+
provider=self.provider if self.provider == other.provider else "",
|
|
74
|
+
model=self.model if self.model == other.model else "",
|
|
75
|
+
)
|