PART 02 / Intermediate

Putting data into a circuit

How does an ordinary feature become a quantum state?

Published lesson

What you will learn

Encode one feature as an angle and calculate a simple quantum-kernel similarity.

Before you begin: A qubit, without the mystery

The data still starts on your laptop

Suppose you have a single numerical feature, such as a normalised sensor reading. Before a circuit can use it, you need a rule that turns that number into operations. This is encoding. It is not a free doorway through which a spreadsheet becomes quantum. The rule determines what differences between observations the circuit can notice, and the work needed to prepare each input belongs in your experiment budget.

One number, one rotation

A gentle first choice is an angle. Starting from zero, a Y rotation by x prepares amplitudes cos(x/2) and sin(x/2). Similar angles tend to prepare similar states in a neighbourhood, but angles wrap around. If your original feature ranges from zero to a million, sending it straight into a rotation without thinking about scale will fold unrelated values together. Decide what distances in the original data should mean before choosing the map.

A kernel asks about resemblance

Instead of asking a circuit to make the whole prediction, ask how much two encoded states overlap. Square the magnitude of that overlap and you obtain a similarity value called a fidelity kernel. A classical learning algorithm can then use a table of these similarities. In our one-qubit example the entire calculation fits in a cosine. That makes it a good lesson and a deliberately unconvincing claim of computational advantage.

Keep the train-test boundary visible

If you scale data, learn the scaling rule from the training set and apply that rule to validation and test data. Looking at all the data first can leak information across the boundary. The same discipline applies whether the features travel into a neural network, a support vector machine or a quantum circuit. The unfamiliar representation does not remove the familiar obligations of a good machine-learning experiment.

SEE THE RELATIONSHIPS

From structure to behavior.

Quantum kernel: a labelled conceptual diagram
Figure 2.1 · Quantum kernel. Original educational diagram; synthetic, not a measured result.
The reasoning pathTraining data only then Fit scaling and encode then Estimate state overlaps then Train a classical predictor1. Training data only2. Fit scaling and encode3. Estimate state overlaps4. Train a classical predictor
A learning flow for this part. Follow the assumptions through to an observable result.

MAKE THE IDEA PRECISE

The mathematics.

K(x, z) = |⟨ψ(x)|ψ(z)⟩|² = cos²((x − z)/2)
Symbols and units
SymbolMeaning
x, zFeature angles, in radians
KSimilarity between encoded states, between 0 and 1
ψ(x)State prepared by a Y rotation of angle x

Build the equation, step by step

  1. Take the dot product of the two real state vectors: cos(x/2)cos(z/2) + sin(x/2)sin(z/2).
  2. Use the cosine difference identity to simplify the overlap to cos((x−z)/2).
  3. Square its magnitude. Equal encodings have K=1; a separation of π gives K=0 for this map.

WORK THROUGH THE NUMBERS

Worked example

Compare 0 with 0, π/2 and π radians. The similarities are 1, 0.5 and 0. This is a chosen representation of similarity, not a fact about which original observations share a label.

A small Python experiment.

Python 3 · Standard library only · Synthetic educational example. Run this in your own notebook or a local file.

from math import cos, pi
def kernel(x, z):
    return cos((x-z)/2)**2
print([round(kernel(0, z), 3) for z in [0, pi/2, pi]])

Expected output

[1.0, 0.5, 0.0]

Change one quantity, predict the result, and then run the code again. Explain any difference before adding complexity.

Test your understanding.

Try it: Evaluate the kernel between 0 and 2π. Explain why a large numerical separation can still produce maximum similarity.

Self-check: Does using a quantum kernel make the whole learning pipeline quantum?

No. Preparing and measuring states can be one part of a hybrid workflow. Data handling, kernel storage and the downstream learner may all be classical. Report the entire pipeline and compare it with a suitable classical representation under the same evaluation rules.

Where this model stops: The selected one-qubit map is efficiently classically computable. This example demonstrates encoding and similarity, not a speedup.

A research question: Keep one assumption fixed and change another. What observation would make you revise your explanation?

Record evidence in your mastery worksheet →

Read with the original sources.

These readings support the concepts and deeper investigation. The worked numbers and illustrations above are teaching examples.

Complete source register →

Where next?