feat(kcsolve): JSON serialization for all solver types (Phase 3a) #299

Merged
forbes merged 2 commits from feat/kcsolve-serialization into main 2026-02-20 18:01:33 +00:00
Owner

Summary

Phase 3a of the solver server integration chain (ref #289). Adds to_dict()/from_dict() JSON serialization to all KCSolve pybind11 types, enabling SolveContext and SolveResult transport as JSON between the Create client, Silo server, and solver runners.

Changes

src/Mod/Assembly/Solver/bindings/kcsolve_py.cpp (+754 lines)

  • 5 constexpr enum string mapping tables (BaseJointKind 24 values, SolveStatus 4, DiagnosticKind 4, MotionKind 3, LimitKind 4) with template enum_to_str()/str_to_enum() helpers
  • 10 pairs of file-local to_dict()/from_dict() conversion functions for all types
  • .def("to_dict") and .def_static("from_dict") attached to every py::class_<> binding

src/Mod/Assembly/AssemblyTests/TestKCSolvePy.py (+259 lines)

  • New TestKCSolveSerialization class with 16 tests

Serialization format (per SOLVER.md §3)

  • SolveContext.to_dict() includes api_version: 1 field
  • SolveContext.from_dict() validates api_version, raises ValueError on mismatch
  • Enums serialize as strings matching pybind11 .value() names
  • Transform: {"position": [x,y,z], "quaternion": [w,x,y,z]}
  • Optional simulation field serializes as None/null
  • Pure pybind11 py::dict construction — no new dependencies

Tests

Test Coverage
Round-trip all types Transform, Part, Constraint+Limits, SolveContext, SolveResult, MotionDef, SimulationParams
Enum exhaustive All 24 BaseJointKind, all 4 SolveStatus values
stdlib JSON json.dumps()json.loads()from_dict()
Error handling Missing key → KeyError, invalid enum → ValueError, bad array length → ValueError, wrong api_version → ValueError

Build

Compiles clean in release (cmake --build build/release --target kcsolve_py). All 32 tests pass (16 new + 16 existing).

## Summary Phase 3a of the solver server integration chain (ref #289). Adds `to_dict()`/`from_dict()` JSON serialization to all KCSolve pybind11 types, enabling SolveContext and SolveResult transport as JSON between the Create client, Silo server, and solver runners. ## Changes **`src/Mod/Assembly/Solver/bindings/kcsolve_py.cpp`** (+754 lines) - 5 constexpr enum string mapping tables (BaseJointKind 24 values, SolveStatus 4, DiagnosticKind 4, MotionKind 3, LimitKind 4) with template `enum_to_str()`/`str_to_enum()` helpers - 10 pairs of file-local `to_dict()`/`from_dict()` conversion functions for all types - `.def("to_dict")` and `.def_static("from_dict")` attached to every `py::class_<>` binding **`src/Mod/Assembly/AssemblyTests/TestKCSolvePy.py`** (+259 lines) - New `TestKCSolveSerialization` class with 16 tests ## Serialization format (per SOLVER.md §3) - `SolveContext.to_dict()` includes `api_version: 1` field - `SolveContext.from_dict()` validates api_version, raises `ValueError` on mismatch - Enums serialize as strings matching pybind11 `.value()` names - Transform: `{"position": [x,y,z], "quaternion": [w,x,y,z]}` - Optional `simulation` field serializes as `None`/`null` - Pure pybind11 `py::dict` construction — no new dependencies ## Tests | Test | Coverage | |------|----------| | Round-trip all types | Transform, Part, Constraint+Limits, SolveContext, SolveResult, MotionDef, SimulationParams | | Enum exhaustive | All 24 BaseJointKind, all 4 SolveStatus values | | stdlib JSON | `json.dumps()` → `json.loads()` → `from_dict()` | | Error handling | Missing key → KeyError, invalid enum → ValueError, bad array length → ValueError, wrong api_version → ValueError | ## Build Compiles clean in release (`cmake --build build/release --target kcsolve_py`). All 32 tests pass (16 new + 16 existing).
forbes added 2 commits 2026-02-20 17:58:38 +00:00
Comprehensive specification covering:
- Architecture: solver module integrated into Silo's job queue system
- Data model: JSON schemas for SolveContext and SolveResult transport
- REST API: submit, status, list, cancel endpoints under /api/solver/
- SSE events: solver.created, solver.progress, solver.completed, solver.failed
- Runner integration: standalone kcsolve execution, capability reporting
- Job definitions: manual solve, commit-time validation, kinematic simulation
- SolveContext extraction: headless Create and .kc archive packing
- Database schema: solver_results table with per-revision result caching
- Configuration: server and runner config patterns
- Security: input validation, runner isolation, authentication
- Client SDK: Python client and Create workbench integration sketches
- Implementation plan: Phase 3a-3e breakdown
feat(kcsolve): add to_dict()/from_dict() JSON serialization for all types
All checks were successful
Build and Test / build (pull_request) Successful in 31m19s
7e766a228e
Phase 3a of the solver server integration: add dict/JSON serialization
to all KCSolve pybind11 types so SolveContext and SolveResult can be
transported as JSON between the Create client, Silo server, and solver
runners.

Implementation:
- Constexpr enum string mapping tables for all 5 enums (BaseJointKind,
  SolveStatus, DiagnosticKind, MotionKind, LimitKind) with template
  bidirectional lookup helpers
- File-local to_dict/from_dict conversion functions for all 10 types
  (Transform, Part, Constraint::Limit, Constraint, MotionDef,
  SimulationParams, SolveContext, ConstraintDiagnostic,
  SolveResult::PartResult, SolveResult)
- .def("to_dict") and .def_static("from_dict") on every py::class_<>
  binding chain

Serialization details per SOLVER.md §3:
- SolveContext.to_dict() includes api_version field
- SolveContext.from_dict() validates api_version, raises ValueError on
  mismatch
- Enums serialize as strings matching pybind11 .value() names
- Transform: {position: [x,y,z], quaternion: [w,x,y,z]}
- Optional simulation serializes as None/null
- Pure pybind11 py::dict construction, no new dependencies

Tests: 16 new tests in TestKCSolveSerialization covering round-trips for
all types, all 24 BaseJointKind values, all 4 SolveStatus values,
json.dumps/loads stdlib round-trip, and error cases (missing key,
invalid enum, bad array length, wrong api_version).
forbes merged commit 1ed73e3eb0 into main 2026-02-20 18:01:33 +00:00
forbes deleted branch feat/kcsolve-serialization 2026-02-20 18:01:33 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kindred/create#299