> ## 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.

# Hybrid Program

### Hybrid programs

A hybrid program is an ordered pipeline of layers describing how your circuits are processed and
run. Build one with `HybridProgram` and execute it with [`haiqu.flow`](/reference/run/flow). See the
[Hybrid programs overview](/hybrid/overview) for a conceptual introduction.

```python theme={null}
from haiqu.sdk.hybrid import HybridProgram, layers
```

#### HybridProgram(layers, schema\_version=1)

A pipeline of layers, validated on construction. It starts with an `InputLayer` and ends with a
`DeviceLayer`.

* **Parameters:**
  * **layers** (*list* \*\[\**Layer* *]*) -- The ordered list of layers that make up the program.
  * **schema\_version** (*int*) -- The wire-format version. Defaults to `1`.
* **Raises:**
  ValueError -- if the layers do not satisfy the structural rules below.

The list of layers must satisfy:

* It is not empty.
* The first layer is an `InputLayer`, and the last is a `DeviceLayer`.
* There is exactly one `InputLayer` and exactly one `DeviceLayer` (neither appears in the middle).
* It contains at most one grouped mitigation layer — `EstimatorLayer` or `DistributionMitigationLayer`
  — as the two are mutually exclusive.

#### Example

```python theme={null}
>>> from haiqu.sdk.hybrid import HybridProgram, layers
>>> program = HybridProgram(layers=[
...     layers.InputLayer(),
...     layers.TranspilationLayer(optimization_level=3),
...     layers.DeviceLayer(device_id="aer_simulator"),
... ])
```

### Layers

A layer is a single processing step in a program. Construct layers from the `layers` module and pass
them to `HybridProgram`.

### Required layers

#### layers.InputLayer()

The program's entry point. Every program starts with one. Takes no parameters.

#### layers.DeviceLayer(device\_id, options={})

Runs the circuits on a backend; every program ends with one.

* **Parameters:**
  * **device\_id** (*str*) -- The backend to run on (e.g. `"aer_simulator"`, `"fake_torino"`).
  * **options** (*dict*) -- Backend-specific settings (e.g. credentials). Defaults to `{}`.

### Circuit processing

#### layers.TranspilationLayer(optimization\_level=None)

Transpile the circuits for the target backend.

* **Parameters:**
  * **optimization\_level** (*int* *|* *None*) -- The optimization effort, `0`–`3`. Leave unset (`None`) for the backend default.

#### layers.PackingLayer(pack\_size=None)

Pack several copies of a circuit into one run to use spare device qubits.

* **Parameters:**
  * **pack\_size** (*int* *|* *None*) -- The number of copies to pack; must be `>= 2`. Leave unset (`None`) to pick a value automatically from the circuit and device sizes.

### Error mitigation (grouped)

A program uses at most one of these. Choose `EstimatorLayer` when you measure observables
(expectation values), and `DistributionMitigationLayer` when you read the raw measurement
distribution. The flags turn individual techniques on or off.

#### layers.EstimatorLayer(mitigation\_enabled=True, advanced\_mitigation=True, readout\_mitigation=True, noise\_tailoring=False, dynamical\_decoupling=True, readout\_mitigation\_options={})

Measure observable expectation values with error mitigation. Use this when the job supplies
observables.

* **Parameters:**
  * **mitigation\_enabled** (*bool*) -- Master switch for error mitigation. Defaults to `True`.
  * **advanced\_mitigation** (*bool*) -- Toggle advanced mitigation. Defaults to `True`.
  * **readout\_mitigation** (*bool*) -- Toggle readout error mitigation. Defaults to `True`.
  * **noise\_tailoring** (*bool*) -- Toggle noise tailoring via Pauli twirling. Defaults to `False`.
  * **dynamical\_decoupling** (*bool*) -- Toggle dynamical decoupling. Defaults to `True`.
  * **readout\_mitigation\_options** (*dict*) -- Extra settings for readout mitigation. Defaults to `{}`.

#### layers.DistributionMitigationLayer(mitigation\_enabled=True, advanced\_mitigation=True, readout\_mitigation=True, noise\_tailoring=False, dynamical\_decoupling=True, readout\_mitigation\_options={})

Mitigate errors on the raw measured probability distribution. Use this when the job reads
measurement outcomes (no observables). Takes the same parameters as `EstimatorLayer`.

### Individual processing steps

Finer-grained steps for building a custom pipeline by hand instead of the grouped error-mitigation
layers above. Each takes no parameters.

#### layers.ObservableSplitLayer()

Split a task with several observables into one task per observable.

#### layers.NoiseTailoringLayer()

Tailor device noise with Pauli twirling.

#### layers.DynamicalDecouplingLayer()

Suppress idle-qubit errors with dynamical-decoupling sequences.

#### layers.AdvancedReadoutMitigationLayer()

Advanced measurement (readout) error mitigation.

#### layers.QWCComputeLayer()

Compute observable expectation values from grouped commuting measurements.
