Skip to main content
A QEC run samples circuits that are compiled to a quantum error-correcting code, with qec_compile or during the run, under a noise model. In each shot, the syndrome measured in the error-correction cycles is decoded, and the decoder’s correction is applied to the measured outcome. The run executes asynchronously on the Haiqu cloud as a job, and the result of the job holds, for each circuit, the decoded counts of the circuit’s classical bits and the logical error rate. Problems that are found when the job runs, such as a decoder that cannot decode a circuit, do not raise an error in the call to haiqu.qec_run. They make the job fail, and the job’s result() raises JobFailedError, whose message describes the problem and, for a problem in one circuit, names the circuit and the step that failed. A run job that has not finished after 30 minutes is cancelled, and result then raises JobCancelledError. After an update of the Haiqu cloud, circuits compiled before the update may need to be compiled again: running them then makes the job fail with a message saying so.

End-to-end example

The example compiles a one-qubit circuit whose ideal outcome is always 0 to the code "color_488_d3". It first runs the compiled circuit without noise, as a check, then with noise, and finally sweeps the noise strength. The noisy runs use "tesseract", the most accurate decoder (see Decoders).

Noise model

The noise model, given in noise, applies uniform noise to the compiled circuit, that is to the gates and measurements on the physical qubits. It has three channels, each given by a probability in [0, 1]:
  • p1q: depolarizing noise after every single-qubit gate, including identity gates. With probability p1q, one of the Pauli operators X, Y and Z, chosen uniformly at random, is applied to the qubit. A logical id gate is compiled into identity gates on the data qubits of its code block, so id gates are how idle time, for example in a memory experiment, receives noise.
  • p2q: two-qubit depolarizing noise after every two-qubit gate. With probability p2q, one of the 15 non-identity two-qubit Pauli operators, chosen uniformly at random, is applied to the two qubits.
  • p_meas: with probability p_meas, the outcome of a measurement is flipped. This applies to every measurement, syndrome measurements and data measurements alike.
Reset instructions and barriers are noiseless, and there is no other noise on idle qubits. By default, noise is applied in every part of the compiled circuit, including the circuits that prepare and reset logical qubits. How these are implemented, including whether they are fault-tolerant, is defined by the code’s .qecx file. To restrict noise to selected parts of the compiled circuit, for example to the error-correction cycles, use the toggles argument, as explained in Targeted noise in QEC runs.

Decoders

The decoder turns the syndrome measured in the error-correction cycles into a correction of the outcome. The decoder argument takes one of five values: Chromobius, which "auto" selects for the library’s color codes, is faster than Tesseract but usually reports higher logical error rates on them; across a logical S gate, which a code such as color_488_d3 also uses for a logical x, the gap is larger. Use "tesseract" when accuracy matters. For example, for the noisy run of the End-to-end example:
The decoder that was used, with "auto" resolved to its choice, is reported in the decoder field of each result. A decoder that cannot decode a given circuit makes the job fail: the job’s result() raises JobFailedError, whose message names the decoder and suggests another. "tesseract" can be used with every code. A run job is cancelled after 30 minutes. With "tesseract", a run with many shots, a large code or strong noise can take longer than that, and the job is then only cancelled once the decoding of its shots has finished. Start with few shots to estimate the decoding time. "auto" selects "tesseract" only for a code whose file declares it and neither Chromobius nor PyMatching.

Custom codes

Circuits compiled to a custom code (see Custom codes) are run like any other compiled circuit, without code: they are sampled and decoded with exactly the version of the QECX file they were compiled with, even if the file has been edited since. code also accepts a custom code, in the same forms as haiqu.qec_compile, to compile circuits that are not compiled yet during the run. When code is given together with compiled circuits, it must be the code they were compiled to, or ValueError names both codes. A custom code matches by content, so an edited file does not match the circuits compiled with the earlier version, and neither does the same file in another experiment, since a custom code belongs to the experiment it was stored with. In that case, leave out code. For a custom code, decoder="auto" selects the first decoder its QECX file declares, as for library codes, and "pymatching" when it declares none; the result’s code_slug is the slug of the custom code, for example my_code-3f9a1c2e. PyMatching does not reliably correct errors on color codes, so if your custom code is a color code that declares no decoder, choose the decoder yourself, for example decoder="tesseract".

Reading results

The job’s result() returns one QECRunResultModel for each circuit, or the result alone when the job ran one circuit. Counts. counts holds the decoded counts of the circuit’s classical bits in the logical frame: in each shot, the decoder’s correction is applied to the measured outcome, and the outcome is expressed in the classical bits of the logical circuit that was compiled. The keys are bitstrings in Qiskit’s convention: one space-separated group per classical register, the first register rightmost, and bit 0 rightmost within its group. Logical error rate. logical_error_rate is the fraction of shots in which the decoder’s correction disagrees with the actual flip of at least one logical Z observable of the circuit’s logical qubits. Whether an observable actually flipped is decided by comparing its outcome with its outcome in the same circuit without noise. Therefore:
  • The logical error rate is meaningful only for outcomes that are deterministic without noise. In the End-to-end example, whose ideal outcome is always 0, it equals the fraction of shots whose decoded outcome is 1.
  • For a circuit whose ideal outcome is random, for example h followed by a measurement, it is 0.0 under any noise. decoded_degrees_of_freedom tells the two cases apart: it is the number of logical outcomes, or deterministic combinations of them, that the decoder predicts, and 0 when it predicts none, in which case logical_error_rate is 0.0 by convention and does not measure anything.
  • For entangled outcomes whose combinations are deterministic, for example the parity of the two bits of a Bell pair, the deterministic combinations are checked.
  • For codes with more than one logical qubit per code block, it does not describe the logical outcomes; use the counts instead.
The result also holds shots, the number of shots; decoder, the decoder that was used; and code_slug, the slug of the code the circuit was compiled to. Warnings. A job can succeed with results that need care, for example when the decoder is known to decode the circuit less accurately, or when no logical outcome could be decoded. Such cases are reported as lines starting with WARNING: in the job’s logs, one line per kind of warning, naming the circuits it concerns. Compilation jobs report warnings about the code in the same way.

Current limitations

  • A qubit that is measured cannot currently be measured again, also after a reset: such circuits compile, but the run fails.
  • The "chromobius" decoder currently makes the job fail in these cases; use the slower "tesseract" instead. "pymatching" does not fail on them, but it does not reliably correct errors on color codes.
    • codes whose .qecx file declares no color information for it;
    • some circuits in which two cx gates that share a logical qubit follow each other without an error-correction cycle between them, for example cx(0, 1) followed by cx(0, 2) or by cx(1, 2);
    • some larger codes, when state preparation is noisy.
  • Across a logical S gate, "chromobius" runs but decodes less accurately than on other circuits. This includes gates that a code compiles into S gates, for example a logical x on color_488_d3.
  • The "bposd" decoder, with its current default settings, can decode some single faults on small codes incorrectly, so its logical error rates can overstate the error rate of the code.

Haiqu.qec_run(circuits, shots=1024, *, noise, sampler=‘stim’, decoder=‘auto’, seed=None, code=None, job_name=None, job_description=None, toggles=None, **compilation_options)

Run QEC-compiled circuits under noise and decode the outcomes. Each circuit is sampled under the noise model given in noise, the syndrome measured in its error-correction cycles is decoded, and the decoded outcomes are returned as counts together with a logical error rate. A circuit that is not compiled yet is compiled to code during the run. The run executes asynchronously on the Haiqu cloud as a job. The noise model, the decoders and the results are explained in Noise model, Decoders and Reading results. By default, noise is applied everywhere in the compiled circuit. The toggles argument restricts it to selected parts, as explained in Targeted noise in QEC runs. Problems that are found when the job runs, such as a decoder that cannot decode a circuit, do not raise an error in this call. They make the job fail, and the job’s result() raises JobFailedError, whose message describes the problem.
  • Parameters:
    • circuits (QuantumCircuit | CircuitModel | list *[*QuantumCircuit | CircuitModel ]) — The circuit to run, or a list of them. Each circuit is either QEC-compiled, as returned by the result of a haiqu.qec_compile job, or a logical circuit, which is compiled to code during the run. A logical circuit can be given as a QuantumCircuit, which is logged automatically, or as a logged circuit, for example as returned by haiqu.log.
    • shots (int) — Number of shots for each circuit, at least 1. Defaults to 1024.
    • noise (QECNoiseModel | dict) — Required. The noise model, as a QECNoiseModel or as a dict with the keys "p1q", "p2q" and "p_meas", each a probability in [0, 1]. See Noise model.
    • sampler (str) — The sampler, "stim". Defaults to "stim".
    • decoder (str) — The decoder, one of "auto", "pymatching", "chromobius", "bposd" and "tesseract". "auto" selects the first decoder the code’s QECX file declares, in the order "chromobius", "pymatching", "tesseract", "bposd", and "pymatching" for a code whose file declares none, custom codes included; the library’s color codes get "chromobius". Each decoder has limits: "pymatching" does not reliably correct color codes; "chromobius" needs color information in the code’s file, decodes less accurately across a logical S gate and fails on some circuits; "bposd" is slow and can decode some single faults on small codes incorrectly; "tesseract" is the most accurate but much slower, and its decoding can outlast the job’s 30-minute limit. Defaults to "auto". See Decoders.
    • seed (int | None) — Random seed of the sampling, a non-negative integer. With a seed, the sampling is reproducible: the same circuits, arguments and seed give the same results. Defaults to None, no seed.
    • code (str | QECCodeModel | os.PathLike | BinaryIO | None) — The code to compile logical circuits to during the run, in one of the forms accepted by qec_compile: a library code, given by its slug, e.g. "color_488_d3", or as a code model, or a custom code, given as the path to its QECX file or as a file opened in binary mode. Required when a circuit is not compiled yet. Only library codes in the "full" completeness tier can be used (see Completeness tiers), and the current data of a library code is always fetched from the library, also when a code model is given; a slug that names no code makes the job fail. Compiled circuits run with the code they were compiled to, so code is not needed for them; when it is given, it must be that code, or ValueError is raised. A library code matches by slug and a custom code by content, so an edited file does not match, and neither does the same file in another experiment, since a custom code belongs to its experiment. The results report a custom code by a slug derived from its file name, or custom_code for a file object without a name, which differs for each version of the file. Defaults to None, no code.
    • job_name (str | None) — Name of the run job. Defaults to None, no name.
    • job_description (str | None) — Description of the run job. Defaults to None, no description.
    • toggles (dict | None) — The parts of the compiled circuit that receive noise, as a dict with up to three keys, explained in Targeted noise in QEC runs. A malformed dict makes the job fail. Defaults to None, noise everywhere.
    • **compilation_options — Options for compiling logical circuits during the run, the same as those of qec_compile, given as keyword arguments:
      • ec_cycle_frequency (int): Where error-correction cycles are inserted. Defaults to 1. See Error-correction cycles.
      • variant_selections (dict | None): The variants to use for the code’s operations. Defaults to None, the code’s default variant for every operation. See Variant selections.
      • add_layer_barriers (bool): Whether to place a barrier at every boundary between consecutive logical layers of the compiled circuit. Defaults to False.
      A value of the wrong type makes the job fail. Other keys are not supported. The options are ignored for circuits that are already compiled, which keep the options they were compiled with.
  • Returns: The run job. Its result() waits for the job to finish and returns the decoded results.
  • Return type: QECRunJobModel
  • Raises:
    • ValueError — If a circuit is not compiled and no code is given, if code is a library code that is not in the "full" tier, if code is not the code a compiled circuit was compiled to, if sampler or decoder is not one of the supported values, if noise, shots or seed has an invalid value, or if a custom code’s file is empty. These checks are made before any circuit is logged or any custom code is stored.
    • FileNotFoundError — If code is a path, or a string containing / or \, that does not exist.
    • TypeError — If code is a file opened in text mode, or of a type not listed above.
    • requests.HTTPError — If a custom code’s QECX file is larger than 5 MB (status 413), or a request fails for another reason. In a notebook, an error message is shown and None is returned instead.

Examples

Run without noise, as a check that every shot gives the ideal outcome:
Sweep the noise strength, collecting the jobs and then reading their results:
Compile a logical circuit to a custom code from a QECX file during the run:
Apply noise only in the error-correction cycles:

class haiqu.sdk.schemas.QECRunJobModel

Job that samples circuits under noise and decodes the outcomes, as returned by haiqu.qec_run. Call result() to wait for the job to finish and obtain the decoded results.

id

ID of the job, for retrieving it later with haiqu.get_job.
  • Type: str

status

Status of the job when it was last checked.
  • Type: JobStatus

circuit_ids

IDs of the submitted circuits.
  • Type: list

shots

Number of shots per circuit.
  • Type: int

noise

The noise model of the run.

sampler

The requested sampler.
  • Type: str

decoder

The requested decoder, possibly "auto". The decoder actually used is reported on each result.
  • Type: str

seed

The random seed, None when none was given.
  • Type: int | None

toggles

The selection of where noise is applied, None when noise is applied everywhere. The integer qubit indices of "qubit_gate_overrides" come back as strings.
  • Type: dict | None

code_slug

Slug of the QEC code given in code for compiling circuits during the run, None when none was given.
  • Type: str | None

compilation_options

The compilation options given for compiling circuits during the run.
  • Type: dict

qec_results

One decoded result per circuit, available once the job has finished, None until then.

progress()

Display a progress widget for the job and stream its log messages.

result()

Wait for the job to finish and return the decoded results. The call blocks until the job has finished, checking its status every few seconds, with no timeout. Interrupting the wait (for example with Ctrl+C) returns None without cancelling the job; call result() again to resume waiting. The job can also be retrieved later by its ID with haiqu.get_job.
  • Returns: The result of the circuit when the job ran one circuit, otherwise a list with one result per circuit. None if the wait was interrupted.
  • Return type: QECRunResultModel | list[QECRunResultModel] | None

class haiqu.sdk.exceptions.JobFailedError(message, *, job_id, logs=None)

Raised by a job’s result when the job failed.
  • Parameters:
    • message (str)
    • job_id (str)
    • logs (str | None)

job_id

ID of the job.
  • Type: str

logs

All log messages of the job, of which the exception message shows the error.
  • Type: str | None

class haiqu.sdk.exceptions.JobCancelledError(message, *, job_id, logs=None)

Raised by a job’s result when the job was cancelled, by the user or because it exceeded its time limit.
  • Parameters:
    • message (str)
    • job_id (str)
    • logs (str | None)

job_id

ID of the job.
  • Type: str

logs

All log messages of the job, of which the exception message shows the reason.
  • Type: str | None

class haiqu.sdk.schemas.QECRunResultModel

Decoded result of a QEC run for one circuit. How to read the counts and the logical error rate is explained in Reading results.

counts

Decoded counts of the circuit’s classical bits in the logical frame, keyed by bitstring in Qiskit’s convention: one space-separated group per classical register, the first register rightmost, and bit 0 rightmost within its group.
  • Type: dict[str, int]

logical_error_rate

Fraction of the shots the decoder got wrong. The precise definition is given in Reading results.
  • Type: float

shots

Number of shots.
  • Type: int

decoder

The decoder actually used, with "auto" resolved to its concrete choice.
  • Type: str

code_slug

Slug of the QEC code the circuit was compiled to.
  • Type: str

decoded_degrees_of_freedom

Number of logical outcomes, or deterministic combinations of them, that the decoder predicts. 0 means none could be decoded, and logical_error_rate is then 0.0 by convention. None for results of jobs that ran before this was reported.
  • Type: int | None

class haiqu.sdk.schemas.QECNoiseModel

Uniform noise parameters for a QEC run. A plain dict with the keys p1q, p2q and p_meas is accepted wherever a noise model is. Where each noise channel is applied is explained in Noise model.

p1q

Depolarizing probability of single-qubit gates, in [0, 1].
  • Type: float

p2q

Depolarizing probability of two-qubit gates, in [0, 1].
  • Type: float

p_meas

Probability that a measurement outcome is flipped, in [0, 1].
  • Type: float