mcpField
Q
Qiskit Gym MCP Server

Qiskit Gym MCP Server

本地服务
github.com科研与教育453 周前更新

关于 Qiskit Gym MCP Server

Qiskit Gym MCP 服务基于强化学习进行量子电路综合,支持训练模型并合成置换、线性函数与 Clifford 电路。它适合研究人员和量子编译开发者,可使用 IBM 硬件拓扑预设,并支持后台训练。

主要功能

  1. 01训练 PPO 或 AlphaZero 强化学习模型
  2. 02支持置换、线性函数与 Clifford 三类综合
  3. 03提供 IBM 硬件与网格等拓扑预设
  4. 04离线获取 IBM 假后端的精确耦合图
  5. 05后台训练并支持状态轮询与模型保存

适用场景

  1. 01为 3x3 网格拓扑训练 Clifford 电路综合模型
  2. 02基于 IBM Nighthawk 的子拓扑批量训练
  3. 03在后台训练模型时继续处理其他任务

MCP 相关

该项目是 MCP 服务,通过环境、训练、综合、模型与耦合图等工具向 MCP 客户端暴露量子电路综合能力。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"qiskit-qiskit-gym": {
"command": "uvx",
"args": [
"qiskit-gym-mcp-server"
]
}
}
}
启动命令uvx qiskit-gym-mcp-server

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
pypiqiskit-gym-mcp-server0.4.2

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

Qiskit Gym MCP 服务

MCP Registry

基于 Model Context Protocol(MCP)的服务,使用 qiskit-gym 提供基于强化学习的量子电路合成能力。

功能

  • 训练 RL 模型:训练强化学习 Agent,以合成最优量子电路
  • 后台训练:在后台线程中运行长时间训练,并支持轮询
  • 三种合成类型:
    • 置换:以最少的 SWAP 门进行量子比特路由
    • 线性函数:为线性布尔函数合成 CNOT
    • Clifford:使用自定义门集合成最优 Clifford 电路
  • 硬件支持:提供 IBM Heron、Nighthawk 以及常见网格/线性拓扑的预设
  • 精确的 IBM 拓扑:访问 IBM Quantum fake 后端的精确耦合映射(离线使用,无需凭据)
  • 子拓扑提取:从硬件耦合映射中提取连通子图,用于针对性训练
  • 模型持久化:保存、加载和管理训练好的模型
  • TensorBoard 集成:使用 TensorBoard 监控训练进度

安装

pip install qiskit-gym-mcp-server

或从源代码安装:

git clone https://github.com/Qiskit/mcp-servers
cd mcp-servers/qiskit-gym-mcp-server
pip install -e .

快速开始

Claude Desktop 配置

添加到 Claude Desktop 配置文件(~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "qiskit-gym": {
      "command": "qiskit-gym-mcp-server"
    }
  }
}
示例工作流
User: "Train a model to synthesize Clifford circuits on a 3x3 grid topology"

AI Agent:
1. create_clifford_env_tool(num_qubits=9, preset="grid_3x3")  # -> env_id
2. start_training_tool(env_id, algorithm="ppo", num_iterations=200)  # -> session_id, model_id
3. save_model_tool(session_id, model_name="clifford_3x3_v1")  # -> saved to disk
User: "Train on all 6-qubit subtopologies from IBM Nighthawk"

AI Agent:
1. extract_subtopologies_tool(preset="ibm_nighthawk", num_qubits=6)  # -> list of subtopologies
2. For each subtopology:
   - create_clifford_env_tool(num_qubits=6, coupling_map=subtopology["edges"])
   - start_training_tool(env_id, algorithm="ppo", num_iterations=100)
   - save_model_tool(session_id, model_name=f"nighthawk_6q_{i}")
User: "Train a model using the exact topology of IBM Fez backend"

AI Agent:
1. get_fake_backend_coupling_map_tool(backend_name="fake_fez")  # -> exact 156-qubit Heron topology
2. extract_subtopologies_tool(edges=coupling_map["edges"], num_qubits=5)  # -> 5-qubit subtopologies
3. For each subtopology:
   - create_permutation_env_tool(num_qubits=5, coupling_map=subtopology["edges"])
   - start_training_tool(env_id, algorithm="ppo", num_iterations=100)
User: "Train a model in the background so I can do other things"

AI Agent:
1. create_clifford_env_tool(num_qubits=6, preset="grid_2x3")  # -> env_id
2. start_training_tool(env_id, algorithm="ppo", num_iterations=500, background=True)  # -> session_id (returns immediately)
3. (User can now ask other questions or the agent can do other work)
4. get_training_status_tool(session_id)  # -> check progress
5. wait_for_training_tool(session_id, timeout=600)  # -> blocks until complete, returns model_id
6. save_model_tool(session_id, model_name="clifford_6q_v1")

工具参考

环境管理
工具说明
create_permutation_env_tool创建用于 SWAP 路由的 PermutationGym
create_linear_function_env_tool创建用于 CNOT 合成的 LinearFunctionGym
create_clifford_env_tool创建使用自定义门集的 CliffordGym
list_environments_tool列出活动环境
get_environment_info_tool获取环境详情
delete_environment_tool移除环境
训练
工具说明
start_training_tool开始 RL 训练(PPO 或 AlphaZero),支持 background=True
wait_for_training_tool等待后台训练完成
batch_train_environments_tool训练多个环境
get_training_status_tool获取训练进度和指标
stop_training_tool停止训练会话
list_training_sessions_tool列出所有训练会话
合成
工具说明
synthesize_permutation_tool生成最优 SWAP 电路
synthesize_linear_function_tool生成最优 CNOT 电路
synthesize_clifford_tool生成最优 Clifford 电路
模型管理
工具说明
save_model_tool将训练好的模型保存到磁盘
load_model_tool从磁盘加载模型
list_saved_models_tool列出磁盘上的模型
list_loaded_models_tool列出内存中的模型
delete_model_tool删除模型
get_model_info_tool获取模型详情
耦合映射
工具说明
create_coupling_map_tool创建自定义耦合映射
extract_subtopologies_tool从硬件中提取 N 量子比特子拓扑
list_subtopology_shapes_tool列出子拓扑形状(线形、网格等)
get_fake_backend_coupling_map_tool获取 fake IBM 后端的精确拓扑(无需凭据)
list_available_fake_backends_tool列出所有可用于离线拓扑访问的 fake 后端
实用工具
工具描述
generate_random_permutation_tool生成随机置换,用于测试
generate_random_linear_function_tool生成随机线性函数,用于测试
generate_random_clifford_tool生成随机 Clifford 元素,用于测试
convert_qpy_to_qasm3_tool将 QPY 电路转换为易读的 QASM3
convert_qasm3_to_qpy_tool将 QASM3 电路转换为 QPY 格式

硬件预设

预设量子比特拓扑描述
ibm_heron_r1133重六边形IBM Heron r1 处理器
ibm_heron_r2156重六边形IBM Heron r2 处理器
ibm_nighthawk12010x12 网格IBM Nighthawk(相比 Heron,深度提升 600%)
grid_3x39网格3x3 方形网格
grid_5x525网格5x5 方形网格
linear_55线形5 量子比特线性链
linear_1010线形10 量子比特线性链

资源

URI描述
qiskit-gym://workflows从这里开始 - 分步工作流和快速入门指南
qiskit-gym://presets/coupling-maps可用的硬件预设
qiskit-gym://algorithmsPPO、AlphaZero 文档
qiskit-gym://policiesBasicPolicy、Conv1dPolicy 文档
qiskit-gym://environments环境类型文档
qiskit-gym://training/sessions活跃的训练会话
qiskit-gym://models已加载的模型
qiskit-gym://server/config服务配置

配置

环境变量:

# Model storage directory (default: ~/.qiskit-gym/models)
QISKIT_GYM_MODEL_DIR=~/.qiskit-gym/models

# TensorBoard logs (default: ~/.qiskit-gym/runs)
QISKIT_GYM_TENSORBOARD_DIR=~/.qiskit-gym/runs

# Training limits (0 = no limit, default)
# QISKIT_GYM_MAX_ITERATIONS=10000  # Uncomment to set a limit
QISKIT_GYM_MAX_QUBITS=15
QISKIT_GYM_MAX_SEARCHES=10000

开发

# Install with dev dependencies
pip install -e ".[all]"

# Run tests
./run_tests.sh

# Or manually
uv run pytest tests/ -v
uv run ruff check src tests
uv run mypy src

依赖项

许可证

Apache 2.0 - 详情请参阅 LICENSE。

贡献

贡献指南请参阅 CONTRIBUTING.md。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。