Examples

Below is a table of example QECX files, available in the python-qecx package. They can be downloaded as standalone files from the package’s source repository, or accessed in Python through qecx.examples. Like any other QECX file, they can be parsed and validated with the python-qecx package (see Quickstart) or its qecx command-line tool (see Command line). After the table, a detailed walkthrough of each field of the QECX file steane_7_1_3.qecx ↓ for a Steane code (CSS) with n=7, k=1 and d=3 is provided as a demonstration of the format.

More QECX files for a range of codes are available in Haiqu’s public QEC code library.

Example files

Click a filename to read it in the source repository, or the arrow (↓) beside it to download it.

Name

Code

Container

steane_7_1_3.qecx ↓

Steane code (CSS) with n=7, k=1 and d=3

JSON

steane_7_1_3_stabilizer.qecx ↓

Steane code (stabilizer) with n=7, k=1 and d=3

JSON

color_488_d3.qecx ↓

Triangular 4.8.8 color code with n=7, k=1 and d=3

JSON

color_488_d5.qecx ↓

Triangular 4.8.8 color code with n=17, k=1 and d=5

JSON

color_488_d7.qecx ↓

Triangular 4.8.8 color code with n=31, k=1 and d=7

ZIP archive

color_666_d3.qecx ↓

Triangular 6.6.6 color code with n=7, k=1 and d=3

JSON

rotated_surface_d3.qecx ↓

Rotated surface code with n=9, k=1 and d=3

JSON

ZIP archive .qecx container

Files like color_488_d7.qecx are ZIP archives rather than plain-text JSON. Both take the .qecx extension, and a reader tells them apart by their content. An archive is an ordinary ZIP file, so you can open it with any archive tool. manifest.json, at the root of the archive, holds the document. Its circuits, matrices and other large parts can sit beside it as separate files, and manifest.json points to each one by path. To change a field, edit manifest.json and leave the circuit and matrix files alone. See Containers for more information.

Steane code example

The Steane code encodes one logical qubit in seven physical qubits, with distance three. It is defined in the QECX file steane_7_1_3.qecx ↓, which is a plain-text JSON document, shown below in full, one top-level field at a time. For reference, the specification’s top-level structure lists every top-level field.

qec_version

"qec_version": "0.1",

The format version the file needs: a reader of format version 0.1 can read every feature in it. See qec_version semantics.

code

"code": {
  "name": "Steane Code",
  "code_type": "css",
  "n": 7,
  "k": 1,
  "d": 3,
  "H_X": [
    [1, 1, 1, 1, 0, 0, 0],
    [0, 1, 1, 0, 1, 1, 0],
    [0, 0, 1, 1, 0, 1, 1]
  ],
  "H_Z": [
    [1, 1, 1, 1, 0, 0, 0],
    [0, 1, 1, 0, 1, 1, 0],
    [0, 0, 1, 1, 0, 1, 1]
  ],
  "logical_operators": {
    "X": ["IIIIXXX"],
    "Z": ["IIIIZZZ"]
  }
},

The code’s algebraic definition, independent of any circuit:

  • name: an optional label for people to read.

  • code_type: "css", so the stabilizers are given as two parity-check matrices. Other code types, such as "stabilizer", take other fields.

  • n, k and d: 7 physical qubits per code block, 1 logical qubit and distance 3.

  • H_X and H_Z: the X-type and Z-type parity-check matrices, with one row per stabilizer generator and one column per physical qubit. The Steane code is self-dual, so the two are equal.

  • logical_operators: one X and one Z Pauli string per logical qubit, in logical-qubit order.

See §1 code in the specification and the Code section of the JSON schema.

register_template

"register_template": {
  "per_code_block": {
    "data_qreg": {
      "size": 7
    },
    "ancilla_qregs": {
      "syndrome": {
        "size": 3,
        "purpose": "syndrome"
      }
    }
  }
},

The registers each code block has, which the circuits below refer to:

  • data_qreg: the block’s 7 data qubits. Its size equals code.n.

  • ancilla_qregs: here a single register, syndrome, of 3 ancilla qubits, whose purpose says they extract the syndrome.

Registers that all code blocks share would go in an optional global section. See §2 register_template in the specification and the Register template section of the JSON schema.

operations

The circuits, with one key per operation type. Each operation offers one or more variants, alternative circuits for the same operation, and names one of them its default. Every variant has:

  • a description, and whether it is fault_tolerant;

  • the registers it uses: qregs for quantum registers and cregs for classical ones. A register with "scope": "block" refers by ref to a register of the register template. One with "scope": "output" is created by the operation and kept afterwards, for example for a decoder to read;

  • its circuit in qasm, an OpenQASM 3 program that declares exactly those registers.

See §3 operations in the specification and the Operations section of the JSON schema.

state_preparation

"state_preparation": {
  "0": {
    "default": "mqt_optimal",
    "variants": {
      "mqt_optimal": {
        "description": "Preparation of |0_L> with a circuit from MQT QECC gate-optimal synthesis. Not fault-tolerant: the circuit is unverified.",
        "fault_tolerant": false,
        "references": ["peham_2025_mqt_qecc", "mqt_qecc"],
        "qregs": {
          "q_data": {
            "scope": "block",
            "ref": "data_qreg"
          }
        },
        "qasm": "OPENQASM 3.0;\ninclude \"stdgates.inc\";\nqubit[7] q_data;\nh q_data[2];\nh q_data[5];\nh q_data[6];\ncx q_data[2], q_data[0];\ncx q_data[6], q_data[3];\ncx q_data[5], q_data[1];\ncx q_data[3], q_data[1];\ncx q_data[1], q_data[4];\ncx q_data[2], q_data[1];\ncx q_data[2], q_data[3];\ncx q_data[5], q_data[2];"
      }
    }
  }
},

Prepares a logical state from physical qubits in |0⟩. The key is the state: "0" is logical |0⟩. The variant’s references cite entries of properties.references (below) by their key. See state_preparation.

reset

"reset": {
  "0": {
    "default": "mqt_optimal",
    "variants": {
      "mqt_optimal": {
        "description": "Reset of every data qubit followed by the preparation of |0_L> with a circuit from MQT QECC gate-optimal synthesis. Not fault-tolerant: the circuit is unverified.",
        "fault_tolerant": false,
        "qregs": {
          "q_data": {
            "scope": "block",
            "ref": "data_qreg"
          }
        },
        "qasm": "OPENQASM 3.0;\ninclude \"stdgates.inc\";\nqubit[7] q_data;\nreset q_data;\nh q_data[2];\nh q_data[5];\nh q_data[6];\ncx q_data[2], q_data[0];\ncx q_data[6], q_data[3];\ncx q_data[5], q_data[1];\ncx q_data[3], q_data[1];\ncx q_data[1], q_data[4];\ncx q_data[2], q_data[1];\ncx q_data[2], q_data[3];\ncx q_data[5], q_data[2];"
      }
    }
  }
},

Resets a block to a logical state, keyed like state_preparation. Here it resets every data qubit and then runs the preparation circuit again. reset is optional, as is logical_measurement, which this file leaves out. See reset.

data_measurement

"data_measurement": {
  "Z": {
    "default": "direct",
    "variants": {
      "direct": {
        "description": "Z-basis measurement of every data qubit.",
        "fault_tolerant": true,
        "transversal_readout_cregs": [
          {
            "name": "c_data_meas",
            "source": "H_Z"
          }
        ],
        "qregs": {
          "q_data": {
            "scope": "block",
            "ref": "data_qreg"
          }
        },
        "cregs": {
          "c_data_meas": {
            "scope": "output",
            "size": 7,
            "purpose": "logical_data"
          }
        },
        "result_creg": "c_data_meas",
        "qasm": "OPENQASM 3.0;\ninclude \"stdgates.inc\";\nqubit[7] q_data;\nbit[7] c_data_meas;\nmeasure q_data -> c_data_meas;"
      }
    }
  }
},

Measures every data qubit of a block, which ends the block. The key is the basis: "Z". result_creg names the register that holds the 7 raw outcomes, and its purpose, "logical_data", marks them as measured data qubits. transversal_readout_cregs declares that the parity of these bits over each row of H_Z equals that Z check’s value, so a decoder can check the outcomes against the stabilizers and then work out the logical result with the Z logical operator, and the variant is fault-tolerant. See data_measurement and Readout declarations.

logical_gates

"logical_gates": {
  "h": [
    {
      "operands": [
        {
          "block": 0,
          "logical_qubit": null
        }
      ],
      "default": "transversal",
      "variants": {
        "transversal": {
          "description": "Transversal Hadamard: H on every qubit. The code is self-dual, so the stabilizer group maps to itself.",
          "fault_tolerant": true,
          "qregs": {
            "q_data": {
              "scope": "block",
              "block_index": 0,
              "ref": "data_qreg"
            }
          },
          "qasm": "OPENQASM 3.0;\ninclude \"stdgates.inc\";\nqubit[7] q_data;\nh q_data;"
        }
      }
    }
  ],
  "s": [
    {
      "operands": [
        {
          "block": 0,
          "logical_qubit": null
        }
      ],
      "default": "transversal",
      "variants": {
        "transversal": {
          "description": "Transversal S: S† on every qubit, which acts as logical S. Every check has weight 4, so the stabilizer group maps to itself.",
          "fault_tolerant": true,
          "qregs": {
            "q_data": {
              "scope": "block",
              "block_index": 0,
              "ref": "data_qreg"
            }
          },
          "qasm": "OPENQASM 3.0;\ninclude \"stdgates.inc\";\nqubit[7] q_data;\nsdg q_data;"
        }
      }
    }
  ],
  "cx": [
    {
      "operands": [
        {
          "block": 0,
          "logical_qubit": null,
          "role": "control"
        },
        {
          "block": 1,
          "logical_qubit": null,
          "role": "target"
        }
      ],
      "default": "transversal",
      "variants": {
        "transversal": {
          "description": "Transversal CNOT between two code blocks: one CNOT on each pair of corresponding qubits.",
          "fault_tolerant": true,
          "qregs": {
            "q_data_ctrl": {
              "scope": "block",
              "block_index": 0,
              "ref": "data_qreg"
            },
            "q_data_tgt": {
              "scope": "block",
              "block_index": 1,
              "ref": "data_qreg"
            }
          },
          "qasm": "OPENQASM 3.0;\ninclude \"stdgates.inc\";\nqubit[7] q_data_ctrl;\nqubit[7] q_data_tgt;\ncx q_data_ctrl, q_data_tgt;"
        }
      }
    }
  ]
},

The logical gates, keyed by gate name: h, s and cx. Each gate lists the operand groups it supports. operands names the logical qubits a gate acts on, by code block and logical_qubit. A logical_qubit of null stands for any logical qubit of the block, which here is its only one. cx acts on two blocks, so each of its registers says which block it belongs to with block_index. All three gates are transversal, and so fault-tolerant. See logical_gates.

syndrome_measurement

"syndrome_measurement": {
  "default": "sequential",
  "variants": {
    "sequential": {
      "description": "Sequential syndrome extraction with one ancilla per check. Not fault-tolerant: hook errors from the single bare ancilla per check reduce the circuit-level distance below d.",
      "fault_tolerant": false,
      "syndrome_cregs": [
        {
          "name": "c_z_syndrome",
          "source": "H_Z"
        },
        {
          "name": "c_x_syndrome",
          "source": "H_X"
        }
      ],
      "qregs": {
        "q_data": {
          "scope": "block",
          "ref": "data_qreg"
        },
        "a_syndrome": {
          "scope": "block",
          "ref": "syndrome"
        }
      },
      "cregs": {
        "c_z_syndrome": {
          "scope": "output",
          "size": 3,
          "purpose": "syndrome"
        },
        "c_x_syndrome": {
          "scope": "output",
          "size": 3,
          "purpose": "syndrome"
        }
      },
      "qasm": "OPENQASM 3.0;\ninclude \"stdgates.inc\";\nqubit[7] q_data;\nqubit[3] a_syndrome;\nbit[3] c_z_syndrome;\nbit[3] c_x_syndrome;\n// --- Z-stabilizer extraction (detects X errors) ---\n// Z stabilizer 0: qubits {0,1,2,3} (H_Z row 0)\nreset a_syndrome[0];\ncx q_data[0], a_syndrome[0];\ncx q_data[1], a_syndrome[0];\ncx q_data[2], a_syndrome[0];\ncx q_data[3], a_syndrome[0];\nmeasure a_syndrome[0] -> c_z_syndrome[0];\n// Z stabilizer 1: qubits {1,2,4,5} (H_Z row 1)\nreset a_syndrome[1];\ncx q_data[1], a_syndrome[1];\ncx q_data[2], a_syndrome[1];\ncx q_data[4], a_syndrome[1];\ncx q_data[5], a_syndrome[1];\nmeasure a_syndrome[1] -> c_z_syndrome[1];\n// Z stabilizer 2: qubits {2,3,5,6} (H_Z row 2)\nreset a_syndrome[2];\ncx q_data[2], a_syndrome[2];\ncx q_data[3], a_syndrome[2];\ncx q_data[5], a_syndrome[2];\ncx q_data[6], a_syndrome[2];\nmeasure a_syndrome[2] -> c_z_syndrome[2];\nbarrier a_syndrome;\n// --- X-stabilizer extraction (detects Z errors) ---\n// X stabilizer 0: qubits {0,1,2,3} (H_X row 0)\nreset a_syndrome[0];\nh a_syndrome[0];\ncx a_syndrome[0], q_data[0];\ncx a_syndrome[0], q_data[1];\ncx a_syndrome[0], q_data[2];\ncx a_syndrome[0], q_data[3];\nh a_syndrome[0];\nmeasure a_syndrome[0] -> c_x_syndrome[0];\n// X stabilizer 1: qubits {1,2,4,5} (H_X row 1)\nreset a_syndrome[1];\nh a_syndrome[1];\ncx a_syndrome[1], q_data[1];\ncx a_syndrome[1], q_data[2];\ncx a_syndrome[1], q_data[4];\ncx a_syndrome[1], q_data[5];\nh a_syndrome[1];\nmeasure a_syndrome[1] -> c_x_syndrome[1];\n// X stabilizer 2: qubits {2,3,5,6} (H_X row 2)\nreset a_syndrome[2];\nh a_syndrome[2];\ncx a_syndrome[2], q_data[2];\ncx a_syndrome[2], q_data[3];\ncx a_syndrome[2], q_data[5];\ncx a_syndrome[2], q_data[6];\nh a_syndrome[2];\nmeasure a_syndrome[2] -> c_x_syndrome[2];"
    }
  }
}

Measures the stabilizers: the three Z-type ones into c_z_syndrome, then the three X-type ones into c_x_syndrome. syndrome_cregs says which bits hold which checks: c_z_syndrome holds one bit per row of H_Z, in order, and c_x_syndrome one per row of H_X. The barrier in the circuit separates its time steps. See syndrome_measurement and Readout declarations.

error_correction_cycle

"error_correction_cycle": {
  "default": "single_sequential",
  "variants": {
    "single_sequential": {
      "description": "Sequential syndrome extraction, one round.",
      "fault_tolerant": false,
      "steps": [
        {
          "measurement": "sequential"
        }
      ]
    },
    "repeated_sequential": {
      "description": "Sequential syndrome extraction, d rounds.",
      "fault_tolerant": false,
      "steps": [
        {
          "measurement": "sequential",
          "repeat": {
            "ref": "code.d"
          }
        }
      ]
    }
  }
},

How syndrome measurements make up a full error-correction cycle. Each variant lists steps, and each step names a variant of syndrome_measurement. repeated_sequential repeats its step code.d times, a reference that resolves to 3 from the code section. See §6 error_correction_cycle and Parametric references.

decoder_config

"decoder_config": {
  "tesseract": {}
},

The syndrome decoders the file supports, keyed by decoder name. A name with an empty body, as tesseract here, declares that the decoder works with this code and needs no further settings. Other decoders need more: chromobius, for example, takes a color for each check, as in the color code example files. See §7 decoder_config.

properties

"properties": {
  "author": "Haiqu",
  "creator": "qecx-generator (generate_steane_code.py) from the qecx reference example steane_7_1_3.qecx; python-qecx 0.1.dev30",
  "license": "CC-BY-4.0",
  "description": "The Steane code [[7,1,3]], built from the [7,4,3] Hamming code. Its three X checks and three Z checks have the same supports, each of weight 4, so H, S and CNOT are transversal. It is the triangular color code at distance 3.",
  "references": [
    {
      "key": "steane_1996",
      "title": "Error correcting codes in quantum theory",
      "doi": "10.1103/PhysRevLett.77.793",
      "note": "Defines the [[7,1,3]] Steane code",
      "authors": "A. M. Steane",
      "year": 1996
    },
    {
      "key": "peham_2025_mqt_qecc",
      "title": "Automated Synthesis of Fault-Tolerant State Preparation Circuits for Quantum Error-Correction Codes",
      "doi": "10.1103/PRXQuantum.6.020330",
      "arxiv": "2408.11894",
      "note": "Gate-optimal Clifford synthesis used by state_preparation.0.mqt_optimal",
      "authors": "T. Peham, L. Schmid, L. Berent, M. Müller, and R. Wille",
      "year": 2025
    },
    {
      "key": "mqt_qecc",
      "title": "MQT QECC - A tool for Quantum Error Correcting Codes",
      "url": "https://github.com/munich-quantum-toolkit/qecc",
      "note": "MQT-QECC software providing the gate-optimal synthesis used by state_preparation.0.mqt_optimal"
    }
  ]
}

Optional metadata: who wrote the file (author), the software that wrote it (creator), its license, and bibliographic references, which variants cite by key. Other keys, such as description, are free-form. See §4 properties.

One optional top-level section is not in this file: a qubit layout, qubit_layout. The color code and rotated surface code example files have one.