QSL - Quantum Search Language: Full-stack quantum computing framework with simulator, algorithms (QFT/Shor/QAOA/VQE), QML, hardware backends (IBM/AWS), AI scientist, and self-evolving meta-system
Project description
QSL — 量子搜索语言
用一句话描述你想找什么,剩下的交给量子计算。
这是什么?
一个 Python 库,让你用日常的布尔表达式描述搜索条件,自动在量子计算机(或本地模拟器)上找到答案。
传统做法:手写量子电路,理解 H 门、CNOT 门、相位翻转……
QSL 的做法:写x0 & ~x1,然后等结果。
5 秒看懂
from qsl import QSLProgram, compile_and_run
# 我想找:3 个变量中,哪些赋值同时满足这三个条件?
program = QSLProgram(
name="3-SAT",
n_qubits=3,
premises=[
"x0 | ~x1", # x0 为真,或者 x1 为假
"x1 | x2", # x1 为真,或者 x2 为真
"~x0 | ~x2", # x0 为假,或者 x2 为假
],
shots=10
)
result = compile_and_run(program)
print(result.get_solutions())
输出:
[3, 4] # 即二进制 011 和 100 —— 这两个就是答案
就这么简单。不需要懂量子力学。
两种运行模式
| 模式 | 说明 | 需要什么 |
|---|---|---|
| 本地模拟 | 在你的电脑上模拟量子计算 | 零依赖,纯 Python |
| 真实硬件 | 连接 IBM 量子计算机跑真任务 | pip install qsl-quantum[ibm] + IBM 账号 |
# 模式 1:本地模拟(默认)
compiler = QSLCompiler(backend="simulator")
result = compiler.compile_and_run(program)
# 模式 2:IBM 真实量子芯片
compiler = QSLCompiler(backend="ibm", backend_options={"token": "your_token"})
result = compiler.compile_and_run(program)
还能更简单 —— DSL 文本语法
不想写 Python?用配置文件式的文本语法:
program "图着色" {
qubits: 3
premise {
x0 ^ x1 # 相邻顶点不能同色
x1 ^ x2
}
main {
algorithm: grover
shots: 10
}
}
from qsl import parse_qsl, compile_and_run
source = open("problem.qsl").read()
program = parse_qsl(source)
result = compile_and_run(program)
它能做什么?
用布尔表达式描述任意搜索约束,QSL 自动找到所有满足条件的解:
| 实际问题 | 布尔表达式 | 说明 |
|---|---|---|
| SAT 求解 | x0 | ~x1 |
逻辑可满足性 |
| 图着色 | x0 ^ x1 |
相邻顶点不同色 |
| 约束满足 | x0 & ~x1 & x2 |
精确约束条件 |
| 组合优化 | (x0&x1) | (x2&x3) |
任意布尔函数 |
支持全部逻辑运算符: &(与) |(或) ^(异或) ~(非) ()(括号)
安装
pip install qsl-quantum
核心部分零外部依赖。只有在使用 IBM 真实硬件时才需要
qiskit。
为什么用 Grover 算法?
| 经典搜索 | QSL(Grover) | |
|---|---|---|
| 搜索 N 个可能 | 查 N 次 | 查约 √N 次 |
| 256 个状态 | 最多查 256 次 | 约 16 次 |
| 1024 个状态 | 最多查 1024 次 | 约 32 次 |
| 百万级 | 不可行 | 约 1000 次 |
搜索空间越大,优势越明显。这是量子计算为数不多已被数学证明比经典算法快的场景。
项目结构
qsl/
├── core/ 量子态、布尔解析、Grover 算法
├── compiler/ 编译器 + DSL 解析器
├── backends/ 模拟器后端 + IBM 后端
└── utils/ 异常体系、输入验证
tests/ 123 个测试用例
运行测试
pip install -e ".[dev]"
pytest tests/ -v # 123 passed
作者
宋梓铭 · Gitee · 15011462616@163.com
许可证
MIT — 随意使用、修改、分发。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qsl_quantum-0.2.0.tar.gz.
File metadata
- Download URL: qsl_quantum-0.2.0.tar.gz
- Upload date:
- Size: 131.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ceeed192249f6b746808478cd2472fb893648316699c0b70de9c13b9ca44849b
|
|
| MD5 |
363844ff33383ba5ffacdc8ccc12d3cf
|
|
| BLAKE2b-256 |
f3d3b3803fac42dc2aed4edc9ad51b9d0bfb550cb6660ae167c347fe513fc97d
|
File details
Details for the file qsl_quantum-0.2.0-py3-none-any.whl.
File metadata
- Download URL: qsl_quantum-0.2.0-py3-none-any.whl
- Upload date:
- Size: 118.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d5bd332ad3fc4a9902440c370630a95b70bc18d2c8f48fc95a4fbfbb652fdb6
|
|
| MD5 |
5ce50344804c65047dcefc36105616f8
|
|
| BLAKE2b-256 |
887eae930a743c19f0e287d037cda58c8f682f1294fc4f12853530f24b0e7c4a
|