Skip to content

optimizer: report failed structures as None instead of dropping them - #41

Merged
niklashoelter merged 1 commit into
niklashoelter:masterfrom
avnoordenne:fix/sequential-drops-failed-structures
Sep 25, 2026
Merged

niklashoelter merged 1 commit into
niklashoelter:masterfrom
avnoordenne:fix/sequential-drops-failed-structures

Conversation

@avnoordenne

Copy link
Copy Markdown
Contributor

BREAKING: optimize_structure_batch now returns list[Structure | None].

_optimize_sequential appended only the structures that optimized, so on a
failure the returned list was shorter than the input and every later result sat
at the wrong index. api.py labels output by position, so for inputs
[A, B, C, D] with C failing, D was written as "Optimized structure 3".

Now one entry per input, in input order, with None marking a failure. This
matches embed.generate_structures, which already reports per-molecule failure
this way.

Breaking: optimize_structure_batch returns list[Structure | None].
Callers iterating the result must skip None. The three api.py entry points
still return a filtered list[Structure], so the high-level API is unchanged;
only their comment numbering changes, leaving a gap at a failed input instead
of renumbering. log_optimization_summary filters None so the success rate
counts real outputs. The batch path never had the defect (torch-sim keeps input
order and raises on a count mismatch); only its annotation moves.

Tests: 4 new in tests/optimization/test_batch.py. Full suite: 248 passed,
3 skipped.

BREAKING: optimize_structure_batch now returns list[Structure | None].

_optimize_sequential appended only the structures that optimized, so the
returned list was shorter than the input and every result after a failure sat
at the wrong index, with nothing to say so. Given inputs [A, B, C, D] where C
fails, the caller received [A, B, D] -- and api.py, which labels output by
position, then wrote D into the file as "Optimized structure 3".

Return one entry per input, in input order, with None marking a failure. This
matches embed.generate_structures, which already reports per-molecule failure
this way, so the two halves of the package now agree.

Callers that iterate results must skip None. Inside the package:

  - log_optimization_summary filters them out, so the success rate counts what
    actually came back rather than counting a None as an output.
  - The three api.py entry points still return list[Structure], filtered, so
    the high-level API is unchanged. What changes there is the labelling:
    comments are numbered by position in the *input*, so a failed structure
    leaves a gap instead of renumbering everything after it.

The batch path never had the defect -- torch-sim's restore_original_order
keeps input order and raises on a count mismatch -- but its annotation moves
to the shared return type.
@niklashoelter
niklashoelter merged commit ec56d38 into niklashoelter:master Sep 25, 2026
1 check passed
@avnoordenne
avnoordenne deleted the fix/sequential-drops-failed-structures branch October 1, 2026 11:41
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.

2 participants