| !3111 merge release-note-0.12 into master Project modernization Created-by: dsdsdshe Commit-by: dsdsdshe Merged-by: dsdsdshe Description: Project modernization See merge request: mindspore/mindquantum!3111 | 7 months ago |
| Project modernization cleanup | 7 months ago |
| !2842 merge chip-class-3 into master feat: add QPU base class for real hardware execution Created-by: dsdsdshe Commit-by: dsdsdshe Merged-by: dsdsdshe Description: ## Context & Objective As MindQuantum evolves from a simulation framework to a full-stack quantum computing platform, there is a critical need to standardize how quantum algorithms are dispatched to physical quantum hardware (or hardware-like backends). This PR introduces the mindquantum.device.QPU abstract base class. The core design philosophy is to **minimize the implementation burden on hardware vendors**. By simply implementing a single sampling() primitive, hardware providers instantly unlock MindQuantum's advanced hybrid quantum-classical features, including expectation value evaluation and gradient calculations. ## Key Changes 1. **The QPU Abstract Base Class (mindquantum/device/qpu.py)** * Defined the sampling(circuit, pr, shots, seed) abstract method as the sole requirement for subclass implementations. * Added _sampling_batch to allow vendors to optimize execution via job batching. 2. **Shot-based Expectation Values** * Implemented get_expectation() to estimate expectation values using measurement shots rather than exact state vectors. * Automatically handles basis rotations for hardware-measurable Pauli sums (constructed via QubitOperator). 3. **Hardware-ready Gradient Estimation** * Implemented get_expectation_with_grad() which returns a GradOpsWrapper compatible with existing MindSpore/VQA workflows. * **Parameter-Shift Rule (PSR):** Supported out-of-the-box (pr_shift=True) for compatible gates (RX, RY, RZ, U3, SWAPalpha, etc.). * **Finite Differences:** Automatically acts as a fallback for unsupported/controlled gates or when pr_shift=False. 4. **Safety & Validation Mechanisms** * Added strict type/value checking to ensure parameter resolvers contain strictly real numbers (rejecting complex numbers that simulators might tolerate but hardware cannot). * Fails fast if users pass circuits containing premature measurement gates into VQA workloads. 5. **Documentation & Optimization** * Added complete Chinese and English Sphinx documentation stubs for the new API. * Optimized imports in mindquantum/device/chip.py (lazy loading) to prevent large module import costs when merely importing mindquantum.device. 6. **Comprehensive Testing (tests/st/test_device/test_qpu.py)** * Created robust test doubles (_SamplingOnlyQPU, _ExactExpectationQPU) to validate the mathematical correctness of gradients and expectations against the exact Simulator backends. * Validated seed decorrelation, parameter-shift rule accuracy, no-grad flag handling, and fail-fast exceptions. ## Architecture / Design Intent This implementation intentionally mirrors the user-facing workflow of mindquantum.simulator.Simulator. This allows users to prototype VQA algorithms on local simulators and seamlessly swap the backend to a real QPU object with zero changes to their training loop. *Example for Hardware Providers:* ``python from mindquantum.device import QPU class MyVendorQPU(QPU): def sampling(self, circuit, pr=None, shots=1, seed=None): # Translate MindQuantum circuit to hardware IR # Dispatch to cloud/hardware API # Return MeasureResult pass `` ## Checklist - [x] Code follows project style guidelines - [x] Python and English API documentation added - [x] Unit/ST tests written and passing - [x] Fallback logic (Finite Difference) handles complex circuits securely - [x] All PR inputs and parameters validated safely See merge request: mindspore/mindquantum!2842 | 8 months ago |
| fix: resolve failure to clean build directory with --clean-all - Fixes the issue where bash build.sh --clean-all could not correctly resolve the temporary build path, leaving stale cache artifacts. - Introduces get_python_build_platform in _build/backend.py and mindquantum_config to correctly resolve the platform string. - Refactors cache cleaning logic in the build scripts to reliably locate and remove the build directory. | 7 months ago |
| feat: add ENABLE_CUQUANTUM build option to decouple cuQuantum from CUDA - Introduce ENABLE_CUQUANTUM CMake option and --cuquantum build flag - Wrap cuQuantum includes and template instantiations with MQ_HAS_CUQUANTUM macro - Update simulator documentation and Python availability checks to reflect the new explicit build requirement | 6 months ago |
| feat: add ENABLE_CUQUANTUM build option to decouple cuQuantum from CUDA - Introduce ENABLE_CUQUANTUM CMake option and --cuquantum build flag - Wrap cuQuantum includes and template instantiations with MQ_HAS_CUQUANTUM macro - Update simulator documentation and Python availability checks to reflect the new explicit build requirement | 6 months ago |
| feat: add ENABLE_CUQUANTUM build option to decouple cuQuantum from CUDA - Introduce ENABLE_CUQUANTUM CMake option and --cuquantum build flag - Wrap cuQuantum includes and template instantiations with MQ_HAS_CUQUANTUM macro - Update simulator documentation and Python availability checks to reflect the new explicit build requirement | 6 months ago |
| style: migrate Python linting and formatting to Ruff - Replaces black, flake8, isort, pyupgrade, and pydocstyle with Ruff to improve linting and formatting speed and simplify the toolchain. - Consolidates pre-commit configurations by removing redundant Gitee and format-specific hooks. - Updates documentation and tool configurations (pyproject.toml, setup.cfg) for Ruff integration. - Removes legacy dependencies (importlib-metadata, typing_extensions) for Python versions older than 3.8. | 7 months ago |
| !3124 merge bug-fix into master fix(qaia): 修复 LSB 指数符号反转和 USB 初始化失效问题 Created-by: dsdsdshe Commit-by: dsdsdshe Merged-by: dsdsdshe Description: #### 问题背景 QSB 模块(TSB/USB/LSB)实现了论文 *Quantized Simulated Bifurcation for the Ising Model*(IEEE NANO 2023)中的三种量化模拟分叉算法。经测试发现 USB 和 LSB 在所有场景下均显著劣于 DSB(能量差一个数量级),无法复现论文中的性能优势。 #### 根因分析 **Bug 1:LSB 对数缩放因子指数符号反转** 论文 Eq. 12 要求对位置变量 x 做对数量化后,以右移(即 2^(l_x),l_x ≤ 0)衰减小值的贡献。但实现中使用了 np.ldexp(ones, -l_x),等价于 2^(-l_x),对 |x| < 1 的值产生了**放大**而非衰减效果。 示例:|x| = 0.125 → l_x = -3 → 代码计算 2^3 = 8(放大 8 倍),论文期望 2^(-3) = 0.125(缩小到 1/8)。 此外,当 x = 0 时 log2(0) 产生 -inf,缺少零值保护。 **Bug 2:USB 因基类初始化范围过小而完全失效** SB 基类将 x 初始化在 [-0.01, 0.01] 范围内。DSB 使用 sign(x) 不受幅度影响,但 USB 的均匀量化函数会将这些小值全部映射为 0,导致哈密顿动力学中的耦合驱动项完全消失,系统无法正常演化。 #### 修复方案 | Bug | 修复位置 | 修改内容 | |-----|---------|---------| | LSB 指数符号 | QSB.py LSB.update() | ldexp(ones, -l_x) → ldexp(ones, l_x);增加 x=0 保护 | | USB 初始化 | QSB.py USB.__init__() | 用户未提供 x 时,将自动初始化范围从 [-0.01, 0.01] 扩大到 [-0.1, 0.1] | USB 的修复仅在 USB.__init__ 中针对性处理,不修改 SB 基类,不影响 ASB/BSB/DSB/TSB 等其他算法。 #### 修复效果 **LSB(全连接图 MaxCut, N=512):** | 指标 | 修复前 | 修复后 | |------|-------|-------| | E_min | -577 | -6225 | | E_mean | -16 | -6168 | | TTS (p=99%) | ∞ | 27.5s(DSB: 56.9s,**2× 加速**)| **USB(全连接图 MaxCut, N=256, threshold=10):** | 指标 | 修复前 | 修复后 | |------|-------|-------| | E_min | -318 | -2174 | | TTS (p=99%) | ∞ | 1.97s(DSB: 5.36s,**2.7× 加速**)| 修复后两种算法均可复现论文中的性能优势。 #### 测试变更 LSB 测试原先由于bug导致放宽了参数,现恢复为标准设置: | 参数 | 修复前 | 修复后 | |------|-------|-------| | n_iter | N_ITER * 10(3000) | N_ITER(300) | | tolerance | TOLERANCE * 3(15%) | TOLERANCE(5%) | | h 测试 | 跳过(None) | 启用(h_test) | | threshold | 5 | 8 | #### 影响范围 - mindquantum/algorithm/qaia/QSB.py:LSB、USB - tests/st/test_algorithm/test_qaia/test_qaia.py:CPU 测试 - tests/st/test_algorithm/test_qaia/test_qaia_gpu.py:GPU 测试 - 不涉及 SB 基类、ASB、BSB、DSB、TSB 及其他 QAIA 算法 See merge request: mindspore/mindquantum!3124 | 6 months ago |
| fix: resolve failure to clean build directory with --clean-all - Fixes the issue where bash build.sh --clean-all could not correctly resolve the temporary build path, leaving stale cache artifacts. - Introduces get_python_build_platform in _build/backend.py and mindquantum_config to correctly resolve the platform string. - Refactors cache cleaning logic in the build scripts to reliably locate and remove the build directory. | 7 months ago |
| feat: add ENABLE_CUQUANTUM build option to decouple cuQuantum from CUDA - Introduce ENABLE_CUQUANTUM CMake option and --cuquantum build flag - Wrap cuQuantum includes and template instantiations with MQ_HAS_CUQUANTUM macro - Update simulator documentation and Python availability checks to reflect the new explicit build requirement | 6 months ago |
| fix skills | 6 months ago |
| !3124 merge bug-fix into master fix(qaia): 修复 LSB 指数符号反转和 USB 初始化失效问题 Created-by: dsdsdshe Commit-by: dsdsdshe Merged-by: dsdsdshe Description: #### 问题背景 QSB 模块(TSB/USB/LSB)实现了论文 *Quantized Simulated Bifurcation for the Ising Model*(IEEE NANO 2023)中的三种量化模拟分叉算法。经测试发现 USB 和 LSB 在所有场景下均显著劣于 DSB(能量差一个数量级),无法复现论文中的性能优势。 #### 根因分析 **Bug 1:LSB 对数缩放因子指数符号反转** 论文 Eq. 12 要求对位置变量 x 做对数量化后,以右移(即 2^(l_x),l_x ≤ 0)衰减小值的贡献。但实现中使用了 np.ldexp(ones, -l_x),等价于 2^(-l_x),对 |x| < 1 的值产生了**放大**而非衰减效果。 示例:|x| = 0.125 → l_x = -3 → 代码计算 2^3 = 8(放大 8 倍),论文期望 2^(-3) = 0.125(缩小到 1/8)。 此外,当 x = 0 时 log2(0) 产生 -inf,缺少零值保护。 **Bug 2:USB 因基类初始化范围过小而完全失效** SB 基类将 x 初始化在 [-0.01, 0.01] 范围内。DSB 使用 sign(x) 不受幅度影响,但 USB 的均匀量化函数会将这些小值全部映射为 0,导致哈密顿动力学中的耦合驱动项完全消失,系统无法正常演化。 #### 修复方案 | Bug | 修复位置 | 修改内容 | |-----|---------|---------| | LSB 指数符号 | QSB.py LSB.update() | ldexp(ones, -l_x) → ldexp(ones, l_x);增加 x=0 保护 | | USB 初始化 | QSB.py USB.__init__() | 用户未提供 x 时,将自动初始化范围从 [-0.01, 0.01] 扩大到 [-0.1, 0.1] | USB 的修复仅在 USB.__init__ 中针对性处理,不修改 SB 基类,不影响 ASB/BSB/DSB/TSB 等其他算法。 #### 修复效果 **LSB(全连接图 MaxCut, N=512):** | 指标 | 修复前 | 修复后 | |------|-------|-------| | E_min | -577 | -6225 | | E_mean | -16 | -6168 | | TTS (p=99%) | ∞ | 27.5s(DSB: 56.9s,**2× 加速**)| **USB(全连接图 MaxCut, N=256, threshold=10):** | 指标 | 修复前 | 修复后 | |------|-------|-------| | E_min | -318 | -2174 | | TTS (p=99%) | ∞ | 1.97s(DSB: 5.36s,**2.7× 加速**)| 修复后两种算法均可复现论文中的性能优势。 #### 测试变更 LSB 测试原先由于bug导致放宽了参数,现恢复为标准设置: | 参数 | 修复前 | 修复后 | |------|-------|-------| | n_iter | N_ITER * 10(3000) | N_ITER(300) | | tolerance | TOLERANCE * 3(15%) | TOLERANCE(5%) | | h 测试 | 跳过(None) | 启用(h_test) | | threshold | 5 | 8 | #### 影响范围 - mindquantum/algorithm/qaia/QSB.py:LSB、USB - tests/st/test_algorithm/test_qaia/test_qaia.py:CPU 测试 - tests/st/test_algorithm/test_qaia/test_qaia_gpu.py:GPU 测试 - 不涉及 SB 基类、ASB、BSB、DSB、TSB 及其他 QAIA 算法 See merge request: mindspore/mindquantum!3124 | 6 months ago |
| feat: add ENABLE_CUQUANTUM build option to decouple cuQuantum from CUDA - Introduce ENABLE_CUQUANTUM CMake option and --cuquantum build flag - Wrap cuQuantum includes and template instantiations with MQ_HAS_CUQUANTUM macro - Update simulator documentation and Python availability checks to reflect the new explicit build requirement | 6 months ago |
| remove symengine | 3 years ago |
| split template | 3 years ago |
| [CMAKE] Improve apply_patches() function in case of a Git repository | 3 years ago |
| fix(qaia): fix LSB sign-inverted exponent and USB dead initialization LSB: The logarithmic scale factor used 2^(-l_x) instead of 2^(l_x), amplifying small position values rather than attenuating them as specified in the paper (Eq. 12, right-shift operation). Also guard against log2(0). USB: The base class initializes x in [-0.01, 0.01], which USB's uniform quantization maps entirely to zero, eliminating the driving force. Override with [-0.1, 0.1] when no user-provided x is given. Update LSB tests to remove workarounds (10x iterations, 3x tolerance) that were masking the bug. Ref: Zhang & Han, "Quantized Simulated Bifurcation for the Ising Model", IEEE NANO 2023, doi:10.1109/NANO58406.2023.10231308 | 7 months ago |
| Refactor MPS compiler and optimize gradient ops in mqsim - Refactor MPSCompiler in ccsrc/include/simulator/mps/compiler/mps_compiler.h to use MPSCompileState for better state management and modularity. - Optimize gate matrix generation in MPS compiler for standard 1-qubit and 2-qubit gates. - Refactor get_expectation_with_grad in mindquantum/simulator/mqsim.py by extracting helper functions for input preparation and result formatting. - Update .whitelizard.txt to reflect changes in mqsim.py. | 10 months ago |
| docs:IGNORE ALL .DS_Store FILES IN MACOS Added **/.DS_Store to the gitignore file. | 3 years ago |
| style: migrate Python linting and formatting to Ruff - Replaces black, flake8, isort, pyupgrade, and pydocstyle with Ruff to improve linting and formatting speed and simplify the toolchain. - Consolidates pre-commit configurations by removing redundant Gitee and format-specific hooks. - Updates documentation and tool configurations (pyproject.toml, setup.cfg) for Ruff integration. - Removes legacy dependencies (importlib-metadata, typing_extensions) for Python versions older than 3.8. | 7 months ago |
| Project modernization cleanup | 7 months ago |
| add rgignore | 8 months ago |
| !2842 merge chip-class-3 into master feat: add QPU base class for real hardware execution Created-by: dsdsdshe Commit-by: dsdsdshe Merged-by: dsdsdshe Description: ## Context & Objective As MindQuantum evolves from a simulation framework to a full-stack quantum computing platform, there is a critical need to standardize how quantum algorithms are dispatched to physical quantum hardware (or hardware-like backends). This PR introduces the mindquantum.device.QPU abstract base class. The core design philosophy is to **minimize the implementation burden on hardware vendors**. By simply implementing a single sampling() primitive, hardware providers instantly unlock MindQuantum's advanced hybrid quantum-classical features, including expectation value evaluation and gradient calculations. ## Key Changes 1. **The QPU Abstract Base Class (mindquantum/device/qpu.py)** * Defined the sampling(circuit, pr, shots, seed) abstract method as the sole requirement for subclass implementations. * Added _sampling_batch to allow vendors to optimize execution via job batching. 2. **Shot-based Expectation Values** * Implemented get_expectation() to estimate expectation values using measurement shots rather than exact state vectors. * Automatically handles basis rotations for hardware-measurable Pauli sums (constructed via QubitOperator). 3. **Hardware-ready Gradient Estimation** * Implemented get_expectation_with_grad() which returns a GradOpsWrapper compatible with existing MindSpore/VQA workflows. * **Parameter-Shift Rule (PSR):** Supported out-of-the-box (pr_shift=True) for compatible gates (RX, RY, RZ, U3, SWAPalpha, etc.). * **Finite Differences:** Automatically acts as a fallback for unsupported/controlled gates or when pr_shift=False. 4. **Safety & Validation Mechanisms** * Added strict type/value checking to ensure parameter resolvers contain strictly real numbers (rejecting complex numbers that simulators might tolerate but hardware cannot). * Fails fast if users pass circuits containing premature measurement gates into VQA workloads. 5. **Documentation & Optimization** * Added complete Chinese and English Sphinx documentation stubs for the new API. * Optimized imports in mindquantum/device/chip.py (lazy loading) to prevent large module import costs when merely importing mindquantum.device. 6. **Comprehensive Testing (tests/st/test_device/test_qpu.py)** * Created robust test doubles (_SamplingOnlyQPU, _ExactExpectationQPU) to validate the mathematical correctness of gradients and expectations against the exact Simulator backends. * Validated seed decorrelation, parameter-shift rule accuracy, no-grad flag handling, and fail-fast exceptions. ## Architecture / Design Intent This implementation intentionally mirrors the user-facing workflow of mindquantum.simulator.Simulator. This allows users to prototype VQA algorithms on local simulators and seamlessly swap the backend to a real QPU object with zero changes to their training loop. *Example for Hardware Providers:* ``python from mindquantum.device import QPU class MyVendorQPU(QPU): def sampling(self, circuit, pr=None, shots=1, seed=None): # Translate MindQuantum circuit to hardware IR # Dispatch to cloud/hardware API # Return MeasureResult pass `` ## Checklist - [x] Code follows project style guidelines - [x] Python and English API documentation added - [x] Unit/ST tests written and passing - [x] Fallback logic (Finite Difference) handles complex circuits securely - [x] All PR inputs and parameters validated safely See merge request: mindspore/mindquantum!2842 | 8 months ago |
| style: migrate Python linting and formatting to Ruff - Replaces black, flake8, isort, pyupgrade, and pydocstyle with Ruff to improve linting and formatting speed and simplify the toolchain. - Consolidates pre-commit configurations by removing redundant Gitee and format-specific hooks. - Updates documentation and tool configurations (pyproject.toml, setup.cfg) for Ruff integration. - Removes legacy dependencies (importlib-metadata, typing_extensions) for Python versions older than 3.8. | 7 months ago |
| fix wall | 3 years ago |
| update CODEOWNERS | 8 months ago |
| Project modernization cleanup | 7 months ago |
| Project modernization cleanup | 7 months ago |
| [CI] Update cpplint suppression files | 4 years ago |
| Revert "feat(security): Enhance binary security through hardening" This reverts commit b8d593715dc7f114b4eec56808d9d9a86c29f465. | 1 year ago |
| remove experimental | 3 years ago |
| init mindquantum | 5 years ago |
| Fix list of file in source and binary wheel - Add MANIFEST.in file - Remove unneeded sections from pyproject.toml and setup.cfg | 4 years ago |
| HiQ 5.0 | 4 years ago |
| refactor: update MindSpore context initialization to use set_device - Replaced device_target argument in set_context with explicit ms.set_device("CPU") calls across framework operations, tests, and documentation. | 6 months ago |
| refactor: update MindSpore context initialization to use set_device - Replaced device_target argument in set_context with explicit ms.set_device("CPU") calls across framework operations, tests, and documentation. | 6 months ago |
| add 0.12 release note | 8 months ago |
| add 0.12 release note | 8 months ago |
| change version to 0.12.0 | 1 year ago |
| fix: resolve failure to clean build directory with --clean-all - Fixes the issue where bash build.sh --clean-all could not correctly resolve the temporary build path, leaving stale cache artifacts. - Introduces get_python_build_platform in _build/backend.py and mindquantum_config to correctly resolve the platform string. - Refactors cache cleaning logic in the build scripts to reliably locate and remove the build directory. | 7 months ago |
| fix: resolve failure to clean build directory with --clean-all - Fixes the issue where bash build.sh --clean-all could not correctly resolve the temporary build path, leaving stale cache artifacts. - Introduces get_python_build_platform in _build/backend.py and mindquantum_config to correctly resolve the platform string. - Refactors cache cleaning logic in the build scripts to reliably locate and remove the build directory. | 7 months ago |
| feat: add ENABLE_CUQUANTUM build option to decouple cuQuantum from CUDA - Introduce ENABLE_CUQUANTUM CMake option and --cuquantum build flag - Wrap cuQuantum includes and template instantiations with MQ_HAS_CUQUANTUM macro - Update simulator documentation and Python availability checks to reflect the new explicit build requirement | 6 months ago |
| Revert "feat(security): Enhance binary security through hardening" This reverts commit b8d593715dc7f114b4eec56808d9d9a86c29f465. | 1 year ago |
| Revert "feat(security): Enhance binary security through hardening" This reverts commit b8d593715dc7f114b4eec56808d9d9a86c29f465. | 1 year ago |
| feat: add ENABLE_CUQUANTUM build option to decouple cuQuantum from CUDA - Introduce ENABLE_CUQUANTUM CMake option and --cuquantum build flag - Wrap cuQuantum includes and template instantiations with MQ_HAS_CUQUANTUM macro - Update simulator documentation and Python availability checks to reflect the new explicit build requirement | 6 months ago |
| refactor: update MindSpore context initialization to use set_device - Replaced device_target argument in set_context with explicit ms.set_device("CPU") calls across framework operations, tests, and documentation. | 6 months ago |
| refactor: update MindSpore context initialization to use set_device - Replaced device_target argument in set_context with explicit ms.set_device("CPU") calls across framework operations, tests, and documentation. | 6 months ago |
| fix(qaia): fix LSB sign-inverted exponent and USB dead initialization LSB: The logarithmic scale factor used 2^(-l_x) instead of 2^(l_x), amplifying small position values rather than attenuating them as specified in the paper (Eq. 12, right-shift operation). Also guard against log2(0). USB: The base class initializes x in [-0.01, 0.01], which USB's uniform quantization maps entirely to zero, eliminating the driving force. Override with [-0.1, 0.1] when no user-provided x is given. Update LSB tests to remove workarounds (10x iterations, 3x tolerance) that were masking the bug. Ref: Zhang & Han, "Quantized Simulated Bifurcation for the Ising Model", IEEE NANO 2023, doi:10.1109/NANO58406.2023.10231308 | 7 months ago |
| Project modernization cleanup | 7 months ago |
| Project modernization cleanup | 7 months ago |
| Project modernization cleanup | 7 months ago |