Skip to content

[Autosolve PR 1] Add hallucination helpers and autosolve foundations - #229

Open
shreyasvinaya wants to merge 9 commits into
mainfrom
autosolve-foundations
Open

[Autosolve PR 1] Add hallucination helpers and autosolve foundations#229
shreyasvinaya wants to merge 9 commits into
mainfrom
autosolve-foundations

Conversation

@shreyasvinaya

@shreyasvinaya shreyasvinaya commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add hallucination_helpers module with ML/heuristic pathway filtering (build_ml_checker, filter_with_checker, resolve_hallucination)
  • Add HallucinationChecker type alias to deepretro.utils.typing
  • Add canonicalize() to utils_molecule for canonical SMILES normalization
  • Full test suite for hallucination helpers (7 tests)
  • Update models/__init__ exports

The checker now takes an already-loaded classifier object (anything satisfying HallucinationPredictor) instead of loading a model from a path string. This decouples the helpers from deepchem/HallucinationClassifier, makes them trivially testable with fakes, and lets callers control model lifetime. Path-based loading was intentionally removed.

Type of change

Please check the option that is related to your PR.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • In this case, we recommend to discuss your modification on GitHub issues before creating the PR
  • Documentations (modification for documents)

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

- hallucination_helpers: build_ml_checker, filter_with_checker,
  resolve_hallucination for optional ML/heuristic filtering
- HallucinationChecker type alias in deepretro.utils.typing
- canonicalize() in utils_molecule for canonical SMILES normalization
- Full test suite for hallucination helpers (7 tests)
- Update models/__init__ exports
- Fix filter_with_checker: unknown pathways from checker no longer cause
  misaligned return lengths (pathways without matching metadata are dropped)
- Remove all monkeypatch and MagicMock usage — inject classifier doubles
- Use real molecules (aspirin, salicylic acid, paracetamol)
- Add missing edge cases: unknown pathway from checker, missing
  is_hallucination key defaults to filtered, empty pathways short-circuit
- Remove lazy import of is_valid_smiles (top-level import)
- Direct imports in models/__init__ (lazy only for deepchem-dependent modules)
Source fixes:
- is_hallucination check uses `is False` (None/0/missing no longer pass)
- filter_with_checker validates input length alignment (raises ValueError)
- Unknown pathways from checker raise ValueError (was silent data loss)
- build_ml_checker validates classifier at construction (TypeError)
- HallucinationPredictor Protocol replaces Any for classifier type
- Raises sections added to all public docstrings

Test fixes:
- Module-level test doubles (StubClassifier, SelectiveClassifier)
- No private classes, no nested functions, no meta-commentary
- Covers: None value, missing key, mismatched lengths, unknown pathway,
  classifier validation, multi-reactant join, empty input
@shreyasvinaya shreyasvinaya changed the title Add hallucination helpers and autosolve foundations [Autosolve PR 1] Add hallucination helpers and autosolve foundations Jun 2, 2026
Callers must pass a loaded model object (HallucinationPredictor)
rather than a file path. This removes the implicit load-from-disk
side effect and the dependency on hallucination_classifier module
at resolution time.
# Conflicts:
#	deepretro/models/hallucination_helpers.py
#	deepretro/tests/test_hallucination_helpers.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant