Embeddings#
An embedding maps classical features onto the circuit. It also decides how the
DataModule shapes those features. The model class picks the
embedding, so the model class controls input shaping.
from pyqit.core import AmplitudeEmbedding
from pyqit.models import VQCClassifier
model = VQCClassifier(n_qubits=4, encoder=AmplitudeEmbedding)
Available embeddings#
Each page gives the circuit, how many features it takes and how the
DataModule prescales them.
One rotation per qubit, PennyLane's AngleEmbedding. |
|
Features as state amplitudes, PennyLane's AmplitudeEmbedding. |
|
The encoding of Mari et al. (2020): a Hadamard layer, then one RY per wire. |
|
IQP feature map of Havlicek et al. (2019), PennyLane's IQPEmbedding. |
|
The second-order Pauli-Z feature map of Havlicek et al. (2019). |
How prescaling is chosen#
Every embedding carries a prescale tag, and setup() maps the tag’s value
to a shaping function.
"angle_pi"Zero-pads to
n_qubitsfeatures, then multiplies by pi. One feature per wire."amplitude"Zero-pads to
2 ** n_qubitsfeatures, then L2-normalizes each row.
Input wider than the embedding takes raises instead of being truncated.
Prescaling is stateless and runs after normalization, which is stateful and fits on the training split only. Nothing here is fitted, so no information leaks between splits.
Adding an embedding#
Subclass BaseEmbedding, implement forward and set the prescale
tag. __init_subclass__ copies the tag onto a PRESCALE class attribute
that setup() reads, so the tag is the whole registration. Then add the class
name to the list above. See the contributing guide.
Base class for PennyLane circuit embedding wrappers. |