From e76713a625bf048125c1df5aee5f9e87da358307 Mon Sep 17 00:00:00 2001 From: Agony Date: Mon, 30 Jun 2025 22:15:01 +0800 Subject: [PATCH 1/2] fix match statement for support Python=3.9 --- qalgo/qda/fundamental.py | 53 +++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/qalgo/qda/fundamental.py b/qalgo/qda/fundamental.py index d3c8ff7..9d2db63 100644 --- a/qalgo/qda/fundamental.py +++ b/qalgo/qda/fundamental.py @@ -108,23 +108,42 @@ def get_mid_eigenstate(self) -> NDArray[np.float64]: print(f"fs = {self.fs}") n = self.row_size - match self.fs: - case 0: - vec = self.get_vector_0b() - case 1: - sol = np.linalg.solve(self.matrix_A, self.vector_b) - sol /= np.linalg.norm(sol) - vec = np.concatenate([np.zeros(n), sol]) - case _ if 0 < self.fs < 1: - Af = self.get_matrix_Af() - b = self.get_vector_0b() - sol = np.linalg.solve(Af, b) - sol /= np.linalg.norm(sol) - vec = sol - case _: - raise RuntimeError( - f"Invalid fs value: {self.fs}. Expected 0 <= fs <= 1." - ) + # match self.fs: + # case 0: + # vec = self.get_vector_0b() + # case 1: + # sol = np.linalg.solve(self.matrix_A, self.vector_b) + # sol /= np.linalg.norm(sol) + # vec = np.concatenate([np.zeros(n), sol]) + # case _ if 0 < self.fs < 1: + # Af = self.get_matrix_Af() + # b = self.get_vector_0b() + # sol = np.linalg.solve(Af, b) + # sol /= np.linalg.norm(sol) + # vec = sol + # case _: + # raise RuntimeError( + # f"Invalid fs value: {self.fs}. Expected 0 <= fs <= 1." + # ) + + # match statement only works for python 3.10+ + # Fix this by using if-else statements + if self.fs == 0: + vec = self.get_vector_0b() + elif self.fs == 1: + sol = np.linalg.solve(self.matrix_A, self.vector_b) + sol /= np.linalg.norm(sol) + vec = np.concatenate([np.zeros(n), sol]) + elif 0 < self.fs < 1: + Af = self.get_matrix_Af() + b = self.get_vector_0b() + sol = np.linalg.solve(Af, b) + sol /= np.linalg.norm(sol) + vec = sol + else: + raise RuntimeError( + f"Invalid fs value: {self.fs}. Expected 0 <= fs <= 1." + ) return np.concatenate([vec, np.zeros(2 * n)], dtype=np.float64) From 2be0d3e49ce8d14e1fcb1461d9d8d3357e874a75 Mon Sep 17 00:00:00 2001 From: Agony Date: Tue, 1 Jul 2025 21:12:34 +0800 Subject: [PATCH 2/2] Update index.md --- docs/index.md | 53 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/docs/index.md b/docs/index.md index 5e4ae24..c403751 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,17 +1,46 @@ -# Welcome to Mklorum +# 欢迎使用 Quantum Algorithm (qalgo) -For full documentation visit [mkdocs.org](https://www.mkdocs.org). +这是 Quantum Algorithm 项目的文档。本项目基于量子虚拟机实现了一些量子算法。 -## Commands +并且本项目还提供了大量用于组成量子算法的组件,例如量子逻辑门,量子算术运算,QRAM,量子态制备,量子傅里叶变换,量子测量等。 -* `mkdocs new [dir-name]` - Create a new project. -* `mkdocs serve` - Start the live-reloading docs server. -* `mkdocs build` - Build the documentation site. -* `mkdocs -h` - Print help message and exit. +## 安装 -## Project layout +### 系统需求 - mkdocs.yml # The configuration file. - docs/ - index.md # The documentation homepage. - ... # Other markdown pages, images and other files. +- 操作系统:Windows、Linux 或 macOS +- Python 版本:3.9 或以上,推荐3.10+ + +### 安装方式 + +```python +pip install qalgo +``` + +## 快速开始 + +```python +import qalgo + +## TODO: + +# 打印结果 +print(result) +``` + +## 算法列表 + +### 已实现 +- 线性求解器 (Quantum Linear System Solver),基于离散绝热定理 + +### 待实现 +- Shor算法 +- 线性求解器 (Quantum Linear System Solver),基于Quantum Walk +- 线性求解器 (Quantum Linear System Solver),基于HHL算法 +- 量子态制备 + + +## 关于 +本项目由 USTC-IAI 量子人工智能团队开发,主要成员为: + +TODO.