diff --git a/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.BSB.rst b/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.BSB.rst index b7656af00bc0ff664844b61b972590aaa0ea7137..b1a9fa5ef03c9556cddca5901d6c3fb0a5d1336c 100644 --- a/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.BSB.rst +++ b/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.BSB.rst @@ -11,6 +11,9 @@ mindquantum.algorithm.qaia.BSB 为了内存效率,输入数组 'x' 不会被复制,并且会在优化过程中被原地修改。 如果需要保留原始数据,请使用 `x.copy()` 传入副本。 + 当使用backend='gpu-int8'时,请注意该后端可能在稠密图或具有连续系数的图上表现不佳。 + 在这些情况下,可以尝试调整参数或考虑使用'cpu-float32'或'gpu-float16'后端。 + 参数: - **J** (Union[numpy.array, scipy.sparse.spmatrix]) - 耦合矩阵,维度为 :math:`(N \times N)`。 - **h** (numpy.array) - 外场强度,维度为 :math:`(N, )`。 diff --git a/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.DSB.rst b/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.DSB.rst index b8e6b03d1822845c6ab9ffdae5210a8bfd7246f2..b0e0096c2fa5bd2cdb3b328afe1b8bca049bc063 100644 --- a/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.DSB.rst +++ b/docs/api_python/algorithm/qaia/mindquantum.algorithm.qaia.DSB.rst @@ -11,6 +11,9 @@ mindquantum.algorithm.qaia.DSB 为了内存效率,输入数组 'x' 不会被复制,并且会在优化过程中被原地修改。 如果需要保留原始数据,请使用 `x.copy()` 传入副本。 + 当使用backend='gpu-int8'时,请注意该后端可能在稠密图或具有连续系数的图上表现不佳。 + 在这些情况下,可以尝试调整参数或考虑使用'cpu-float32'或'gpu-float16'后端。 + 参数: - **J** (Union[numpy.array, scipy.sparse.spmatrix]) - 耦合矩阵,维度为 :math:`(N \times N)`。 - **h** (numpy.array) - 外场强度,维度为 :math:`(N, )`。 diff --git a/mindquantum/algorithm/qaia/SB.py b/mindquantum/algorithm/qaia/SB.py index a97409a134708bf4d8c94a365e5f2dcebb6c1089..d18376b8185d0c38f71d2280413b9536d327a78f 100644 --- a/mindquantum/algorithm/qaia/SB.py +++ b/mindquantum/algorithm/qaia/SB.py @@ -192,6 +192,10 @@ class BSB(SB): # noqa: N801 in-place during optimization. If you need to preserve the original data, please pass a copy using `x.copy()`. + When using backend='gpu-int8', be aware that it may not perform well on dense graphs + or graphs with continuous coefficients. Please try adjusting parameters or consider + using 'cpu-float32' or 'gpu-float16' in these cases. + Args: J (Union[numpy.array, scipy.sparse.spmatrix]): The coupling matrix with shape (N x N). h (numpy.array): The external field with shape (N, ). @@ -308,6 +312,10 @@ class DSB(SB): # noqa: N801 in-place during optimization. If you need to preserve the original data, please pass a copy using `x.copy()`. + When using backend='gpu-int8', be aware that it may not perform well on dense graphs + or graphs with continuous coefficients. Please try adjusting parameters or consider + using 'cpu-float32' or 'gpu-float16' in these cases. + Args: J (Union[numpy.array, scipy.sparse.spmatrix]): The coupling matrix with shape (N x N). h (numpy.array): The external field with shape (N, ). diff --git a/mindquantum/core/circuit/circuit.py b/mindquantum/core/circuit/circuit.py index f366c6d352e357eb31f8eac84db9849165d1b51f..ef0963bd5ddd1c8d6e4643945a26a15bf58b0f6e 100644 --- a/mindquantum/core/circuit/circuit.py +++ b/mindquantum/core/circuit/circuit.py @@ -21,6 +21,7 @@ import os from collections.abc import Iterable from types import FunctionType, MethodType from typing import List, Optional +import warnings import numpy as np from rich.box import ROUNDED @@ -972,6 +973,12 @@ class Circuit(list): # pylint: disable=too-many-instance-attributes,too-many-pu if pr is None: pr = ParameterResolver() pr = _check_and_generate_pr_type(pr, self.params_name) + if pr.is_complex: + warnings.warn( + "Simulator does not support complex number, the imaginary part will be ignored", + UserWarning, + stacklevel=2, + ) if self.has_measure_gate: raise ValueError("This circuit cannot have measurement gate.") if self.is_noise_circuit: diff --git a/mindquantum/simulator/mqsim.py b/mindquantum/simulator/mqsim.py index 0ced47391c7042d45a9a1b89a8f89accf3b99865..1a573d88015c0980a163c17c3682bfff0e9c84a2 100644 --- a/mindquantum/simulator/mqsim.py +++ b/mindquantum/simulator/mqsim.py @@ -13,6 +13,7 @@ # limitations under the License. # ============================================================================ """Mindquantum simulator.""" +import warnings from typing import Dict, Iterable, List, Union import numpy as np @@ -109,6 +110,12 @@ class MQSim(BackendBase): if pr is None: raise ValueError("Applying a parameterized circuit needs a parameter_resolver.") pr = _check_and_generate_pr_type(pr, circuit.params_name) + if pr.is_complex: + warnings.warn( + "Simulator does not support complex number, the imaginary part will be ignored", + UserWarning, + stacklevel=3, + ) else: pr = ParameterResolver() res = self.sim.apply_circuit(circuit.get_cpp_obj(), pr) @@ -139,6 +146,12 @@ class MQSim(BackendBase): pr = _check_and_generate_pr_type(pr, list(set(sum([p.params_name for p in gate.prs], [])))) else: pr = _check_and_generate_pr_type(pr, gate.coeff.params_name) + if pr.is_complex: + warnings.warn( + "Simulator does not support complex number, the imaginary part will be ignored", + UserWarning, + stacklevel=3, + ) else: pr = ParameterResolver() if isinstance(gate, Measure):