# ADR-0018: Each Object a Later Step Reads Is Saved in One Format ## Status Accepted 2026-12-02 ## Context A calibration runs once and is analysed many times, often in different scripts, and a command line passes results from one command to the next. irtlib wrote and read only item banks (ADR-0009), so each script calibrated again, which costs much for Markov chain Monte Carlo. The maintainer asked for few formats, and for no object to have two. Two measurements, taken on 2026-12-02, settled the formats: - A gzipped CSV file is as small as a NumPy `.npz` file. Responses of 10,000 examinees to 100 items, a fifth of them missing, take 1,801 kB as CSV, 251 kB gzipped, and 232 kB to 397 kB as `.npz`. - With the defaults, a Markov chain Monte Carlo calibration of 40 items keeps 4 million draws. As many standard normal values take 32 MB with `numpy.savez` and 85 MB as JSON, which also has no NaN, while a calibration has NaN wherever a parameter is not estimated. ## Decision - **irtlib saves what a later step reads again, each object in one format.** Tables go to CSV: the bank (ADR-0009), the response matrix and the ability estimates. A calibration, which is not a table, goes to NumPy's `.npz`. Fit statistics and model comparisons get no file, since they recompute in milliseconds from a saved calibration and its responses, and neither do the settings, since a calibration file holds its grid. - **One module, `irtlib.files`, reads and writes them**, the bank's own methods aside. It sits above `irtlib.mcmc` in the import layers, so `read_calibration` returns the class that was written, a Markov chain Monte Carlo calibration with its draws. - **CSV files share the bank's conventions**, gzip-compressed when the path ends in `.gz`. A missing response is written as R writes it, `NA`, and a number that is not finite as `Inf`, `-Inf` or `NaN`. Each column of the abilities file is named after its attribute. - **A calibration file** stores each attribute as an array under its name, the bank, grid and abilities taken apart into arrays, and records the class, irtlib's version and a format number. The number goes up with every change an earlier reader cannot read, and a reader refuses a number it does not know. Reading never unpickles, and builds every object through its constructor. - **Names live in the files, not in the results.** Results keep the items' generated names. The readers return the item and examinee names beside the data, and the writers take them. ## Consequences - Every object a later step needs is saved and loaded by a pair of calls, and R reads every CSV file with `read.csv`, gzipped ones included. - A calibration file opens neither in a spreadsheet nor in R without a reader of NumPy's format; people read it by loading and printing it (ADR-0017). - A bank built from a calibration takes the response file's item names from its caller, who maps each item's generated name to its column. ## Alternatives Considered - Pickle: unpickling a file runs the code it holds, a renamed field breaks every file saved before, and only Python reads it. - JSON for calibrations: it has no NaN, and draws take more than twice the space. - `.npz` for every object: responses and banks come from and go to R and spreadsheets as CSV, so they would need two formats. - Methods on each class, such as `Calibration.to_npz`: `irtlib.calibration` sits below `irtlib.mcmc`, so its reader could not return a Markov chain Monte Carlo calibration. - Names in the results: every calibrator and estimator would take names that only files need.