Input and Output
save_code is the single entry point for writing a code to disk. The destination format is chosen by the type keyword, which is dispatched on internally, so adding a format does not change the call site. See the input and output tutorial for worked examples of each format.
The formats differ in what they preserve, and the difference matters:
:csvwrites a bare matrix. It is the most portable option and the most lossy, since the field, the code type, and any cached metadata are gone.:tomlwrites a human-readable, portable description of a quantum code, including the field, the checks, and the parameters, along with a SHA-256 fingerprint of the check data so that corruption is detectable on load.:pauliwrites stabilizers as Pauli strings, which is the interchange format most other quantum software understands.:jld2and:npz(also accepted as:nz) require their respective package extensions to be loaded.:jld2round-trips native Julia objects, while:npztargets NumPy consumers; its reader accepts SciPy's zero-based CSR index convention.
CodingTheory.code_matrix_array — Method
code_matrix_array(
C::AbstractLinearCode;
representation
) -> Any
Return a classical code matrix as a plain Matrix{Int} over the prime field. Extension-field symbols are expanded into adjacent coordinate columns.
The default representation is the generator matrix for general linear codes and the parity-check matrix for LDPC codes.
CodingTheory.save_code — Method
save_code(
path::AbstractString,
C::AbstractCode;
type,
kwargs...
) -> Any
Return path after exporting a classical, LDPC, stabilizer, or subsystem code through a unified interface. The backend is selected by Val(type); type=:auto infers it from the file extension. :nz is accepted as an alias for :npz.
CSV and NPZ are numeric matrix exports. TOML and JLD2 are complete portable quantum-code formats. Pauli output is a lossy binary quantum format.
CodingTheory.write_code_csv — Method
write_code_csv(
path::AbstractString,
C::AbstractLinearCode;
representation
) -> AbstractString
Return path after writing code_matrix_array(C) as a header-free numeric CSV suitable for numpy.loadtxt(path, delimiter=",", dtype=int). For LDPC codes the default is representation=:parity_check.
CSV stores only one matrix and is not a complete code serialization.
Quantum codes
CodingTheory.load_quantum_code — Method
load_quantum_code(
path::AbstractString;
format,
restore_cache
) -> Union{StabilizerCode, StabilizerCodeCSS, SubsystemCode, SubsystemCodeCSS}
Return a stabilizer or subsystem code loaded from TOML, JLD2, or a phase-free Pauli-string file. Set restore_cache=false to ignore stored cache entries.
CodingTheory.pauli_strings — Method
pauli_strings(
S::AbstractSubsystemCode;
generators
) -> Vector{String}
Return binary symplectic generators as strings over I, X, Y, and Z. Phase information is not included; use save_quantum_code for a lossless round trip.
CodingTheory.quantum_code_data — Method
quantum_code_data(
S::AbstractSubsystemCode
) -> Dict{String, Any}
Return a language-neutral dictionary describing S. Matrices are flattened in row-major order after expanding each GF(q) entry over its prime field. This is the schema used by save_quantum_code and is directly consumable from Python, Julia, or other TOML/JLD2 readers.
CodingTheory.quantum_code_from_data — Method
quantum_code_from_data(
payload::AbstractDict;
restore_cache
) -> Union{StabilizerCode, StabilizerCodeCSS, SubsystemCode, SubsystemCodeCSS}
Return a stabilizer or subsystem code reconstructed from a portable quantum_code_data dictionary. Validate the integrity fingerprint before restoring generators or certified cache entries.
CodingTheory.quantum_generator_array — Method
quantum_generator_array(
S::AbstractSubsystemCode;
generators
) -> Any
Return the selected quantum generators as a plain Matrix{Int} over the prime field. Extension-field entries are expanded into adjacent coordinate columns. The result can be passed directly to PythonCall/NumPy or written with write_quantum_csv.
generators=:presentation selects the gauge group for subsystem codes and the stabilizer group otherwise.
CodingTheory.read_pauli_strings — Method
read_pauli_strings(
path::AbstractString;
subsystem
) -> Union{StabilizerCode, StabilizerCodeCSS, SubsystemCode, SubsystemCodeCSS}
Return a stabilizer code, or a subsystem code when subsystem=true, parsed from a file containing one phase-free binary Pauli generator per line.
CodingTheory.save_quantum_code — Method
save_quantum_code(
path::AbstractString,
S::AbstractSubsystemCode;
format,
allow_lossy
) -> AbstractString
Return path after persisting a stabilizer or subsystem code. TOML is the portable, dependency-free format. JLD2 is available when JLD2 is loaded. Certified cache data is bound to the generator payload by a SHA-256 integrity fingerprint. Files ending in .pauli or .stab omit phase/cache metadata and therefore require allow_lossy=true.
CodingTheory.write_pauli_strings — Method
write_pauli_strings(
path::AbstractString,
S::AbstractSubsystemCode;
generators
) -> AbstractString
Return path after writing one phase-free binary Pauli generator per line. Throw an error when the code has a nonempty character vector because this format cannot preserve explicit phases.
CodingTheory.write_quantum_csv — Method
write_quantum_csv(
path::AbstractString,
S::AbstractSubsystemCode;
generators
) -> AbstractString
Return path after writing a header-free numeric CSV containing quantum_generator_array(S). It is directly readable with numpy.loadtxt(path, delimiter=",", dtype=int).
CSV stores only a selected generator matrix. It does not preserve field, phase, code-kind, or cached metadata; use TOML for a complete portable round trip.