JSON schemas

Two JSON formats have published schemas, generated from the pydantic models with model_json_schema().

Archive index

The index at the end of every archive is an ArchiveIndex (see Archive format). Read one with ArchiveIndex.model_validate_json(...), or open the archive with Archive.open and use archive.index.

{
  "$defs": {
    "BaseRef": {
      "additionalProperties": false,
      "description": "Names the base archive of a delta archive by file name and index CRC-32.",
      "properties": {
        "index_crc": {
          "title": "Index Crc",
          "type": "integer"
        },
        "name": {
          "title": "Name",
          "type": "string"
        }
      },
      "required": [
        "name",
        "index_crc"
      ],
      "title": "BaseRef",
      "type": "object"
    },
    "ChunkEntry": {
      "additionalProperties": false,
      "description": "The index entry of one chunk: its offset, its stored length, its raw length (1 to `MAX_CHUNK_SIZE` bytes),\nand the CRC-32 of the bytes a reader must produce.",
      "properties": {
        "crc32": {
          "maximum": 4294967295,
          "minimum": 0,
          "title": "Crc32",
          "type": "integer"
        },
        "length": {
          "minimum": 0,
          "title": "Length",
          "type": "integer"
        },
        "offset": {
          "minimum": 0,
          "title": "Offset",
          "type": "integer"
        },
        "raw_length": {
          "maximum": 268435456,
          "minimum": 1,
          "title": "Raw Length",
          "type": "integer"
        }
      },
      "required": [
        "offset",
        "length",
        "raw_length",
        "crc32"
      ],
      "title": "ChunkEntry",
      "type": "object"
    },
    "JsonValue": {},
    "TensorEntry": {
      "additionalProperties": false,
      "description": "The index entry of one tensor: its metadata, the codec id and parameters, `lossless`, `max_abs_err`, and its\nchunks. Each chunk's raw length is a multiple of the item size, and together they are `nbytes`.",
      "properties": {
        "chunks": {
          "items": {
            "$ref": "#/$defs/ChunkEntry"
          },
          "title": "Chunks",
          "type": "array"
        },
        "codec": {
          "title": "Codec",
          "type": "string"
        },
        "dtype": {
          "title": "Dtype",
          "type": "string"
        },
        "lossless": {
          "title": "Lossless",
          "type": "boolean"
        },
        "max_abs_err": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Max Abs Err"
        },
        "name": {
          "title": "Name",
          "type": "string"
        },
        "params": {
          "additionalProperties": {
            "$ref": "#/$defs/JsonValue"
          },
          "title": "Params",
          "type": "object"
        },
        "role": {
          "default": "other",
          "title": "Role",
          "type": "string"
        },
        "shape": {
          "items": {
            "minimum": 0,
            "type": "integer"
          },
          "title": "Shape",
          "type": "array"
        }
      },
      "required": [
        "name",
        "dtype",
        "shape",
        "codec",
        "params",
        "lossless",
        "max_abs_err",
        "chunks"
      ],
      "title": "TensorEntry",
      "type": "object"
    }
  },
  "additionalProperties": false,
  "description": "The JSON index at the end of an archive. `model_json_schema()` is the schema of the format.",
  "properties": {
    "base": {
      "anyOf": [
        {
          "$ref": "#/$defs/BaseRef"
        },
        {
          "items": {
            "$ref": "#/$defs/BaseRef"
          },
          "type": "array"
        },
        {
          "type": "null"
        }
      ],
      "title": "Base"
    },
    "format": {
      "enum": [
        1,
        2
      ],
      "title": "Format",
      "type": "integer"
    },
    "skeleton": {
      "$ref": "#/$defs/JsonValue"
    },
    "source": {
      "$ref": "#/$defs/JsonValue"
    },
    "tensors": {
      "items": {
        "$ref": "#/$defs/TensorEntry"
      },
      "title": "Tensors",
      "type": "array"
    },
    "writer": {
      "title": "Writer",
      "type": "string"
    }
  },
  "required": [
    "format",
    "writer",
    "tensors",
    "skeleton",
    "source",
    "base"
  ],
  "title": "ArchiveIndex",
  "type": "object"
}

Comparison report

jabara bench --json prints a BenchReport, and jabara.bench.compare returns one. report.model_dump_json() returns the JSON text that the results viewer reads. A report has an environment, which records the machine, the versions, and the settings of the run, and one row per candidate and role.

{
  "$defs": {
    "BenchEnvironment": {
      "additionalProperties": false,
      "description": "Where and how the numbers were taken. `load_average_1m` is read once, before the first candidate runs.\n`cpu_model` is the processor name the OS reports (`None` where it reports none). `optional_packages` holds the\nversions of the optional packages a codec can load (`zipnn`, `torch`) that are loaded when the run ends.",
      "properties": {
        "chunk_size": {
          "title": "Chunk Size",
          "type": "integer"
        },
        "cpu_count": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "title": "Cpu Count"
        },
        "cpu_model": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Cpu Model"
        },
        "jabara": {
          "title": "Jabara",
          "type": "string"
        },
        "load_average_1m": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Load Average 1M"
        },
        "machine": {
          "title": "Machine",
          "type": "string"
        },
        "numpy": {
          "title": "Numpy",
          "type": "string"
        },
        "optional_packages": {
          "additionalProperties": {
            "type": "string"
          },
          "title": "Optional Packages",
          "type": "object"
        },
        "platform": {
          "title": "Platform",
          "type": "string"
        },
        "python": {
          "title": "Python",
          "type": "string"
        },
        "repeats": {
          "title": "Repeats",
          "type": "integer"
        },
        "spin_seconds": {
          "title": "Spin Seconds",
          "type": "number"
        },
        "threads": {
          "title": "Threads",
          "type": "integer"
        },
        "warmup_passes": {
          "title": "Warmup Passes",
          "type": "integer"
        },
        "zstandard": {
          "title": "Zstandard",
          "type": "string"
        }
      },
      "required": [
        "jabara",
        "python",
        "platform",
        "machine",
        "cpu_model",
        "cpu_count",
        "load_average_1m",
        "threads",
        "repeats",
        "warmup_passes",
        "spin_seconds",
        "chunk_size",
        "numpy",
        "zstandard",
        "optional_packages"
      ],
      "title": "BenchEnvironment",
      "type": "object"
    },
    "BenchRow": {
      "additionalProperties": false,
      "description": "One candidate on all tensors of one role.\n\n`encode_seconds_all` holds each of `repeats` wall-clock runs (`time.perf_counter`), in run order, of\n`Codec.encode` over every chunk of every tensor of the role, after `warmup_passes` untimed passes;\n`encode_seconds` is the smallest. The chunks run as `write_archive` runs them: on the container's thread pool,\nor one after another with the copy that `Codec.with_threads` returns. A run includes slicing the chunks and\nthe base reference and handing them to the pool or the copy, and nothing else. `decode_seconds_all` and\n`decode_seconds` are the same for `Codec.decode` plus the length and CRC-32 check of each decoded chunk that\n`Archive.read` also does. When any decode pass fails that check, `decode_error` holds the reader's message and\nboth decode fields are `None`, so a broken codec has no decode time to rank. Throughput is\n`raw_bytes / seconds`. Each timed run starts right after the pool's threads and the calling thread have run a busy\nloop for `BenchEnvironment.spin_seconds`; see DESIGN.md, \"Comparison\", for what that was observed to change.\n\nThese seconds are the codec's share of a save or load, not its cost. A real save (`write_archive`) also\ncomputes the CRC-32 of the input, decodes the whole base tensor first when `needs_base`, decodes every chunk\nonce more to check it when `check_decode`, and writes the file. A real load (`Archive.read`) also decodes the\nwhole base tensor first when `needs_base`, and reads the file. `needs_base` is true when a tensor of the row is\ncoded with a delta codec; `check_decode` is true when one is coded with a lossy codec, so it is `not lossless`.\n\n`codecs` lists each distinct codec id and full parameters (defaults filled in, as an archive index records\nthem) that coded the role's tensors, with the number of tensors each coded. `stored_bytes` is the sum of chunk\npayload lengths from one untimed encode pass, without the archive index and magic. `lossless` is the codecs'\nown claim; `bit_exact` compares the decoded bytes with the input and is false when decoding failed.\n`fallback_tensors` counts the tensors for which the candidate chose a delta codec but the base had no\nreference, so they were coded with the choice's `fallback`.",
      "properties": {
        "bit_exact": {
          "title": "Bit Exact",
          "type": "boolean"
        },
        "candidate": {
          "title": "Candidate",
          "type": "string"
        },
        "check_decode": {
          "title": "Check Decode",
          "type": "boolean"
        },
        "codecs": {
          "items": {
            "$ref": "#/$defs/CodecUse"
          },
          "title": "Codecs",
          "type": "array"
        },
        "decode_error": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Decode Error"
        },
        "decode_seconds": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Decode Seconds"
        },
        "decode_seconds_all": {
          "anyOf": [
            {
              "items": {
                "type": "number"
              },
              "type": "array"
            },
            {
              "type": "null"
            }
          ],
          "title": "Decode Seconds All"
        },
        "encode_seconds": {
          "title": "Encode Seconds",
          "type": "number"
        },
        "encode_seconds_all": {
          "items": {
            "type": "number"
          },
          "title": "Encode Seconds All",
          "type": "array"
        },
        "fallback_tensors": {
          "title": "Fallback Tensors",
          "type": "integer"
        },
        "lossless": {
          "title": "Lossless",
          "type": "boolean"
        },
        "max_abs_err": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "title": "Max Abs Err"
        },
        "needs_base": {
          "title": "Needs Base",
          "type": "boolean"
        },
        "raw_bytes": {
          "title": "Raw Bytes",
          "type": "integer"
        },
        "role": {
          "title": "Role",
          "type": "string"
        },
        "stored_bytes": {
          "title": "Stored Bytes",
          "type": "integer"
        }
      },
      "required": [
        "candidate",
        "role",
        "codecs",
        "raw_bytes",
        "stored_bytes",
        "encode_seconds",
        "encode_seconds_all",
        "decode_seconds",
        "decode_seconds_all",
        "decode_error",
        "lossless",
        "needs_base",
        "check_decode",
        "bit_exact",
        "max_abs_err",
        "fallback_tensors"
      ],
      "title": "BenchRow",
      "type": "object"
    },
    "CodecUse": {
      "additionalProperties": false,
      "description": "A codec id and its full parameters, and how many tensors of a row it coded.",
      "properties": {
        "codec_id": {
          "title": "Codec Id",
          "type": "string"
        },
        "params": {
          "additionalProperties": {
            "$ref": "#/$defs/JsonValue"
          },
          "title": "Params",
          "type": "object"
        },
        "tensors": {
          "title": "Tensors",
          "type": "integer"
        }
      },
      "required": [
        "codec_id",
        "params",
        "tensors"
      ],
      "title": "CodecUse",
      "type": "object"
    },
    "JsonValue": {}
  },
  "additionalProperties": false,
  "description": "The result of `compare`: the environment of the run and one row per candidate and role. `model_dump_json()`\nwrites the file that the results viewer reads.",
  "properties": {
    "bench": {
      "const": 1,
      "title": "Bench",
      "type": "integer"
    },
    "environment": {
      "$ref": "#/$defs/BenchEnvironment"
    },
    "rows": {
      "items": {
        "$ref": "#/$defs/BenchRow"
      },
      "title": "Rows",
      "type": "array"
    }
  },
  "required": [
    "bench",
    "environment",
    "rows"
  ],
  "title": "BenchReport",
  "type": "object"
}