用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/ZhangXin8069/PyQCU --skill cann命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | cann |
| description | pyqcu.cann 目录的完整生成 skill:Ascend NPU 的 torch 兼容层,将复数算子分解为实/虚部;含 force_use_npu 全局标志与 einsum 组合分解算法。 |
Torch compatibility layer for Ascend NPU. All Python code in PyQCU imports pyqcu.cann as _torch instead of using torch directly.
Ascend NPU does not natively support complex tensors. This module wraps torch operations, decomposing complex ops into real/imaginary parts on NPU while passing through directly on CUDA/CPU.
device.type != 'npu' and force_use_npu=False): delegates to torch.* unchangeddevice.type == 'npu' or force_use_npu=True): decomposes complex ops into real/imaginary partspyqcu.cann.force_use_npu = True — force NPU code paths on CPU for testing without NPU hardware. This affects only the cann layer; some modules (dslash/_wilson.py, tools/_define.py, tools/_multigrid.py, smear/_stout.py) also have their own per-module force_use_npu flag for deeper NPU workarounds (e.g., tensor dimension limits).
Always use these instead of raw torch calls anywhere complex tensors might run on NPU:
| Category | Functions | Notes |
|---|---|---|
| Math | abs, vdot, norm, sqrt, matmul | vdot → conj-flatten-sum; norm → abs-then-norm; sqrt → CPU fallback |
| Reduction/shape | roll, allclose, einsum | roll → roll real/imag separately; allclose → check real + imag separately |
| Creation | zeros, zeros_like, randn, randn_like, eye | Creates real parts then combines to complex |
| Linear algebra | linalg_qr | Falls back to CPU on NPU for complex inputs |
torchtorch.linalg.det — used in lattice.check_su3() for SU(3) determinant check. No equivalent in _torch; works on NPU for real matrices.torch.matrix_exp — used in lattice.generate_gauge_field() for exponential map.General N-operand complex einsum uses a combinatorial approach. For Z = Π(a_k + i·b_k):
eye(n, m, ...) — creates real identity then casts to complex dtype on NPUzeros(*args, ...) / randn(*args, ...) — creates separate real + imag tensors and combinessqrt(input) — sends complex input to CPU, computes sqrt, sends back (NPU doesn't support complex sqrt)matmul(input, other) — uses explicit (ac-bd) + i(ad+bc) decompositionqcu/ — placeholder stub (empty PASS file), no implementation yet.
The content of each subdirectory below was produced with Claude Code assistance. Per repo convention, the complete skill that generates that content is reproduced verbatim below (source: the subdirectory's own CLAUDE.md), so the full knowledge is available directly at this level.
qcu/ (source: qcu/CLAUDE.md)Placeholder for the Ascend NPU C++ Cython bridge. No implementation yet.
Contains only an empty PASS file as a directory placeholder.