Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [unreleased]

### Changed

- Moved single-point primary-result validation from `SinglePointData` to `ProgramOutput` so failed calculations can carry empty or partial `SinglePointData` while successful calculations still require their requested primary result.

## [0.17.2] - 2026-05-31

### Added
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ dev = [
"pytest>=7.2.2",
"pre-commit>=3.2.1",
"pytest-cov>=4.0.0",
"qcelemental>=0.26.0",
"qcelemental>=0.50.4",
"types-toml>=0.10.8.6",
"types-pyyaml>=6.0.12.10",
"rdkit>=2022.9.5",
Expand Down
11 changes: 0 additions & 11 deletions src/qcdata/models/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,6 @@ def return_result(self, calctype: CalcType) -> float | SerializableNDArray:
"""Return the primary result of the calculation."""
return getattr(self, calctype.value)

@model_validator(mode="after")
def _ensure_results(self) -> Self:
"""Ensure that at least one result is present."""
if all(result is None for result in [self.energy, self.gradient, self.hessian]):
raise ValueError(
"SinglePointResults requires either an energy, gradient, or hessian "
"value."
)
return self


class OptimizationData(Files, CalcInfoData):
"""Computed data for an optimization (may be for a minimum or transition state).

Expand Down
2 changes: 1 addition & 1 deletion src/qcdata/models/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _ensure_structured_results_on_success(self) -> Self:

@model_validator(mode="after")
def ensure_primary_result_on_success(self) -> Self:
if type(self.data) is SinglePointData:
if self.success is True and type(self.data) is SinglePointData:
calctype_val = self.input_data.calctype.value # type: ignore
assert getattr(self.data, calctype_val) is not None, (
f"Missing the primary result: {calctype_val}."
Expand Down
15 changes: 15 additions & 0 deletions tests/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ def test_primary_result_must_be_present_on_success(prog_output):
ProgramOutput[ProgramInput, SinglePointData](**po_dict)


def test_primary_result_can_be_missing_on_failure(prog_input_factory):
pi_gradient = prog_input_factory("gradient")
output = ProgramOutput[ProgramInput, SinglePointData](
success=False,
input_data=pi_gradient,
data=SinglePointData(extras={"program_version": "3.0.2"}),
traceback="Fake traceback",
provenance={"program": "qcdata-test-suite"},
)
assert output.data.energy is None
assert output.data.gradient is None
assert output.data.hessian is None
assert output.data.extras == {"program_version": "3.0.2"}


@pytest.mark.parametrize(
"input_data, data, success, expected_input_type, expected_result_type",
[
Expand Down
10 changes: 5 additions & 5 deletions tests/test_single_point_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import numpy as np
import pytest
from pydantic import ValidationError

from qcdata import SinglePointData, Wavefunction

Expand Down Expand Up @@ -102,6 +100,8 @@ def test_wavefunction_to_numpy():
assert wavefunction.scf_occupations_b.dtype == np.float64


def test_ensure_result_present_on_single_point_data_validator():
with pytest.raises(ValidationError):
SinglePointData()
def test_single_point_data_can_be_empty_for_partial_or_failed_outputs():
data = SinglePointData()
assert data.energy is None
assert data.gradient is None
assert data.hessian is None
174 changes: 157 additions & 17 deletions uv.lock

Large diffs are not rendered by default.

Loading