# 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 {py:mod}`qecx.examples`. Like any other QECX file, they can be parsed and validated with the `python-qecx` package (see [Quickstart](quickstart.md)) or its `qecx` command-line tool (see [Command line](command_line.md)). After the table, a [detailed walkthrough](#steane-code-example) of each field of the QECX file [`steane_7_1_3.qecx`](repo:src/qecx/examples/steane_7_1_3.qecx) {download}`↓ <../src/qecx/examples/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](https://dashboard.haiqu.ai/qec). ## 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`](repo:src/qecx/examples/steane_7_1_3.qecx) {download}`↓ <../src/qecx/examples/steane_7_1_3.qecx>` | Steane code (CSS) with n=7, k=1 and d=3 | JSON | | [`steane_7_1_3_stabilizer.qecx`](repo:src/qecx/examples/steane_7_1_3_stabilizer.qecx) {download}`↓ <../src/qecx/examples/steane_7_1_3_stabilizer.qecx>` | Steane code (stabilizer) with n=7, k=1 and d=3 | JSON | | [`color_488_d3.qecx`](repo:src/qecx/examples/color_488_d3.qecx) {download}`↓ <../src/qecx/examples/color_488_d3.qecx>` | Triangular 4.8.8 color code with n=7, k=1 and d=3 | JSON | | [`color_488_d5.qecx`](repo:src/qecx/examples/color_488_d5.qecx) {download}`↓ <../src/qecx/examples/color_488_d5.qecx>` | Triangular 4.8.8 color code with n=17, k=1 and d=5 | JSON | | [`color_488_d7.qecx`](repo:src/qecx/examples/color_488_d7.qecx) {download}`↓ <../src/qecx/examples/color_488_d7.qecx>` | Triangular 4.8.8 color code with n=31, k=1 and d=7 | ZIP archive | | [`color_666_d3.qecx`](repo:src/qecx/examples/color_666_d3.qecx) {download}`↓ <../src/qecx/examples/color_666_d3.qecx>` | Triangular 6.6.6 color code with n=7, k=1 and d=3 | JSON | | [`rotated_surface_d3.qecx`](repo:src/qecx/examples/rotated_surface_d3.qecx) {download}`↓ <../src/qecx/examples/rotated_surface_d3.qecx>` | Rotated surface code with n=9, k=1 and d=3 | JSON | (zip-archive-container)= :::{admonition} ZIP archive `.qecx` container :class: note Files like `color_488_d7.qecx` are [ZIP archives](format_specification.md#containers) 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](format_specification.md#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`](repo:src/qecx/examples/steane_7_1_3.qecx) {download}`↓ <../src/qecx/examples/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](format_specification.md#top-level-structure) lists every top-level field. ### `qec_version` ```{literalinclude} ../src/qecx/examples/steane_7_1_3.qecx :language: json :start-at: '"qec_version"' :end-before: '"code": {' :dedent: 2 ``` The format version the file needs: a reader of format version 0.1 can read every feature in it. See [`qec_version` semantics](format_specification.md#qec_version-semantics). ### `code` ```{literalinclude} ../src/qecx/examples/steane_7_1_3.qecx :language: json :start-at: '"code": {' :end-before: '"register_template": {' :dedent: 2 ``` 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`](format_specification.md#1-code-algebraic-definition) in the specification and the [Code section](json_schema.md#1-code-section) of the JSON schema. ### `register_template` ```{literalinclude} ../src/qecx/examples/steane_7_1_3.qecx :language: json :start-at: '"register_template": {' :end-before: '"operations": {' :dedent: 2 ``` 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`](format_specification.md#2-register_template-declarative-register-layout) in the specification and the [Register template section](json_schema.md#2-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`](format_specification.md#3-operations-circuit-implementations) in the specification and the [Operations section](json_schema.md#3-operations-section) of the JSON schema. #### `state_preparation` ```{literalinclude} ../src/qecx/examples/steane_7_1_3.qecx :language: json :start-at: '"state_preparation": {' :end-before: '"reset": {' :dedent: 4 ``` 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`](format_specification.md#state_preparation). #### `reset` ```{literalinclude} ../src/qecx/examples/steane_7_1_3.qecx :language: json :start-at: '"reset": {' :end-before: '"data_measurement": {' :dedent: 4 ``` 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`](format_specification.md#reset-optional). #### `data_measurement` ```{literalinclude} ../src/qecx/examples/steane_7_1_3.qecx :language: json :start-at: '"data_measurement": {' :end-before: '"logical_gates": {' :dedent: 4 ``` 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`](format_specification.md#data_measurement) and [Readout declarations](format_specification.md#readout-declarations). #### `logical_gates` ```{literalinclude} ../src/qecx/examples/steane_7_1_3.qecx :language: json :start-at: '"logical_gates": {' :end-before: '"syndrome_measurement": {' :dedent: 4 ``` 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`](format_specification.md#logical_gates). #### `syndrome_measurement` % The last operation in the file: lines leaves out the line that closes % operations, which dedent would otherwise reject. If syndrome_measurement changes length, % change the 42. ```{literalinclude} ../src/qecx/examples/steane_7_1_3.qecx :language: json :start-at: '"syndrome_measurement": {' :end-before: '"error_correction_cycle": {' :lines: 1-42 :dedent: 4 ``` 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`](format_specification.md#syndrome_measurement) and [Readout declarations](format_specification.md#readout-declarations). ### `error_correction_cycle` ```{literalinclude} ../src/qecx/examples/steane_7_1_3.qecx :language: json :start-at: '"error_correction_cycle": {' :end-before: '"decoder_config": {' :dedent: 2 ``` 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`](format_specification.md#6-error_correction_cycle-ec-cycle-composition) and [Parametric references](format_specification.md#parametric-references). ### `decoder_config` ```{literalinclude} ../src/qecx/examples/steane_7_1_3.qecx :language: json :start-at: '"decoder_config": {' :end-before: '"properties": {' :dedent: 2 ``` 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](#example-files). See [§7 `decoder_config`](format_specification.md#7-decoder_config-syndrome-decoder-declaration). ### `properties` % The last top-level field: lines leaves out the line that closes the file, which dedent % would otherwise reject. If properties changes length, change the 31. ```{literalinclude} ../src/qecx/examples/steane_7_1_3.qecx :language: json :start-at: '"properties": {' :lines: 1-31 :dedent: 2 ``` 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`](format_specification.md#4-properties-metadata-and-provenance). One optional top-level section is not in this file: a qubit layout, [`qubit_layout`](format_specification.md#5-qubit_layout-spatial-geometry-and-coordinates). The color code and rotated surface code [example files](#example-files) have one.