Layers & Pipelines API Reference
HLQuantum borrows the layer / sequential pattern from ML frameworks to let you compose complex quantum circuits from reusable building blocks.
Key Concepts
| Class | Purpose |
|---|---|
Layer |
Abstract base — every layer implements build() → Circuit. |
Sequential |
Container that chains layers and composes their circuits. |
CircuitLayer |
Wraps an existing Circuit as a layer. |
QFTLayer |
Layer wrapping the QFT algorithm. |
GroverLayer |
Layer wrapping Grover's search. |
RealAmplitudes |
RY + CX variational ansatz (full / linear entanglement). |
HardwareEfficientAnsatz |
RX + RY + CX hardware-efficient ansatz. |
QuantumMultiHeadAttention |
Quantum multi-head attention mechanism. |
QuantumTransformerBlock |
Attention + variational feed-forward block. |
Quick Example
from hlquantum.layers import (
Sequential, CircuitLayer, QFTLayer, GroverLayer, RealAmplitudes,
)
from hlquantum.circuit import Circuit
# Wrap a hand-crafted circuit
init = CircuitLayer(Circuit(4).h(0).cx(0, 1))
# Stack layers into a pipeline
model = Sequential([
init,
QFTLayer(num_qubits=4),
GroverLayer(num_qubits=4, target_states=["1010"]),
RealAmplitudes(num_qubits=4, reps=2),
])
# Compile to a single circuit
circuit = model.build()
print(circuit)
Layers can also be composed with the | (pipe) operator:
from hlquantum.layers.core import CircuitLayer
a = CircuitLayer(Circuit(2).h(0))
b = CircuitLayer(Circuit(2).cx(0, 1))
combined = a | b # returns a Sequential
circuit = combined.build()
Base & Container
hlquantum.layers.base ~~~~~~~~~~~~~~~~~~~~~
Base classes for quantum layers and modular circuit building.
Layer
Bases: ABC
Abstract base class for a quantum layer.
Source code in hlquantum/layers/base.py
16 17 18 19 20 21 22 23 24 25 26 27 28 | |
__or__(other)
Pipe layers together.
Source code in hlquantum/layers/base.py
24 25 26 27 28 | |
build(input_qubits=None)
abstractmethod
Build the module and return a QuantumCircuit.
Source code in hlquantum/layers/base.py
19 20 21 22 | |
Sequential
Bases: Layer
A container for a sequence of quantum layers.
Source code in hlquantum/layers/base.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
Core Layers
hlquantum.layers.core ~~~~~~~~~~~~~~~~~~~~~
Core layer implementations.
CircuitLayer
Bases: Layer
Wraps an existing QuantumCircuit as a layer.
Source code in hlquantum/layers/core.py
14 15 16 17 18 19 20 21 22 23 | |
Functional Layers
hlquantum.layers.functional ~~~~~~~~~~~~~~~~~~~~~~~~~~~
Functional layers wrapping standard algorithms.
GroverLayer
Bases: Layer
A layer implementing Grover's search.
Source code in hlquantum/layers/functional.py
16 17 18 19 20 21 22 23 24 25 26 | |
QFTLayer
Bases: Layer
A layer implementing Quantum Fourier Transform.
Source code in hlquantum/layers/functional.py
29 30 31 32 33 34 35 36 37 | |
Variational Templates
hlquantum.layers.templates ~~~~~~~~~~~~~~~~~~~~~~~~~~
Predefined quantum templates and variational ansätze.
HardwareEfficientAnsatz
Bases: Layer
A general hardware-efficient ansatz with RX, RY, RZ and CX.
Source code in hlquantum/layers/templates.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
RealAmplitudes
Bases: Layer
An ansatz consisting of single-qubit RY rotations and CX entanglers.
Source code in hlquantum/layers/templates.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
Attention & Transformer Layers
hlquantum.layers.attention ~~~~~~~~~~~~~~~~~~~~~~~~~
Quantum Transformers and Attention Mechanisms.
QuantumMultiHeadAttention
Bases: Layer
A Quantum Multi-Head Attention layer.
This layer encodes classical data into quantum states and applies a parameterized circuit to compute attention-like features.
Source code in hlquantum/layers/attention.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
QuantumTransformerBlock
Bases: Layer
A high-level block containing Quantum Attention and Feed-Forward layers.
Source code in hlquantum/layers/attention.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |