> ## Documentation Index
> Fetch the complete documentation index at: https://docs.haiqu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# QEC Code Library

> Browse the quantum error-correcting codes that QEC circuits can be compiled to and run with.

The Haiqu QEC code library is the collection of quantum error-correcting codes available on the
Haiqu cloud. Each code is identified by a unique slug, such as `"color_488_d3"`, and that slug is
how a code is referred to when compiling circuits to it with
[qec\_compile](https://docs.haiqu.ai/reference/run/qec_compile.md) and when running circuits with
[qec\_run](https://docs.haiqu.ai/reference/run/qec_run.md).

The library can be browsed from the SDK in two ways:

* `haiqu.list_qec_codes` lists the codes page by page, optionally filtered by family, code type,
  completeness tier, number of physical qubits and code distance. Its `q` argument searches the
  codes by the beginning of their name or slug.
* `haiqu.get_qec_code` fetches a single code by its slug.

```python theme={null}
from haiqu.sdk import haiqu

haiqu.login()
haiqu.init("qec-code-library")

page = haiqu.list_qec_codes(family=["color"], completeness=["full"])
for code in page.items:
    print(code.slug, code.name)

code = haiqu.get_qec_code("color_488_d3")
```

The details of an individual code, such as the logical operations it supports and how they are
implemented, are defined by the code's `.qecx` file and are shown in the code library on the
[Haiqu dashboard](https://dashboard.haiqu.ai).

# Completeness tiers

Every code belongs to one of three completeness tiers, given by its `completeness` field. The
tier says how much of the code is available in the library:

| Tier | Meaning |
| - | - |
| `"full"` | The code is defined together with the circuits that implement its operations. Only codes in this tier can be compiled to with `haiqu.qec_compile` or used to compile circuits during `haiqu.qec_run`. |
| `"partial"` | The code is defined, but its circuits are incomplete or missing, so it cannot be compiled to. |
| `"metadata_only"` | Only descriptive information about the code, such as its parameters and family, is recorded. The code has no `.qecx` file and cannot be compiled to. |

To list only the codes that can be compiled to, pass `completeness=["full"]` to
`haiqu.list_qec_codes`.

# Current limitations

* Downloading `.qecx` files with `haiqu.download_qec_code` is not available yet: the call
  raises `requests.HTTPError` for every code that has a file.

#### Haiqu.list\_qec\_codes(family=None, code\_type=None, completeness=None, n=None, d=None, q=None, page=1, page\_size=20)

List the codes of the Haiqu QEC code library, optionally filtered.

The results come in pages. Each filter keeps the codes that match any of its values, and
the filters given together keep only the codes that match all of them. The values of
`family`, `code_type` and `completeness` are matched exactly, including case, so an
unknown value matches no codes rather than raising an error.

* **Parameters:**
  * **family** (*list* \*\[\**str* *]*  *|* *None*) -- Keep the codes of these code families, given by their slugs
    (the `family` field of a code), e.g. `["color"]`. Defaults to `None`, no
    family filter.
  * **code\_type** (*list* \*\[\**str* *]*  *|* *None*) -- Keep the codes of these code types: `"css"`,
    `"stabilizer"`, `"subsystem_css"`, `"subsystem_stabilizer"`. Defaults to
    `None`, no code type filter.
  * **completeness** (*list* \*\[\**str* *]*  *|* *None*) -- Keep the codes in these completeness tiers:
    `"full"`, `"partial"`, `"metadata_only"`, as explained in
    [Completeness tiers](https://docs.haiqu.ai/reference/run/qec_codes.md#completeness-tiers).
    Defaults to `None`, no completeness filter.
  * **n** (*list* \*\[\**int* *]*  *|* *None*) -- Keep the codes with one of these numbers of physical qubits.
    Defaults to `None`, no filter on the number of physical qubits.
  * **d** (*list* \*\[\**int* *]*  *|* *None*) -- Keep the codes with one of these code distances. A code whose X
    and Z distances differ matches no value. Defaults to `None`, no distance filter.
  * **q** (*str* *|* *None*) -- Keep the codes whose name or slug starts with this text, ignoring
    case. Defaults to `None`, no search.
  * **page** (*int*) -- Number of the page to return, starting at 1. A page past the last one has
    no items. Defaults to 1.
  * **page\_size** (*int*) -- Maximum number of codes per page. Defaults to 20.
* **Returns:**
  The requested page of matching codes, with the total number
  of matching codes.
* **Return type:**
  [QECCodeListResponseModel](#haiqu.sdk.schemas.QECCodeListResponseModel)

- **Raises:**
  **requests.HTTPError** -- If the request fails, for example because a value of `n` or
  `d` is not an integer. In a notebook, an error message is shown and `None` is
  returned instead.

#### Examples

```python theme={null}
>>> page = haiqu.list_qec_codes(family=["color"], completeness=["full"])
>>> slugs = [code.slug for code in page.items]
```

#### Haiqu.get\_qec\_code(slug)

Get a code of the Haiqu QEC code library by its slug.

* **Parameters:**
  **slug** (*str*) -- Slug of the code, as listed by `haiqu.list_qec_codes`, e.g.
  `"color_488_d3"`.
* **Returns:**
  The code.
* **Return type:**
  [QECCodeModel](#haiqu.sdk.schemas.QECCodeModel)

- **Raises:**
  * **ValueError** -- If the library has no code with this slug.
  * **requests.HTTPError** -- If the request fails for another reason. In a notebook, an error
    message is shown and `None` is returned instead.

#### Examples

```python theme={null}
>>> code = haiqu.get_qec_code("color_488_d3")
>>> code.name
'Distance-3 Triangular 4.8.8 Color Code'
>>> code.n, code.k, code.d
(7, 1, 3)
```

#### Haiqu.download\_qec\_code(slug)

Download the `.qecx` file of a code of the Haiqu QEC code library.

A `.qecx` file holds the definition of a code together with the circuits that implement
its operations, as far as these are available. Codes in the `"metadata_only"` tier have
no file (see [Completeness tiers](https://docs.haiqu.ai/reference/run/qec_codes.md#completeness-tiers)).

* **Parameters:**
  **slug** (*str*) -- Slug of the code, as listed by `haiqu.list_qec_codes`, e.g.
  `"color_488_d3"`.
* **Returns:**
  The content of the code's `.qecx` file. Currently, downloading is not
  available, and the call raises `requests.HTTPError` for every code that has a
  file (see [Current limitations](https://docs.haiqu.ai/reference/run/qec_codes.md#current-limitations)).
* **Return type:**
  bytes

- **Raises:**
  * **ValueError** -- If the library has no code with this slug, or the code is in the
    `"metadata_only"` tier and so has no file.
  * **requests.HTTPError** -- If the request fails for another reason.

### *class* haiqu.sdk.schemas.QECCodeModel

A code of the Haiqu QEC code library, as returned by `haiqu.get_qec_code` and `haiqu.list_qec_codes`.

A code in the `"full"` tier can be passed to `haiqu.qec_compile` and `haiqu.qec_run`
either by its slug or as this model. Which logical operations a code supports and how they are
implemented is defined by the code's `.qecx` file and shown in the code library on the
[Haiqu dashboard](https://dashboard.haiqu.ai).

#### slug

Unique identifier of the code, used to refer to it in `haiqu.get_qec_code`,
`haiqu.qec_compile` and `haiqu.qec_run`.

* **Type:**
  str

#### name

Display name of the code.

* **Type:**
  str

#### family

Slug of the code family, as used by the `family` filter of
`haiqu.list_qec_codes`.

* **Type:**
  str

#### sub\_family

Slug of the sub-family within the code family, `""` when the code has
none.

* **Type:**
  str

#### code\_type

Type of the code: `"css"`, `"stabilizer"`, `"subsystem_css"` or
`"subsystem_stabilizer"`.

* **Type:**
  str

#### n

Number of physical qubits, `None` when not available.

* **Type:**
  int | None

#### k

Number of logical qubits, `None` when not available.

* **Type:**
  int | None

#### d

Code distance. For a code whose X and Z distances differ, a dict
with the keys `"X"` and `"Z"`. `None` when not available.

* **Type:**
  int | dict | None

#### completeness

Completeness tier of the code: `"full"`, `"partial"` or
`"metadata_only"`, as explained in
[Completeness tiers](https://docs.haiqu.ai/reference/run/qec_codes.md#completeness-tiers).

* **Type:**
  str

#### description

Short description of the code, `None` when not available.

* **Type:**
  str | None

#### stabilizers

Stabilizer generators of the code, `None` when not available.

* **Type:**
  dict | None

#### logical\_operators

Logical operators of the code, `None` when not available.

* **Type:**
  dict | None

#### references

Literature references for the code, `None` when not available.
Each reference has the optional fields `key`, `title`, `authors`, `year`,
`doi`, `arxiv`, `url` and `note`.

* **Type:**
  list | None

### *class* haiqu.sdk.schemas.QECCodeListResponseModel

One page of codes of the Haiqu QEC code library, as returned by `haiqu.list_qec_codes`.

#### items

The codes on this page, see [`QECCodeModel`](#haiqu.sdk.schemas.QECCodeModel).

* **Type:**
  list\[[QECCodeModel](#haiqu.sdk.schemas.QECCodeModel)]

#### total

Total number of codes matching the filters, across all pages.

* **Type:**
  int

#### page

Number of this page, as requested.

* **Type:**
  int

#### page\_size

Maximum number of codes per page, as requested.

* **Type:**
  int


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.