Control: Driving a Qubit
Shape a time-dependent control field to steer a qubit between states — the basis of pulse-level gate design and optimal control.
A Gaussian control pulse
import qalgora
from qalgora import operators
import numpy as np
amp, t0, sigma = 1.0, 25.0, 5.0 # pulse area knob, center time, width
T = 50.0 # total evolution time
def gaussian(t):
return amp * np.exp(-((t - t0) ** 2) / (2 * sigma ** 2))
# drive along X with a shaped envelope
H = operators.scalar(gaussian) * operators.spin.x(0)
Simulating the driven evolution
The initial state ground is the qubit in |0⟩ — supply your own state object here
(illustrative fragment).
# ground: qubit in |0> (construct from your state API)
result = qalgora.evolve(
H, dimensions={0: 2},
schedule=qalgora.Schedule(steps=np.linspace(0, T, 500), parameters=["t"]),
initial_state=ground,
observables=[operators.spin.z(0)],
)
# tune amp/sigma so <Z> flips from +1 to -1: a calibrated X gate
Toward optimal control
Couple a differentiable integrator with gradient descent to learn pulse shapes that realize a
target gate with maximum fidelity.
控制:受驱量子比特
通过含时控制场引导量子比特在态之间跃迁——这是脉冲级门设计与最优控制的基础。
Gaussian 控制脉冲
import qalgora
from qalgora import operators
import numpy as np
amp, t0, sigma = 1.0, 25.0, 5.0 # 脉冲面积 中心时刻 宽度
T = 50.0 # 总演化时间
def gaussian(t):
return amp * np.exp(-((t - t0) ** 2) / (2 * sigma ** 2))
# drive along X with a shaped envelope
H = operators.scalar(gaussian) * operators.spin.x(0)
模拟受驱演化
初态 ground 即量子比特处于 |0⟩——此处为示例片段,需自行构造对应的态对象。
# ground 量子比特处于 |0>(用你的态 API 构造)
result = qalgora.evolve(
H, dimensions={0: 2},
schedule=qalgora.Schedule(steps=np.linspace(0, T, 500), parameters=["t"]),
initial_state=ground,
observables=[operators.spin.z(0)],
)
# tune amp/sigma so <Z> flips from +1 to -1: a calibrated X gate
迈向最优控制
将可微积分器与梯度下降相结合,学习能以最高保真度实现目标门的脉冲形状。