Skip to content

Contest solution for 2024第三届“量旋杯”大湾区量子计算挑战营

License

Notifications You must be signed in to change notification settings

Kahsolt/VQLS-JiuZhang-PennyLane

Repository files navigation

VQLS-JiuZhang-PennyLane

Contest solution for 2024第三届“量旋杯”大湾区量子计算挑战营

Contest page: https://quantum-challenge.spinq.cn/competitionDetail/profession
Team Name: 啊这是什么吃一口

⚠ Due to the contest problem case is rather simple, the implemented method is actually the VALA (arXiv:1909.03898), NOT the more complicated VQLS (arXiv:1909.05820) 😈; but we do carefully explain the differences between these methods in METHOD.md

Problem

[原题 - 出自《九章算术·方程·8》]
今有卖牛二、羊五,以买一十三豕,有余钱一千;
卖牛三、豕三,以买九羊,钱适足;
卖六羊,八豕,以买五牛,钱不足六百。
问:牛、羊、豕价各几何?
答曰:牛价一千二百,羊价五百,豕价三百。

[线性方程组]
 2 * x + 5 * y - 13 * z = 1000
 3 * x - 9 * y +  3 * z = 0
-5 * x + 6 * y +  8 * z = -600
解:牛 x = 1200, 羊 y = 500, 豕 z = 300

赛题本质为给定的线性方程组求解,其同解方程组为:

$$ \begin{array}{ll} \begin{bmatrix} 2 & 5 & -13 \\ 3 & -9 & 3 \\ -5 & 6 & 8 \\ \end{bmatrix} \begin{bmatrix} 12 \\ 5 \\ 3 \\ \end{bmatrix} = \begin{bmatrix} 10 \\ 0 \\ -6 \\ \end{bmatrix} \end{array} $$

已知的 量子线性求解器 Quantum Linear-system Solver 算法流派有:

  • HHL / QPE-based
    • 需要矩阵指数化 $ e^{iA\frac{t0}{2^k}} $
    • 受控旋转部分 $ CR $ 角度难以确定
    • 精度由qubit位数 / 线路宽度决定
  • Adiabatic-based: 绝热演化
    • 需要虚时演化算子 $ e^{-iHt} $,或一阶近似后使用 BlockEncoding
    • 精度由迭代次数 / 线路深度决定
  • VQLS: 变分线路 ⭐
    • 浅线路,需要变分训练
    • 精度由 ansatz 结构和参数质量决定
  • qubo-based VQE (思路提供者: 铅笔芯奇)
    • 解向量中的每个元素 $ x_i $ 转为二进制形式 $ \overline{b_k \dots b_1 b_0} $ ,由一组量子比特表达 (BasisEncoding)
    • 原方程转换为 QUBO 问题,构造哈密顿量求最小值,取得最小值时即解出各 $ b_k $
    • 优点: 若每个 $ x_i $ 表达为二进制时都是有穷串,则此方法可给出 精确解 (此时损失函数应取到最小值0)
    • 缺点: 需要先验地知道每个 $ x_i $ 的值域,以确定用多少比特表达
  • Grover-based (?)

考虑到赛题对所用量子门和线路深度的限制,VQLS 方法应该是唯一正解 🤔

Quick start

  • pip install pennylane
  • run submit.ipynb with jupyter
    • run python run_VALA.py if you wanna reproduce the training
    • read METHOD.md for the theoretical story
  • run submit_ising.ipynb with jupyter, we owe the raw idea to @铅笔芯奇
    • I must admit that VALA method is more like a simulator toy, while the ising method is more practical & promising on real-chip and the future!

Example of run_VALA.py run:

run_VALA.png

refenrence


by Armit 2024/6/13

About

Contest solution for 2024第三届“量旋杯”大湾区量子计算挑战营

Topics

Resources

License

Stars

Watchers

Forks