Quantum computing in machine learning (part 3)

Oppdatert: 24. mars 2026

Read Quantum computing in machine learning part 1 here — and part 2 here.

In the setup in the paper the authors use a microwave pulse generator to manipulate the qubit state. And the state we might visualize as being a point on a sphere, as I mentioned. The sphere is called a Bloch sphere. The Schrodinger equation then computes results over time. I mentioned that you can do two things. You can measure. And you can rotate the sphere. That is to say, if you choose a particular qubit state you can use the pulse generator to make it so that the Schrodinger rotates the point around a chosen axis.

Let’s look into how we could write code for this. Code that you could send to a vendor that has a physical lab as we described and who could run the code, rotate the Bloch sphere, that is do the multiplication approximation by a quantum computer. So that you could plug that into your algorithm for updating the model weights of your large language model.

Previously we mentioned that a qubit state is defined as a combination of two parameters governing state 0 and state 1. They are called alpha and beta by convention. The sphere we work on is just a visualization. The state, described with alpha and beta, corresponds to a point on the sphere. Let’s say we want to put the point 45 degrees “north” — up the z axis — and at Greenwich longitude — at x = 1 and y = 0. With some math, that would correspond to some specific alpha and beta values. That would be the qubit state for that point on the sphere. Using a so-called RY gate, that point will by Schrodinger equation start rotating around the Y axis by itself. This is the code (github):

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D


omega = 2 * np.pi                     
t_vals = np.linspace(0, 1, 200)       


alpha0 = np.sqrt((2 + np.sqrt(2)) / 4)
beta0 = np.sqrt((2 - np.sqrt(2)) / 4)


alpha_t = alpha0 * np.exp(-1j * omega * t_vals / 2)
beta_t = beta0 * np.exp(1j * omega * t_vals / 2)


def bloch_coords(alpha, beta):
    x = 2 * np.real(np.conj(alpha) * beta)
    y = 2 * np.imag(np.conj(alpha) * beta)
    z = np.abs(alpha)**2 - np.abs(beta)**2
    return x, y, z


x_vals, y_vals, z_vals = [], [], []
for a, b in zip(alpha_t, beta_t):
    x, y, z = bloch_coords(a, b)
    x_vals.append(x)
    y_vals.append(y)
    z_vals.append(z)


u, v = np.mgrid[0:2*np.pi:60j, 0:np.pi:30j]
xs = np.cos(u) * np.sin(v)
ys = np.sin(u) * np.sin(v)
zs = np.cos(v)


fig = plt.figure(figsize=(8, 8))
ax = fig.add_subplot(111, projection='3d')


ax.plot_surface(xs, ys, zs, color='lightblue', alpha=0.1, linewidth=0)


ax.plot(x_vals, y_vals, z_vals, color='purple', label='Qubit state trajectory')
ax.scatter(x_vals[0], y_vals[0], z_vals[0], color='green', s=50, label='Start (t=0)')
ax.scatter(x_vals[-1], y_vals[-1], z_vals[-1], color='blue', s=50, label='End (t=1)')


ax.set_title(r"$alpha = sqrt{frac{2 + sqrt{2}}{4}}, quad beta = sqrt{frac{2 - sqrt{2}}{4}}$")

ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
ax.legend()
ax.set_box_aspect([1, 1, 1])

plt.show()

which outputs

The blue and (occluded) green dot represent the start and the point after a full rotation. The violet line illustrates the trajectory on the qubit state sphere.

If you wanted to run this on physical hardware, let Schrodinger do the computation for you, you could write the same in qiskit, and submit it to a vendor that accepts qiskit code. IBM could run the code on an Eagle quantum computer for example. The vendor would then use the microwave pulse generator to do the “RY gate”, i.e. configure the qubit state and it’s energy so that Schrodinger would rotate the point around the Y axis. The code looks like this (github):

from qiskit import QuantumCircuit, transpile
from qiskit_aer import Aer
from qiskit.visualization import plot_bloch_multivector
import matplotlib.pyplot as plt
import numpy as np


qc = QuantumCircuit(1)
qc.ry(np.pi / 4, 0)  


backend = Aer.get_backend('statevector_simulator')
transpiled_qc = transpile(qc, backend)
job = backend.run(transpiled_qc)
result = job.result()
statevector = result.get_statevector()


fig = plot_bloch_multivector(statevector)


plt.title(r"$alpha = sqrt{frac{2 + sqrt{2}}{4}}, quad beta = sqrt{frac{2 - sqrt{2}}{4}}$")

plt.show()

That about wraps it up for now. You’ve followed me from a Lora substitute for fine-tuning a large language model, to writing a small relevant snippet that you could run on an actual quantum machine today. Thanks for your time!


Quantum computing in machine learning (part 3) was originally published in Compendium on Medium, where people are continuing the conversation by highlighting and responding to this story.