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 always0 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 innoise, 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 probabilityp1q, one of the Pauli operators X, Y and Z, chosen uniformly at random, is applied to the qubit. A logicalidgate is compiled into identity gates on the data qubits of its code block, soidgates are how idle time, for example in a memory experiment, receives noise.p2q: two-qubit depolarizing noise after every two-qubit gate. With probabilityp2q, one of the 15 non-identity two-qubit Pauli operators, chosen uniformly at random, is applied to the two qubits.p_meas: with probabilityp_meas, the outcome of a measurement is flipped. This applies to every measurement, syndrome measurements and data measurements alike.
.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. Thedecoder 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:
"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, withoutcode: 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’sresult() 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 is1. - For a circuit whose ideal outcome is random, for example
hfollowed by a measurement, it is0.0under any noise.decoded_degrees_of_freedomtells the two cases apart: it is the number of logical outcomes, or deterministic combinations of them, that the decoder predicts, and0when it predicts none, in which caselogical_error_rateis0.0by 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.
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
.qecxfile declares no color information for it; - some circuits in which two
cxgates that share a logical qubit follow each other without an error-correction cycle between them, for examplecx(0, 1)followed bycx(0, 2)or bycx(1, 2); - some larger codes, when state preparation is noisy.
- codes whose
- 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 logicalxoncolor_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 innoise, 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_compilejob, or a logical circuit, which is compiled tocodeduring the run. A logical circuit can be given as aQuantumCircuit, which is logged automatically, or as a logged circuit, for example as returned byhaiqu.log. - shots (int) — Number of shots for each circuit, at least 1. Defaults to 1024.
-
noise (QECNoiseModel | dict) — Required. The noise model, as a
QECNoiseModelor 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, socodeis not needed for them; when it is given, it must be that code, orValueErroris 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, orcustom_codefor a file object without a name, which differs for each version of the file. Defaults toNone, 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 toNone, 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 toFalse.
-
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
- 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
codeis given, ifcodeis a library code that is not in the"full"tier, ifcodeis not the code a compiled circuit was compiled to, ifsamplerordecoderis not one of the supported values, ifnoise,shotsorseedhas 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
codeis a path, or a string containing/or\, that does not exist. - TypeError — If
codeis 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
Noneis returned instead.
- ValueError — If a circuit is not compiled and no
Examples
class haiqu.sdk.schemas.QECRunJobModel
Job that samples circuits under noise and decodes the outcomes, as returned byhaiqu.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 withhaiqu.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.- Type: QECNoiseModel
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 incode 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.
- Type: list[QECRunResultModel] | None
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) returnsNone 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.
Noneif the wait was interrupted. - Return type: QECRunResultModel | list[QECRunResultModel] | None
- Raises:
- haiqu.sdk.exceptions.JobFailedError — If the job failed. The message describes the problem,
and the exception’s
logsholds all log messages of the job. - haiqu.sdk.exceptions.JobCancelledError — If the job was cancelled, by the user or because it exceeded the time limit of 30 minutes, which the message then says.
- haiqu.sdk.exceptions.JobFailedError — If the job failed. The message describes the problem,
and the exception’s
class haiqu.sdk.exceptions.JobFailedError(message, *, job_id, logs=None)
Raised by a job’sresult 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’sresult 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 keysp1q, 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