Skip to content

fix: round trip of a Solution with unset optional solver fields - #469

Merged
ocots merged 2 commits into
mainfrom
fix/optional-solver-fields
Oct 18, 2026
Merged

ocots merged 2 commits into
mainfrom
fix/optional-solver-fields

Conversation

@ocots

@ocots ocots commented Oct 18, 2026

Copy link
Copy Markdown
Member

Closes #464.

Stacked on #468 (JSON.jl), itself stacked on #463: the base of this PR is feat/json-jl-v1. Once #468 is merged, the base moves to main.

Problem

A Solution whose iterations, constraints_violation, message or status are NotProvided (e.g. the ones built by an indirect method) could be exported but not imported, in JSON and JLD2: Float64("NotProvided") / Float64(NotProvided) raised a raw MethodError, and an unset status / message silently came back as :NotProvided / "NotProvided".

Changes

  • Export. _serialize_solution writes nothing (null in JSON) for an unset field, in both formats.
  • Import. New helper _optional(data, key, T): a missing key, nothing, NotProvided or the legacy string "NotProvided" gives Core.NotProvided; a value of the wrong type raises a ParsingError.
  • JSON extension. The four fields are read with get(blob, key, nothing).
  • Format. SERIALIZATION_FORMAT_VERSION unchanged (2): files written before are still read.
  • CHANGELOG.md entry and docstrings updated.

Tests

New test/suite/serialization/test_optional_fields.jl (JSON and JLD2): four fields unset, four fields set, legacy file with "NotProvided", wrong type raises ParsingError, JSON file holds null. Serialization suite: 2257 passed. In the full suite, only the 3 plot test files fail (CTBase.Plotting.switching_vlines, unreleased CTBase #613), unrelated to this PR.

Known limitation

A status or message that is genuinely the string "NotProvided" is read as unset (price of reading legacy files).

🤖 Generated with Devin

An unset iterations, constraints_violation, message or status (NotProvided) is
written as null/nothing and read back as NotProvided; the legacy string
"NotProvided" is still read, and a wrong type raises a ParsingError.

Closes #464.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Base automatically changed from feat/json-jl-v1 to main October 18, 2026 18:59
@ocots
ocots marked this pull request as ready for review October 18, 2026 18:59
@ocots
ocots merged commit f4d9a49 into main Oct 18, 2026
4 checks passed
@ocots
ocots deleted the fix/optional-solver-fields branch October 18, 2026 19:02
@ocots ocots mentioned this pull request Oct 19, 2026
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.

Export/import round trip fails for a Solution with unset optional solver fields (NotProvided)

1 participant