Skip to content

Add idempotence tests for export/import serialization#263

Merged
ocots merged 3 commits intodevelopfrom
test/serialization-idempotence
Jan 29, 2026
Merged

Add idempotence tests for export/import serialization#263
ocots merged 3 commits intodevelopfrom
test/serialization-idempotence

Conversation

@ocots
Copy link
Copy Markdown
Member

@ocots ocots commented Jan 29, 2026

Add idempotence tests for export/import serialization

Summary

This PR adds comprehensive idempotence tests for the export_ocp_solution and import_ocp_solution functions to verify that multiple export-import cycles produce stable results with no progressive information loss.

Changes

Test Implementation (~460 lines)

Helper Functions (test/suite/serialization/test_export_import.jl):

  • compare_trajectories: Compares function-based trajectories at time points
  • compare_infos: Deep comparison of Dict{Symbol,Any} with type awareness
  • compare_solutions: Comprehensive Solution object comparison with configurable tolerances

New Test Cases (7 total):

  • JSON (4 tests): Double/triple cycles with duals, without duals, complex infos
  • JLD2 (3 tests): Double/triple cycles with duals, without duals

Documentation

Analysis: reports/2026-01-29_Idempotence/analysis/01_serialization_idempotence_analysis.md

  • Identified 6 potential information loss points
  • Analyzed existing test coverage
  • Future investigation items (function serialization, deepcopy usage)

Implementation Plan: reports/2026-01-29_Idempotence/reference/01_serialization_idempotence_plan.md

  • Detailed test strategy and verification plan

Walkthrough: reports/2026-01-29_Idempotence/walkthrough.md

  • Summary of changes and test results
  • Key findings and recommendations

Test Results

Test Summary:                               | Pass  Total   Time
CTModels tests                              | 1721   1721  14.4s
  suite/serialization/test_export_import.jl | 1721   1721  14.4s
     Testing CTModels tests passed

✅ All tests pass - No regressions

Key Findings

Information Preserved ✅

  • All scalar fields (objective, iterations, status, etc.)
  • Time grid and variable (full precision)
  • All trajectories (state, control, costate)
  • All dual variables
  • Infos dictionary structure and values

Expected Transformations 🔄

  1. Functions → Discretization: Analytical functions become interpolated after JSON export/import

    • Impact: Minimal (within atol=1e-8)
    • Idempotent after first cycle
  2. Symbols → Strings: Symbols in infos become strings after JSON serialization

    • Example: :optimal"optimal"
    • Idempotent after first cycle

Conclusion

No progressive information loss: sol₁ ≈ sol₂ ≈ sol₃ after multiple cycles.

Future Work

The analysis identified areas for future investigation:

  • Bidirectional ctinterpolate/ctdeinterpolate for lossless function serialization
  • Review of deepcopy usage in build_solution (rationale unclear)
  • Improved JLD2 handling of anonymous functions

See analysis document for details.

Related Issue

Closes #217

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 29, 2026

Breakage test results
Date: 2026-01-29 13:31:06

Name Latest Stable
CTDirect compat: v0.6.10-beta compat: v0.7.1-beta.1
CTFlows compat: v0.6.10-beta compat: v0.7.1-beta.1
OptimalControl compat: v0.6.10-beta compat: v0.6.10-beta

ocots added 2 commits January 29, 2026 13:48
- Add 3 helper functions for deep Solution comparison
- Add 7 idempotence test cases (4 JSON, 3 JLD2)
- Test double and triple export-import cycles
- Verify no progressive information loss
- Add comprehensive analysis and documentation

All 1721 tests pass. Closes #217
- Add infos_symbol_keys metadata field to track Symbol values
- Implement path-based Symbol restoration during deserialization
- Update _serialize_infos and _deserialize_infos to handle Symbol tracking
- Fix type conversion issues with JSON3.Array using collect()
- Update test expectations to verify Symbol preservation
- All 1722 tests pass

Closes part of #217
@ocots ocots merged commit fd3cfed into develop Jan 29, 2026
18 of 19 checks passed
@ocots ocots deleted the test/serialization-idempotence branch January 29, 2026 13:23
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