Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Memory and execution

CyteArc keeps large matrices in Zarr and streams planned blocks through memory. It does not load the full count matrix simply because a DataStore is opened. Memory use still depends on the operation: graph construction and clustering can hold structures in addition to the streamed count blocks.

Set resources and inspect a run

Set a budget and worker count when sharing a machine or submitting a batch job. For an existing RNA store, this example allows up to four workers and a 16 GiB operation budget:

# Import CyteArc for the analysis.
import cytearc

# Open the existing store with the chosen resource limits.
ds = cytearc.DataStore("data.zarr", mem_budget="16G", nthreads=4)

# Run the RNA recipe under a new analysis label.
run = ds.pipeline.rna(label="rna_analysis")

# Inspect recorded stage timings, memory use, and reused results.
run.report()

Use a new label for each run. To inspect a completed run without recomputing it, reopen its label with ds.pipeline.open(label="rna_analysis") and call report() on that result. The report includes stage timings, sampled resident memory (RSS), and the warnings that each stage logged. Sampled peaks can miss brief allocations.

mem_budget is an operation budget, not a hard cap on total process resident memory. It covers the data that CyteArc holds: the arrays and blocks that grow with the cells, features, values and chunks an operation works on. Python, Zarr and NumPy hold a little more of their own, such as objects, file buffers and temporaries, so leave some headroom beside the budget. Memory the process already holds when an operation starts, such as the interpreter, native libraries, graph structures, and earlier results, is not subtracted either, so a process can peak at its resident memory plus the budget.

The sections below explain what the budget covers, how workers are chosen, and how to compare measurements.

Resource controls

Memory budget

mem_budget accepts bytes, a size such as "8G", or a fraction of detected system memory such as "0.6". The size suffixes K, M, G, and T are powers of 1024, alone or followed by B or iB, so "8G", "8GB", and "8GiB" are the same budget. A budget that is not a positive finite size, such as "inf", and a worker count below one, from nthreads or CYTEARC_WORKERS, raise ValueError. Without an explicit value or CYTEARC_MEM_BUDGET, it defaults to 75% of detected memory, using the smaller of physical memory and any detected cgroup limit: the total, not the memory free when the budget is resolved, so leave room for other processes on a shared host. Physical memory comes from /proc/meminfo on Linux, sysconf on macOS and other Unix systems, and GlobalMemoryStatusEx on Windows. Where neither physical memory nor a cgroup limit can be read, a default or fractional budget raises RuntimeError, and a size such as mem_budget="16G" still works. Explicit budgets, including fractions of detected memory, are not reduced. Each operation reserves within it the blocks it reads and what Zarr holds while it reads them: for a sharded array, such as the counts, a shard-level copy of the selection and the compressed chunks the read touches in a shard, and for every array the chunks it decodes, which an unsharded array, such as normalized data, holds beside their compressed bytes. For a block transformed by a chain of element-wise steps, such as library-size scaling followed by a logarithm, it reserves the step of the chain that holds the most, one step’s input beside its output. It also reserves its kernel scratch and results, and limits its concurrent reads and writes and the width of automatically sized feature batches to fit. Imports write the default count layout unless they are given a policy, and an import whose default count shards do not fit stops before it writes, naming the smaller policy that fits; given policy="fit", it writes that policy instead. A sparse import charges what its producer holds: a source batch of one band of rows, which holds an int64 row and column beside each value, and the band’s values, which it holds twice, with two mask bytes each, while it cuts the band. That is about 62 bytes for each nonzero count of a band of 4-byte values, beside the band it writes; rows whose indices are unsorted or repeated add their sort, and an assay of a few features, such as antibodies whose band spans every cell, is charged its own values only. Subset, repack, merge, and grouped assays fit the count layout to the budget by default, writing smaller count shards. The layout changes how the counts are stored, never the store’s identity.

Some steps hold whole structures in memory beside their streamed blocks, and compare an estimate of them with the budget before they read a coordinate or graph:

Over the budget, such a step raises MemoryBudgetError before it reads anything or creates or loads an index, naming the bytes, the cells and other sizes, and the limit; it never changes its algorithm on its own. The estimates count the arrays that grow with the data; silhouette also counts the distance buffers and reductions made beside its distance chunks. The budget compares them with its limit; they are not a cap on the memory of the process, which also holds the interpreter, native libraries and their own buffers, and earlier results. A coordinate stream’s reads reserve what its consumer holds while it reads, and a consumer releases each block before the stream reads the next. Cluster selection reads its sampled cells in blocks of the stored coordinates, so it decodes every stored chunk that holds one of them, which for a sample spread over a large normalized matrix is most of it.

graph.ann_index saves the index through a temporary file of about 4 * dims + 8 * ann_m + 20 bytes per cell, and graph.neighbors loads it through another one of the same size, in the system’s temporary directory (TMPDIR on Linux and macOS); leave that much free space there. variants.import_counts sorts the rows that outgrow its budget in runs in the same directory, about 4 bytes per count row of mgatk’s files, and removes them when the import ends. An import that shuffles cells keeps the cells’ rows in the reader’s temp_dir, about one byte per stored count, and deletes them as it writes the counts. A composite with remote sources keeps downloaded source objects in the same temporary directory, up to CYTEARC_SOURCE_CACHE_BYTES per open composite (2 GiB unless set; 0 reads the sources directly). That disk space is outside mem_budget, and where the temporary directory is memory-backed, such as a tmpfs /tmp, it uses memory.

An RNA run with pca={"dims": 0} builds its graph on the normalized values of the selected features, one coordinate per highly variable gene, so the memory and time of the ANN index, the neighbor queries, the embedding initialization, and cluster selection scale with the HVG count instead of the PCA dimensions. At 1,000,000 cells the index alone holds about 4.3 GB with 1,000 HVGs and 8.3 GB with 2,000 at the default ann_m=24, and the embedding initialization holds every cell’s coordinates, 4 bytes per HVG per cell, when one stored band holds every cell; pass embedding_initialization={"batch_size": ...} with a batch size below the cell count to select its streamed fit, which holds a sample of the cells and one block of coordinates at a time.

A stream that closes early, such as one whose consumer stops or fails, can leave a chunk fetch or decode of one of its reads still running on a codec thread. That call ends just after, holding at most one chunk per busy codec thread, which is part of the headroom to leave: in the default layouts a chunk holds at most 128 MiB of normalized values, 100 MB of counts and 16 MiB of a new store’s cell column.

What a refusal names

The receptor import, clonotypes, gene_usage, spectratype, export_airr and the other repertoire steps charge what each step will hold to the budget before the step allocates, and refuse a step that would pass it before anything is written. So do the imports of clones, lineage barcodes, recorder alleles, phylogenies and variant counts, from the selected cells’ positions and IDs to the artifact they write: the join of the files’ barcodes to the cells, the clones gathered, the records encoded, each chunk of a file, whose rows the room left when the file is planned sizes, and the save. So do from_column, which stamps the column by its stored chunks before it reads a label, the clone summaries, their loads and the clone export, the figure labels of clonotypes, and the calls of clones from lineage barcodes, recorder alleles and phylogenies, each on one ledger from its first read to its write, the steps of clone calling and the search for near sequences included. So do the screen’s guide calling, call_guides and import_guide_calls, perturbation.labels, their loaders and the perturbation recipe’s check of a call file, from the guide IDs, the cells’ positions, samples and IDs to the calls, labels and fits they write: the call file’s parse and the join of its barcodes, the histograms of the fitted methods as they grow, the padded calls and the save. So does genotype_clones, from the sites it reads to the clones it writes: the calls, read in bands of cells whose rows the room sizes and packed 64 sites to a word, each fit’s arrays of cells by components and each step of its search, or the exact rule’s sets and graph. Every grouping of cells, of the clone summaries, of gene usage and junction lengths, of figures and of the clone callers’ within columns, charges the same way what it reads and builds beside what the call holds when it groups. The refusal is a MemoryBudgetError, a MemoryError, whose message names the step, the bytes the call needs at that step and the budget, and closes with the budget that passes the step:

Importing contigs for 8 selected cells holds about 1154586 bytes for a chunk of 1000 contig rows
as parsed, more than the memory budget of 1000000 bytes. Raise mem_budget to at least 1154586
bytes, or pass a smaller cell_selection.

The error holds the same numbers as needed_bytes and budget_bytes, and the step as item. A budget of needed_bytes passes that step; a later step can need more, and names it the same way. A step whose blocks take a share of the room, such as a file’s chunks or from_column’s blocks of labels, reads larger blocks at a larger budget, so the budget that its refusals name runs it, and a budget a little below may run it too, with smaller blocks. Each step is charged:

The count value scan, which reads every count of an import to choose the dtype that stores the counts, words its refusal as the example above does. It names the budget of the longest row or column of the matrix, also when that comes after the one that the scan stopped at or in another run of a 10x HDF5 file’s selected barcodes, so a budget of needed_bytes scans the whole matrix. An H5AD import restates the refusals of its scan, of its shuffle and of its conversion of a matrix compressed by column in the same words, with its own budget: what the step needs beside the IDs, names and other arrays that the import holds throughout. A conversion refused before it reads any entry names the budget of its row with the most entries, which the row indices give. Shuffled imports of 10x HDF5, Matrix Market and Tapestri files restate the refusals of their scan and shuffle beside the cell order. A shuffled CSV import restates its shuffle’s refusal the same way, with the least budget that passes the shuffle, since a larger budget sizes larger buckets, which need less memory beside them. SparseToZarr restates its scan’s refusal beside the matrices that it holds.

Every other memory check raises a MemoryBudgetError with the same three fields and keeps its own message, which ends with the bytes the step needs where it named none:

needed_bytes is always a mem_budget: where a step plans with part of the budget, as normalization’s producer does beside its writer and chromVAR’s background model with half of it, it names the whole budget that leaves the step what it needs. One refusal names no budget that passes it: a count write handed a batch larger than its producer reserved names what the write would reserve with that batch, which can be below the budget, since the producer broke its own reservation. Lineage curves write the cells’ positions and distances a whole chunk band of 100,000 rows at a time, and count each band and what Zarr holds to write it. The checks of the other variant operations raise a MemoryError of their own, and the screen’s other operations, efficiency, edistance, signature, mixscape, associations, profiles and cluster, raise a MemoryBudgetError in their own words.

The budget bounds the bytes that these steps charge, not the resident memory of the process. The identity checks of stored cell and feature selections, which most operations run once on their inputs, read the row identifiers one stored chunk at a time and hold one chunk, with its selected rows where they check a row order, outside the budget: at most 16 MiB of values in a new store’s cell table. Only the first check of a process decodes the identifiers; later checks reuse its fingerprint while the identifiers’ stored bytes are unchanged, and so do the checks of the columns that a run snapshot holds, such as the feature names of a graph’s highly variable genes. A planner that sizes a step before its call has a ledger, such as the loads of variant calls and recorder alleles, measures a column of variable-width text without a ledger to charge, and holds one stored chunk of it outside the budget the same way, unless a read of the operation measured the column first. glibc can also keep freed buffers of 32 MiB or less resident after an operation; setting the MALLOC_MMAP_THRESHOLD_ environment variable, for example to 131072, before Python starts returns them to the system.

Worker concurrency

Worker concurrency is auto-detected from the process environment. On shared hosts, multiprocess jobs, or remote object stores, set CYTEARC_WORKERS or pass the advanced nthreads constructor argument to bound the maximum worker budget. Zarr decompresses and compresses a store’s chunks on at most nthreads threads for every read and write through its DataStore: opening the store, its operations, plots, exports and recipes, and the arrays that you compute from it yourself, such as ds.RNA.rawData, so nthreads=1 keeps that work on one core. DataStores open on one store, or on one location, such as a local folder or a remote URL, decompress its chunks on the fewest of their nthreads, and an import, a subset, a merge, a mount, a composite or a repack does this work on its own nthreads. A Zarr codec pipeline that you configure in place of Zarr’s default decompresses on all of the host’s threads. More workers can increase concurrent buffers or remote requests, so pair a large worker budget with an explicit mem_budget. Opt-in parallel UMAP layouts and ANN index builds are faster but not reproducible: two runs on several threads can differ even with the same thread count. Their artifact identities therefore record only the parallel or ann_parallel flag, and the thread counts are execution options, so the same request reuses its result on any machine. A serial UMAP layout runs on one thread and releases the GIL during each epoch, so other Python threads of the process, such as an application’s heartbeat, keep running. Doublet detection scores as many samples at once as the workers and the memory budget hold. A sample of 50,000 cells and simulated doublets or more is indexed in 4 parts, built at once, and every index is built on one thread, whatever ann_parallel says, so a sample’s scores are the same for any thread count. Leiden clustering with the default "cytearc" backend runs on the worker budget and returns identical labels for any thread count, so its artifacts record no worker count either; the optional "igraph" and "leidenalg" backends run on one thread. t-SNE always runs on one thread through the optional sgtsnepi package, so its artifacts record no worker count. GRN inference with nthreads above 1 fits the targets left after about two seconds of fitting in worker processes, as many as nthreads allows; regulons.grn runs fewer when the memory budget holds fewer of them, each charged its own copy of the regulators and one fit. Every target’s regressor has the same seed, so the links are the same for any thread count. The workers start as new interpreters that import the main module, so a script keeps its own work under if __name__ == "__main__":.

Each process plans within its own mem_budget and nthreads and knows nothing of what other processes hold, so processes that analyze one store at once (Several processes on one store), or share a machine, each need their share: two processes might each take mem_budget="0.35" and half the cores.

Why RNA stores have two count orientations

Most analysis steps walk the matrix by cell. Quality control, library-size normalization, and graph construction read rows of counts. Gene-wise steps such as highly variable gene selection and marker search walk the matrix by feature.

Those two access patterns compete on a single physical layout. CyteArc therefore stores RNA counts twice: counts is cell-major, and countsT contains the same values in gene-major order. They are two orientations of one assay matrix, not two datastores. The second orientation roughly doubles stored RNA counts. ATAC, ADT, and other non-RNA assays keep only counts.

Current RNA stores require a matching current-layout countsT. Store inspection, import, and offline rewrite procedures belong to Import and export and the FAQ, rather than the memory-planning model on this page.

Storage profiles

New writers use Zarr v3 and choose one of two profiles:

Override automatic selection with a writer’s profile=, a datastore’s zarrProfile=, or CYTEARC_ZARR_PROFILE=fast_local|cloud. The profile determines the physical encoding when arrays are written. Changing it while reopening an existing store does not rewrite the arrays.

See Explore a remote dataset to mount a remote dataset and save your work separately. Storage options, source identity, and local_cache scratch behavior are covered in Remote storage configuration.

Batch and HPC output

Disable animated progress in non-interactive logs and add timestamps:

# Configure output for a non-interactive job.
import cytearc

# Disable progress bars and add log timestamps.
cytearc.configure_output(progress=False, timestamps=True)

Progress rendering and log severity are independent. To also select a log level or file:

# Write informational logs to a local file.
cytearc.set_verbosity(level="INFO", filepath="cytearc-run.log")

A job that configures Python’s logging can receive CyteArc’s records there instead: cytearc.configure_output(stdlib=True) sends them to the standard-library logger named cytearc, and a record logged during a pipeline stage carries the run ID and stage as its cytearc_run_id and cytearc_stage attributes. set_verbosity returns the records to CyteArc’s own output. With progress bars off, a pipeline run still sends stage_progress events to its callback and listeners, so a job can record progress without rendering bars.

See the utilities API reference for the exact output contract.

Measuring resource use

Measure the complete workflow on the hardware and storage service you intend to use. Runtime and memory depend on dataset sparsity, selected features, graph parameters, worker count, cache state, and software versions.

Record the dataset and cell selection, analysis settings, code revision, dependency versions, CPU and memory limits, storage location, and whether the run reused existing artifacts. Keep conversion and download time separate from analysis time, and report both stage timings and the complete elapsed time. Repeat measurements under the same conditions before comparing changes.

A pipeline run records, for each stage, its wall and CPU time, sampled resident memory and the process’s peak, OS threads, network bytes, the worker count and memory budget it was given, the CPUs and memory its process could use, and a trace of samples, beside its warnings and summary, in run.report() (Stage resources). ds.pipeline.plan reports these values from the latest earlier run that computed each stage, so the stages that stay on one core, read the most over the network, or need the most memory show before a run starts. Sampled peaks can miss brief allocations; the process’s peak RSS, which the kernel keeps, holds them when a stage raised it. mem_budget controls planned work and is not a hard limit on the process’s resident memory; see Memory budget.

For focused performance checks, the repository’s benchmark suite measures input-size ladders and projects their scaling to larger workloads:

# Measure the benchmark input sizes and project their scaling.
CYTEARC_RUN_BENCHMARKS=1 uv run pytest -n 0 tests/benchmarks

Without a baseline, this records measurements without a regression comparison. See Contributing for creating a baseline, comparing revisions on the same machine, and interpreting projected delays.

Compare remote and local storage only with matched datasets, analysis settings, resources, and cache conditions. Measurements from one workload do not establish biological correctness or hardware requirements for another. See Explore a remote dataset for storage and mounting mechanics.