Skip to content

Serialize scipy.sparse matrices across the sandbox boundary - #60

Merged
eliotwrobson merged 1 commit into
mainfrom
claude/sparse-serialization
Nov 20, 2026
Merged

eliotwrobson merged 1 commit into
mainfrom
claude/sparse-serialization

Conversation

@eliotwrobson

Copy link
Copy Markdown
Collaborator

Summary

query and query_function now serialize scipy.sparse matrices and arrays back to the grader. CSR, CSC and COO keep their native data/indices/indptr (or row/col) arrays, so the matrix round-trips exactly as the student built it; other formats are returned as COO. Previously a sparse value came back as NOT_SERIALIZABLE.

This unblocks converting legacy questions whose graded output is a sparse matrix read directly from student code (e.g. CS357's 11-Sparse/DBLP-matrix-normalization, which checks modified_A.indices/.indptr/.data), without changing the student's task.

scipy is added to the dev/test dependency group (it is already in the full image via requirements-full.txt); the import stays lazy, so json_utils still loads with no scientific stack on the :lite image.

Testing

  • Unit round-trip tests over CSR/CSC/COO, matrix and array flavors, and int/float/complex dtypes, through an actual json.dumps/loads to exercise the real transport.
  • A new test_sparse_matrix_query scenario runs the full sandbox: student code builds sparse matrices, the test queries them back (and a function that returns one) and checks values and index arrays.
  • Full suite green (333 passed), mypy, ruff, and format clean on Python 3.14.

🤖 Generated with Claude Code

`query` and `query_function` now round-trip scipy.sparse matrices and
arrays. CSR, CSC and COO keep their native index arrays so the matrix
comes back exactly as the student built it, including their own ordering
of entries; other formats are returned as COO. Previously a sparse value
came back as NOT_SERIALIZABLE, so questions whose graded output is a
sparse matrix couldn't be run.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@eliotwrobson
eliotwrobson marked this pull request as ready for review November 20, 2026 06:41
@eliotwrobson
eliotwrobson merged commit 51b1170 into main Nov 20, 2026
5 checks passed
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