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

# QiskitBackend: Compile to Quantum Circuits

> Reference for QiskitBackend, which compiles a b01t IRProgram into a Qiskit QuantumCircuit ready to run on a simulator or real hardware.

`QiskitBackend` translates a b01t `IRProgram` into a Qiskit `QuantumCircuit`. Use it as the final step after building and (optionally) lowering your b01t program. The backend requires `qiskit` to be installed separately — b01t does not depend on it by default.

```bash theme={null}
pip install qiskit
```

***

## QiskitBackend

```python theme={null}
from b01t import QiskitBackend

backend = QiskitBackend()
```

`QiskitBackend` has no constructor arguments. Create one instance and reuse it across multiple programs.

***

## QiskitBackend.emit

```python theme={null}
backend.emit(ir: IRProgram) -> QuantumCircuit
```

Compiles an `IRProgram` into a Qiskit `QuantumCircuit`. Each `QReg` in the program becomes a `QuantumRegister` with the same name and size. Measurement ops add a corresponding `ClassicalRegister` automatically.

<ParamField path="ir" type="IRProgram" required>
  The compiled IR program to emit. Obtain this from `.build()` on a `@parametric` or `@adaptive` function, or from `lower_exact_program()` on an `ExactProgram`.
</ParamField>

**Returns:** a `qiskit.QuantumCircuit` with the same register layout and gate sequence as the input IR.

**Raises:**

* `DSLValidationError` — if `qiskit` is not installed, or if the IR contains an `IfOp` (classical feed-forward is not supported in the current release).
* `DSLValidationError` — if the IR contains a gate name not supported by the backend.

### Supported gates

The backend supports all gates in the b01t exact and parametric gate sets:

`x`, `h`, `z`, `s`, `sdg`, `t`, `tdg`, `rx`, `ry`, `rz`, `cx`, `cz`, `swap`, `cry`, `crz`, `ccx`, `ccz`, `mcx`, `mcz`, `measure`, `measure_all`.

`IfOp` (from `if_then`) is not lowered and raises `DSLValidationError`.

***

## Full example: @coherent to QuantumCircuit

```python theme={null}
from b01t import coherent, QReg, h, cx
from b01t import QiskitBackend
from b01t.core.exact_lowering import lower_exact_program

@coherent
def bell(a: QReg, b: QReg) -> None:
    h(a[0])
    cx(a[0], b[0])

# Step 1: build the exact program
exact = bell.build_exact(("a", 1), ("b", 1))

# Step 2: lower to broad IR
ir = lower_exact_program(exact)

# Step 3: emit to Qiskit
backend = QiskitBackend()
circuit = backend.emit(ir)

print(circuit)
#      ┌───┐
# a_0: ┤ H ├──■──
#      └───┘┌─┴─┐
# b_0: ─────┤ X ├
#            └───┘
```

## Example: @parametric to QuantumCircuit

```python theme={null}
from b01t import parametric, QReg, h, rz, cx
from b01t import QiskitBackend
import math

@parametric
def ansatz(q: QReg) -> None:
    h(q[0])
    rz(math.pi / 4, q[0])
    cx(q[0], q[1])

ir = ansatz.build(("q", 2))
backend = QiskitBackend()
circuit = backend.emit(ir)

print(circuit)
```

## Example: @adaptive with measurement

```python theme={null}
from b01t import adaptive, QReg, h, measure, x
from b01t import QiskitBackend

@adaptive
def measure_and_reset(q: QReg) -> None:
    h(q[0])
    measure(q[0])

ir = measure_and_reset.build(("q", 1))
backend = QiskitBackend()
circuit = backend.emit(ir)
# A ClassicalRegister "c_q_0" is automatically added
```

## Unsupported gate error

If you pass an IR that contains an unrecognised gate name, the backend raises `DSLValidationError`:

```python theme={null}
from b01t.core.types import IRProgram, GateOp, Wire, Effect

bad_ir = IRProgram(
    name="bad",
    effect=Effect.COHERENT,
    regs=[],
    ops=[GateOp(name="unknown_gate", wires=(Wire("q", 0),))],
    is_safe=False,
)

backend = QiskitBackend()
backend.emit(bad_ir)
# DSLValidationError: backend does not support gate 'unknown_gate'
```
