Skip to content

Benchmark checkpoints fail for nested objects inside NumPy arrays #23

Description

@danielgaskins

Bug

Environment

OS: Linux
Browser: Not applicable
Python: 3.12.11
AISteer360 commit: 1d7c84314b19341ac78c9ae4ee1eabf4e2f58632

Issue Summary

to_jsonable() does not recursively convert values inside NumPy arrays. It calls ndarray.tolist() and returns the resulting list directly.

For object arrays, values such as Path instances or sets remain unchanged. Benchmark._save_checkpoint() then passes the result to json.dump(), which raises TypeError instead of saving the checkpoint.

Steps to Reproduce

import json
from pathlib import Path

import numpy as np

from aisteer360.evaluation.utils.data_utils import to_jsonable

profiles = {
    "params": np.array(
        [Path("models/base"), {"layers": {1, 2}}],
        dtype=object,
    )
}

safe = to_jsonable(profiles)
json.dumps(safe)

The converted value still contains a Path and a set:

{'params': [PosixPath('models/base'), {'layers': {1, 2}}]}

The final call fails with:

TypeError: Object of type PosixPath is not JSON serializable

Expected Behaviour

Values produced by ndarray.tolist() should pass through the same recursive conversion used for ordinary lists. The result should be accepted by json.dump() so benchmark checkpoint saving does not fail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions