bosing: 微波波形生成器

简介

bosing 是一个用于生成微波波形的 Python 库, 通过类似 HTML DOM 的结构编排波形, 既可直接用于生成简单的波形序列, 也可作为 qiskit 等量子门 线路优化器的后端, 生成复杂的微波波形. 目前实现的功能有:

  • 脉冲编排: 通过 Stack 等控制波形时序

  • 自定义波形: 通过 Interp 自定义插值波形

安装

$ pip install bosing

从源码安装

  1. 安装 Rustup

  2. 安装 Python 3.9+

  3. Clone 本项目并安装
    $ git clone https://github.com/kahojyun/Bosing.git
    $ cd Bosing
    $ pip install .
    

注意

小心

项目中所有相位 (phase) 的单位均为周期数, 比如 \(1\) 代表弧度制的 \(2\pi\), \(0.5\) 代表 \(\pi\).

示例

 1"""An example of using bosing to generate a pulse sequence."""
 2
 3import numpy as np
 4from matplotlib import pyplot as plt
 5from scipy.interpolate import make_interp_spline
 6
 7from bosing import (
 8    Absolute,
 9    Barrier,
10    Channel,
11    Grid,
12    Hann,
13    Interp,
14    Play,
15    Repeat,
16    ShiftPhase,
17    Stack,
18    generate_waveforms,
19)
20
21if __name__ == "__main__":
22    length = 100000
23    channels = {
24        "xy0": Channel(0, 2e9, length),
25        "xy1": Channel(0, 2e9, length),
26        "u0": Channel(0, 2e9, length),
27        "u1": Channel(0, 2e9, length),
28        "m0": Channel(0, 2e9, length),
29    }
30    halfcos = np.sin(np.linspace(0, np.pi, 10))
31    interp = make_interp_spline(np.linspace(-0.5, 0.5, 10), halfcos)
32    shapes = {
33        "hann": Hann(),
34        "halfcos": Interp(interp.t, interp.c, interp.k),
35    }
36
37    measure = Absolute(
38        Play("m0", "hann", 0.1, 30e-9, plateau=1e-6, frequency=123e6),
39        Play("m0", "hann", 0.15, 30e-9, plateau=1e-6, frequency=-233e6),
40    )
41    c01 = Stack(
42        Play("u0", None, 0.5, 50e-9),
43        Play("u1", None, 0.5, 50e-9),
44        ShiftPhase("xy0", 0.1),
45        ShiftPhase("xy1", 0.2),
46    )
47    x0 = Play("xy0", "hann", 0.3, 50e-9, drag_coef=5e-10)
48    x1 = Play("xy1", "hann", 0.4, 100e-9, drag_coef=3e-10)
49    x_group = Grid(
50        Stack(x0, alignment="center"),
51        Stack(x1, alignment="center"),
52    )
53
54    schedule = Stack(duration=50e-6).with_children(
55        Repeat(
56            Stack(
57                x_group,
58                Barrier(duration=15e-9),
59                c01,
60            ),
61            count=200,
62            spacing=15e-9,
63        ),
64        Barrier(duration=15e-9),
65        measure,
66        Barrier(duration=15e-9),
67    )
68
69    schedule.plot(channels=["xy0", "u0", "m0"], max_depth=6)
70    plt.show()
71
72    result = generate_waveforms(channels, shapes, schedule, time_tolerance=1e-13)
73
74    t = np.arange(length) / 2e9
75    plt.plot(t, result["xy0"][0])
76    plt.plot(t, result["xy0"][1])
77    plt.plot(t, result["xy1"][0])
78    plt.plot(t, result["xy1"][1])
79    plt.plot(t, result["u1"][0])
80    plt.plot(t, result["u1"][1])
81    plt.plot(t, result["m0"][0])
82    plt.plot(t, result["m0"][1])
83    plt.show()

索引