{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/roroquantum-com/json-schema/roroquantum-com-run-schema.json",
  "title": "Run",
  "x-generated": "2026-11-23",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/roroquantum-com-openapi.yml#/components/schemas/Run",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "machineTargetId": {
      "type": "string",
      "description": "The target's codename."
    },
    "machineName": {
      "type": "string",
      "description": "Friendly display name of the target."
    },
    "shots": {
      "type": "integer"
    },
    "status": {
      "type": "string",
      "enum": [
        "queued",
        "running",
        "completed",
        "failed",
        "cancelled"
      ]
    },
    "cost": {
      "type": "number",
      "format": "double",
      "description": "Credits charged for this run."
    },
    "counts": {
      "type": [
        "object",
        "null"
      ],
      "description": "Measured bitstring counts (present when completed).",
      "additionalProperties": {
        "type": "integer"
      }
    },
    "probabilities": {
      "type": [
        "object",
        "null"
      ],
      "description": "Normalized probabilities per bitstring (present when completed).",
      "additionalProperties": {
        "type": "number"
      }
    },
    "error": {
      "type": [
        "string",
        "null"
      ],
      "description": "Failure reason (present when status is failed)."
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "qasm": {
      "type": [
        "string",
        "null"
      ],
      "description": "The submitted OpenQASM 2.0 source."
    },
    "providerJobId": {
      "type": [
        "string",
        "null"
      ],
      "description": "Upstream provider job id",
      "when run on real hardware.": null
    },
    "providerStatus": {
      "type": [
        "string",
        "null"
      ],
      "description": "Live raw provider status while running (e.g. 'Running'); null for instant simulator runs."
    },
    "queuePosition": {
      "type": [
        "integer",
        "null"
      ],
      "description": "Jobs ahead on the backend while queued; null for instant simulator runs."
    },
    "refundable": {
      "type": "boolean",
      "description": "True when a failed, charged run has a machine-side error — you may `POST /v1/runs/{id}/refund`."
    },
    "refundStatus": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "pending",
        "approved",
        "rejected"
      ],
      "description": "The refund audit trail: null (no refund involved), `pending` (requested), `approved` (credited — automatic refunds appear here), `rejected`."
    },
    "notebookId": {
      "type": [
        "string",
        "null"
      ],
      "description": "Set when the run was submitted from a console notebook."
    },
    "labProjectId": {
      "type": [
        "string",
        "null"
      ],
      "description": "Set when the run was submitted from a lab project."
    },
    "countsProvenance": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "measured",
        "provider-corrected"
      ],
      "description": "Where `counts` came from: `measured` as read out, or `provider-corrected` (the provider already applied its own readout correction). Null for runs that predate the label — read them as received."
    },
    "effectiveShots": {
      "type": [
        "integer",
        "null"
      ],
      "description": "Shot-equivalents billed — equal to `shots` for a plain run."
    },
    "resilience": {
      "nullable": true,
      "allOf": [
        {
          "$ref": "#/$defs/ResilienceInfo"
        }
      ]
    },
    "mitigated": {
      "nullable": true,
      "allOf": [
        {
          "$ref": "#/$defs/Mitigated"
        }
      ]
    },
    "resilienceDetail": {
      "nullable": true,
      "allOf": [
        {
          "$ref": "#/$defs/ResilienceDetail"
        }
      ]
    }
  },
  "$defs": {
    "Calibration": {
      "type": [
        "object",
        "null"
      ],
      "description": "Readout error rates measured in this run. Index i is the i-th character from the RIGHT of a counts key.",
      "properties": {
        "source": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "measured-this-run"
          ]
        },
        "shots": {
          "type": [
            "integer",
            "null"
          ]
        },
        "bits": {
          "type": [
            "integer",
            "null"
          ]
        },
        "qubits": {
          "type": "array",
          "items": {
            "type": "integer"
          }
        },
        "p01": {
          "type": "array",
          "items": {
            "type": "number"
          },
          "description": "P(read 1 | prepared 0) per bit."
        },
        "p10": {
          "type": "array",
          "items": {
            "type": "number"
          },
          "description": "P(read 0 | prepared 1) per bit."
        }
      }
    },
    "Mitigated": {
      "type": "object",
      "description": "The DERIVED distribution and how it was derived. `counts` on the run are never altered.",
      "properties": {
        "probabilities": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": {
            "type": "number"
          }
        },
        "method": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "readout",
            "zne",
            "readout+zne"
          ],
          "description": "`readout+zne`: each scale's counts are readout-corrected, then extrapolated."
        },
        "negativityClipped": {
          "type": [
            "number",
            "null"
          ],
          "description": "Probability mass clipped below zero by the inversion."
        },
        "calibration": {
          "$ref": "#/$defs/Calibration"
        },
        "zne": {
          "$ref": "#/$defs/ZneResult"
        },
        "warnings": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "ResilienceDetail": {
      "type": "object",
      "description": "Raw histograms behind `mitigated` — only on `GET /v1/runs/{id}` and the stream's `done` frame; null in lists and on `POST` responses.",
      "properties": {
        "calibration": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "zeroStateCounts": {
              "type": [
                "object",
                "null"
              ],
              "additionalProperties": {
                "type": "integer"
              }
            },
            "oneStateCounts": {
              "type": [
                "object",
                "null"
              ],
              "additionalProperties": {
                "type": "integer"
              }
            }
          }
        },
        "zne": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "perScaleCounts": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": {
                  "type": "integer"
                }
              },
              "description": "One histogram per scale, in `zneScales` order, never readout-corrected."
            }
          }
        }
      }
    },
    "ResilienceInfo": {
      "type": "object",
      "description": "The resolved, expanded set a quote priced and a run was charged for, with its settled outcome.",
      "properties": {
        "readout": {
          "type": "boolean"
        },
        "calibrationShots": {
          "type": "integer",
          "description": "Shots per calibration circuit (0 without readout)."
        },
        "zneScales": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "integer"
          }
        },
        "zneExtrapolator": {
          "type": [
            "string",
            "null"
          ]
        },
        "zneObservable": {
          "type": [
            "string",
            "null"
          ]
        },
        "zneMode": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "histogram-heuristic",
            "observable"
          ]
        },
        "dd": {
          "type": [
            "string",
            "null"
          ]
        },
        "twirling": {
          "type": "boolean"
        },
        "circuits": {
          "type": "integer",
          "description": "1 + 2·readout + (scales − 1)."
        },
        "effectiveShots": {
          "type": "integer",
          "description": "shots × Σscales + 2 × calibrationShots."
        },
        "baseCostMilli": {
          "type": "integer",
          "description": "What the same run would cost with no resilience."
        },
        "resilienceCostMilli": {
          "type": "integer",
          "description": "The extra, in milli-credits."
        },
        "calibrationSource": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "measured-this-run"
          ],
          "description": "On a simulator the calibration measures the family model's readout rate, not a device."
        },
        "transpiledToNoiseBasis": {
          "type": [
            "boolean",
            "null"
          ],
          "description": "Simulators: the whole set was translated to the noise basis. Null on hardware."
        },
        "projectedSeconds": {
          "type": [
            "number",
            "null"
          ],
          "description": "Simulators: projected wall time from the measured throughput. Null on hardware."
        },
        "status": {
          "type": "string",
          "enum": [
            "planned",
            "applied",
            "partially-applied",
            "zne-measured-not-extrapolated",
            "readout-measured-not-applied",
            "not-applied-refunded"
          ],
          "description": "`zne-measured-not-extrapolated` / `readout-measured-not-applied`: the circuits ran and are charged, the estimate was skipped (see notes). `partially-applied` / `not-applied-refunded`: circuits that did not run were refunded (`refundedMilli`)."
        },
        "refundedMilli": {
          "type": "integer",
          "description": "Milli-credits returned for circuits of the set that did not run."
        },
        "notes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "ZneResult": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "scales": {
          "type": "array",
          "items": {
            "type": "integer"
          }
        },
        "extrapolator": {
          "type": [
            "string",
            "null"
          ]
        },
        "mode": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "histogram-heuristic",
            "observable"
          ]
        },
        "observable": {
          "type": [
            "string",
            "null"
          ]
        },
        "values": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "number"
          },
          "description": "Observable mode: ⟨O⟩ per scale."
        },
        "stderrs": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "number"
          }
        },
        "extrapolated": {
          "type": [
            "number",
            "null"
          ],
          "description": "Null when the extrapolation was skipped."
        },
        "tvdToScale1": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "number"
          }
        },
        "shotNoiseTvd": {
          "type": [
            "number",
            "null"
          ]
        },
        "foldGateRatio": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "number"
          }
        }
      }
    }
  }
}