Transpiler API Reference
The transpiler optimises circuits before execution by running a configurable sequence of transformation passes.
Built-in Passes
| Pass | Description |
|---|---|
RemoveRedundantGates |
Cancels adjacent self-inverse gates (e.g. H-H, X-X). |
MergeRotations |
Merges consecutive rotations around the same axis. |
Usage
from hlquantum.transpiler import transpile, Transpiler
from hlquantum.transpiler import RemoveRedundantGates, MergeRotations
# Quick — use the default pass set
optimised = transpile(circuit)
# Custom — pick your own passes
t = Transpiler(passes=[RemoveRedundantGates(), MergeRotations()])
optimised = t.run(circuit)
Writing a Custom Pass
Subclass TranspilationPass and implement the run(circuit) method:
from hlquantum.transpiler import TranspilationPass
class MyPass(TranspilationPass):
def run(self, circuit):
# Return a new, optimised Circuit
...
Optimization and transpilation logic.
MergeRotations
Bases: TranspilationPass
Merges consecutive rotation gates on the same qubit.
Source code in hlquantum/transpiler.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
RemoveRedundantGates
Bases: TranspilationPass
Removes consecutive gates that cancel out (e.g., H H).
Source code in hlquantum/transpiler.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
TranspilationPass
Bases: ABC
Base class for a transpilation pass.
Source code in hlquantum/transpiler.py
11 12 13 14 15 16 17 | |
run(circuit)
abstractmethod
Run the pass on the circuit.
Source code in hlquantum/transpiler.py
14 15 16 17 | |
Transpiler
Orchestrates transpilation passes.
Source code in hlquantum/transpiler.py
84 85 86 87 88 89 90 91 92 93 94 95 | |
transpile(circuit)
Apply passes to the circuit.
Source code in hlquantum/transpiler.py
90 91 92 93 94 95 | |
transpile(circuit)
Transpile using default transpiler.
Source code in hlquantum/transpiler.py
101 102 103 | |