Skip to content

feat: raw Hessian elements as training data (#124)#190

Merged
ericchansen merged 4 commits intomasterfrom
feat/issue-124-raw-hessian-training
Mar 30, 2026
Merged

feat: raw Hessian elements as training data (#124)#190
ericchansen merged 4 commits intomasterfrom
feat/issue-124-raw-hessian-training

Conversation

@ericchansen
Copy link
Copy Markdown
Owner

Summary

Add support for raw Hessian matrix elements as training data, complementing the existing eigenmatrix-based approach. Closes #124.

Changes

File Change
q2mm/optimizers/evaluators/hessian_element.py New HessianElementEvaluator -- computes raw MM Hessian, extracts elements at (row, col)
q2mm/optimizers/objective.py Add hessian_element kind, add_hessian_element() and add_hessian_from_matrix() builders, evaluator registration
q2mm/parsers/reference_yaml.py YAML parsing for kind: hessian_element and bulk kind: hessian directive

Testing

  • 30 new tests covering evaluator, ReferenceData builders, YAML round-trip, and ObjectiveFunction integration
  • 664 existing tests pass with no regressions

YAML Usage

# Individual element
- kind: hessian_element
  row: 3
  col: 3
  value: 0.5
  weight: 0.1

# Bulk from molecule hessian
- kind: hessian
  diagonal_weight: 0.1
  offdiagonal_weight: 0.05

Add support for using raw Hessian matrix elements (not eigenmatrix) as
training data, following the existing pattern established by eigenmatrix
evaluators.

Changes:
- New HessianElementEvaluator in q2mm/optimizers/evaluators/hessian_element.py
- ReferenceValue.kind now accepts 'hessian_element'
- ReferenceData gains add_hessian_element() and add_hessian_from_matrix()
- ObjectiveFunction registers and dispatches to the new evaluator
- YAML parser supports 'hessian_element' kind and 'hessian' bulk directive
- 30 new tests covering evaluator, ReferenceData, YAML round-trip, and
  ObjectiveFunction integration

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 29, 2026 19:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new training-data pathway for fitting against raw Cartesian Hessian matrix elements (in Hartree/Bohr²), alongside the existing eigenmatrix-based Hessian training workflow. This expands the objective/reference-data system and YAML reference format to support element-wise Hessian targets.

Changes:

  • Introduces HessianElementEvaluator to compute an MM Hessian and extract (row, col) elements for residual scoring.
  • Extends ReferenceData/ObjectiveFunction to register and evaluate kind: hessian_element, plus a bulk loader from a full Hessian matrix.
  • Updates YAML reference parsing to accept kind: hessian_element and a bulk kind: hessian directive that expands to many hessian_element references; adds a dedicated test module.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.

File Description
q2mm/optimizers/evaluators/hessian_element.py New evaluator computing raw MM Hessian and extracting element values for scoring.
q2mm/optimizers/objective.py Adds hessian_element reference kind, builders for single/bulk Hessian elements, and evaluator registration/evaluation.
q2mm/parsers/reference_yaml.py Adds YAML parsing/serialization for hessian_element plus bulk kind: hessian expansion.
test/test_hessian_element.py New tests covering evaluator behavior, builders, YAML parsing/round-trip, and objective integration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread q2mm/parsers/reference_yaml.py
Comment thread test/test_hessian_element.py Outdated
Comment thread test/test_hessian_element.py Outdated
Comment thread q2mm/optimizers/objective.py
Comment thread q2mm/optimizers/objective.py
Comment thread q2mm/optimizers/objective.py
Comment thread q2mm/optimizers/objective.py
Comment thread test/test_hessian_element.py Outdated
Comment thread test/test_hessian_element.py Outdated
ericchansen and others added 2 commits March 30, 2026 09:10
- Add hessian_element to _kind_to_category() mapping (fixes gradient())
- Validate negative row/col in add_hessian_element()
- Validate skip_translational in add_hessian_from_matrix() and YAML parser
- Use tmp_path in tests instead of CWD
- Remove dead patch.object code in test

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Change auto-extraction defaults to match Q2MM literature
(Norrby & Liljefors 1998): geometries and eigenmatrix ON,
frequencies OFF.

- from_molecule(): include_eigenmatrix default True
- from_molecules(): include_eigenmatrix default True
- from_gaussian(): include_frequencies default False,
  add include_eigenmatrix parameter (default True)

Raw hessian_element training remains opt-in only.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 30, 2026 16:52
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread q2mm/optimizers/evaluators/hessian_element.py
Comment thread q2mm/optimizers/objective.py
Comment thread q2mm/optimizers/objective.py
Comment thread q2mm/optimizers/objective.py
Comment thread q2mm/parsers/reference_yaml.py
… upper bound

- Remove unused **kwargs from HessianElementEvaluator.compute()
  (no other evaluator uses it; consistent interface)
- Validate skip_translational < Hessian dimension in YAML parser
  with ReferenceYAMLError for proper context

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ericchansen ericchansen merged commit 6dfc24e into master Mar 30, 2026
11 checks passed
@ericchansen ericchansen deleted the feat/issue-124-raw-hessian-training branch March 30, 2026 18:45
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.

feat: consider supporting raw Hessian elements as training data

2 participants