Skip to content

Commit

Permalink
!2246 [DOC] Fix docing
Browse files Browse the repository at this point in the history
Merge pull request !2246 from donghufeng/dev/fix_docing
  • Loading branch information
donghufeng authored and gitee-org committed Jan 9, 2024
2 parents e5f0efd + 1d970b1 commit 970bd92
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 22 deletions.
1 change: 1 addition & 0 deletions docs/api_python/algorithm/mindquantum.algorithm.qaia.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mindquantum.algorithm.qaia

.. py:module:: mindquantum.algorithm.qaia
量子退火启发式算法。

.. mscnautosummary::
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mindquantum.algorithm.nisq.HardwareEfficientAnsatz
===================================================

.. py:class:: mindquantum.algorithm.nisq.HardwareEfficientAnsatz(n_qubits, single_rot_gate_seq, entangle_gate=X, entangle_mapping='linear', depth=1)
.. py:class:: mindquantum.algorithm.nisq.HardwareEfficientAnsatz(n_qubits, single_rot_gate_seq, entangle_gate=X, entangle_mapping='linear', depth=1, prefix: str = '', suffix: str = '')
HardwareEfficientAnsatz是一种可以很容易地在量子芯片上高效实现的ansatz。

Expand All @@ -14,3 +14,5 @@ mindquantum.algorithm.nisq.HardwareEfficientAnsatz
- **entangle_gate** (BasicGate) - 非参数化纠缠门。如果它是单个量子比特门,则将使用控制版本。默认值: ``XGate``。
- **entangle_mapping** (Union[str, list[tuple[int]]]) - 纠缠门的纠缠映射。 ``"linear"`` 表示纠缠门将作用于每个相邻的量子比特。 ``"all"`` 表示纠缠门将作用于任何两个两个量子比特。此外,可以通过将纠缠映射设置为两个量子比特元组的列表来指定要执行纠缠的两个量子比特。默认值: ``"linear"``。
- **depth** (int) - ansatz的深度。默认值: ``1``。
- **prefix** (str) - 参数的前缀。默认值: ``''``。
- **suffix** (str) - 参数的后缀。默认值: ``''``。
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mindquantum.algorithm.nisq.IQPEncoding
=======================================

.. py:class:: mindquantum.algorithm.nisq.IQPEncoding(n_feature, first_rotation_gate=RZ, second_rotation_gate=RZ, num_repeats=1)
.. py:class:: mindquantum.algorithm.nisq.IQPEncoding(n_feature, first_rotation_gate=RZ, second_rotation_gate=RZ, num_repeats=1, prefix: str = '', suffix: str = '')
通用IQP编码。

Expand All @@ -12,6 +12,8 @@ mindquantum.algorithm.nisq.IQPEncoding
- **first_rotation_gate** (ParameterGate) - 旋转门RX、RY或RZ之一。
- **second_rotation_gate** (ParameterGate) - 旋转门RX、RY或RZ之一。
- **num_repeats** (int) - 编码迭代次数。
- **prefix** (str) - 参数的前缀。默认值: ``''``。
- **suffix** (str) - 参数的后缀。默认值: ``''``。

.. py:method:: data_preparation(data)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mindquantum.algorithm.nisq.StronglyEntangling
==============================================

.. py:class:: mindquantum.algorithm.nisq.StronglyEntangling(n_qubits: int, depth: int, entangle_gate: BasicGate)
.. py:class:: mindquantum.algorithm.nisq.StronglyEntangling(n_qubits: int, depth: int, entangle_gate: BasicGate, prefix: str = '', suffix: str = '')
强纠缠ansatz。请参考 `Circuit-centric quantum classifiers <https://arxiv.org/pdf/1804.00633.pdf>`_。

Expand All @@ -11,3 +11,5 @@ mindquantum.algorithm.nisq.StronglyEntangling
- **entangle_gate** (BasicGate) - 产生纠缠的量子门。
如果传入单量子比特门,则会添加一个控制量子比特,
如果传入双量子比特门,则该双量子比特门将作用于不同的量子比特。
- **prefix** (str) - 参数的前缀。默认值: ``''``。
- **suffix** (str) - 参数的后缀。默认值: ``''``。
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ mindquantum.algorithm.qaia.LQA
初始化自旋。

.. py:method:: update()
.. py:method:: update(beta1=0.9, beta2=0.999, epsilon=10e-8)
参数:
- **beta1** (float) - Beta1参数。默认值: ``0.9``。
- **beta2** (float) - Beta2参数。默认值: ``0.999``。
- **epsilon** (float) - Epsilon参数。默认值: ``10e-8``。

Adam动力学演化。
8 changes: 7 additions & 1 deletion mindquantum/algorithm/nisq/chem/hardware_efficient_ansatz.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

from mindquantum.core.circuit import AP, A, Circuit, add_prefix, add_suffix
from mindquantum.core.gates import BasicGate, X
from mindquantum.utils.type_value_check import _check_int_type, _check_value_should_not_less, _check_input_type
from mindquantum.utils.type_value_check import (
_check_input_type,
_check_int_type,
_check_value_should_not_less,
)

from .._ansatz import Ansatz

Expand Down Expand Up @@ -61,6 +65,8 @@ class HardwareEfficientAnsatz(Ansatz):
qubits you want to do entanglement by setting the entangle_mapping to a list of two qubits
tuple. Default: ``"linear"``.
depth (int): The depth of ansatz. Default: ``1``.
prefix (str): The prefix of parameters. Default: ``''``.
suffix (str): The suffix of parameters. Default: ``''``.
Examples:
>>> from mindquantum.algorithm.nisq import HardwareEfficientAnsatz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ class ASWAP(Ansatz, Initializer):
q2: ───────────────────────────────────■───┨ RZ(a_p2) ┠─┨ RZ(π) ┠─┨ RY(a_p3) ┠─┨ RY(π/2) ┠─↯─
┗━━━━━━━━━━┛ ┗━━━━━━━┛ ┗━━━━━━━━━━┛ ┗━━━━━━━━━┛
q0: ────────────────────────────────────────────────────────────────────
┏━━━┓
q1: ────■───────────────────────────────────────────────────────┨╺╋╸┠───
┃ ┗━┳━┛
Expand Down Expand Up @@ -330,7 +329,6 @@ class PCHeaXYZ1F(Ansatz, Initializer):
q2: ──┨ RX(p2) ┠─┨ RY(p5) ┠─────────────────────────────────────────────────────┨ RY(-1/2*p8) ┠─↯─
┗━━━━━━━━┛ ┗━━━━━━━━┛ ┗━━━━━━━━━━━━━┛
q0: ─────────────────────────────────────────────────────────────────────────────────────────↯─
┏━━━━━━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━━━━━━━━┓
q1: ──┨ ┠────────────────────────────────────────────┨ ┠─↯─
┃ ┃ ┃ ┃
Expand Down
5 changes: 4 additions & 1 deletion mindquantum/algorithm/nisq/qnn/iqp_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _check_intrinsconeparagate(msg, gate_type):


class IQPEncoding(Ansatz):
"""
r"""
General IQP Encoding.
For more information, please refer to `Supervised learning with quantum-enhanced feature
Expand All @@ -43,6 +43,8 @@ class IQPEncoding(Ansatz):
first_rotation_gate (ParameterGate): One of the rotation gate RX, RY or RZ.
second_rotation_gate (ParameterGate): One of the rotation gate RX, RY or RZ.
num_repeats (int): Number of encoding iterations.
prefix (str): The prefix of parameters. Default: ``''``.
suffix (str): The suffix of parameters. Default: ``''``.
Examples:
>>> import numpy as np
Expand Down Expand Up @@ -71,6 +73,7 @@ class IQPEncoding(Ansatz):
0.31027229+0.16950252j, 0.31027229+0.16950252j])
"""

# pylint: disable=too-many-arguments
def __init__(
self,
n_feature,
Expand Down
11 changes: 9 additions & 2 deletions mindquantum/algorithm/nisq/qnn/strongly_entangling.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
from mindquantum.core.circuit import Circuit, add_prefix, add_suffix
from mindquantum.core.gates import BasicGate
from mindquantum.core.gates.basicgate import U3
from mindquantum.utils.type_value_check import _check_int_type, _check_value_should_not_less, _check_input_type
from mindquantum.utils.type_value_check import (
_check_input_type,
_check_int_type,
_check_value_should_not_less,
)

from .._ansatz import Ansatz


class StronglyEntangling(Ansatz): # pylint: disable=too-few-public-methods
"""
r"""
Strongly entangling ansatz.
Please refers `Circuit-centric quantum classifiers <https://arxiv.org/pdf/1804.00633.pdf>`_.
Expand All @@ -34,6 +38,8 @@ class StronglyEntangling(Ansatz): # pylint: disable=too-few-public-methods
entangle_gate (BasicGate): a quantum gate to generate entanglement. If a single
qubit gate is given, a control qubit will add, if a two qubits gate is given,
the two qubits gate will act on different qubits.
prefix (str): The prefix of parameters. Default: ``''``.
suffix (str): The suffix of parameters. Default: ``''``.
Examples:
>>> from mindquantum.core.gates import X
Expand All @@ -60,6 +66,7 @@ class StronglyEntangling(Ansatz): # pylint: disable=too-few-public-methods
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┗━━━┛
"""

# pylint: disable=too-many-arguments
def __init__(self, n_qubits: int, depth: int, entangle_gate: BasicGate, prefix: str = '', suffix: str = ''):
"""Initialize a strongly entangling ansatz."""
_check_int_type('n_qubits', n_qubits)
Expand Down
2 changes: 1 addition & 1 deletion mindquantum/algorithm/qaia/CAC.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CAC(QAIA):
# pylint: disable=too-many-arguments,too-many-instance-attributes
def __init__(
self,
J, # noqa: N803
J,
h=None,
x=None,
n_iter=1000,
Expand Down
2 changes: 1 addition & 1 deletion mindquantum/algorithm/qaia/CFC.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CFC(QAIA):
# pylint: disable=too-many-arguments,too-many-instance-attributes
def __init__(
self,
J, # noqa: N803
J,
h=None,
x=None,
n_iter=1000,
Expand Down
11 changes: 9 additions & 2 deletions mindquantum/algorithm/qaia/LQA.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class LQA(QAIA):
# pylint: disable=too-many-arguments
def __init__(
self,
J, # noqa: N803
J,
h=None,
x=None,
n_iter=1000,
Expand All @@ -68,7 +68,14 @@ def initialize(self):
raise ValueError(f"The size of x {self.x.shape[0]} is not equal to the number of spins {self.N}")

def update(self, beta1=0.9, beta2=0.999, epsilon=10e-8):
"""Dynamical evolution with Adam."""
"""
Dynamical evolution with Adam.
Args:
beta1 (float): Beta1 parameter. Default: ``0.9``.
beta2 (float): Beta2 parameter. Default: ``0.999``.
epsilon (float): Epsilon parameter. Default: ``10e-8``.
"""
m_dx = 0
v_dx = 0

Expand Down
2 changes: 1 addition & 1 deletion mindquantum/algorithm/qaia/NMFA.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class NMFA(QAIA):
# pylint: disable=too-many-arguments
def __init__(
self,
J, # noqa: N803
J,
h=None,
x=None,
n_iter=1000,
Expand Down
2 changes: 1 addition & 1 deletion mindquantum/algorithm/qaia/QAIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class QAIA:
"""

# pylint: disable=too-many-arguments
def __init__(self, J, h=None, x=None, n_iter=1000, batch_size=1): # noqa: N803
def __init__(self, J, h=None, x=None, n_iter=1000, batch_size=1):
"""Construct a QAIA algorithm."""
self.J = J
self.h = h
Expand Down
8 changes: 4 additions & 4 deletions mindquantum/algorithm/qaia/SB.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SB(QAIA):
# pylint: disable=too-many-arguments
def __init__(
self,
J, # noqa: N803
J,
h=None,
x=None,
n_iter=1000,
Expand Down Expand Up @@ -95,7 +95,7 @@ class ASB(SB): # noqa: N801
# pylint: disable=too-many-arguments
def __init__(
self,
J, # noqa: N803
J,
h=None,
x=None,
n_iter=1000,
Expand Down Expand Up @@ -145,7 +145,7 @@ class BSB(SB): # noqa: N801
# pylint: disable=too-many-arguments
def __init__(
self,
J, # noqa: N803
J,
h=None,
x=None,
n_iter=1000,
Expand Down Expand Up @@ -192,7 +192,7 @@ class DSB(SB): # noqa: N801
# pylint: disable=too-many-arguments
def __init__(
self,
J, # noqa: N803
J,
h=None,
x=None,
n_iter=1000,
Expand Down
2 changes: 1 addition & 1 deletion mindquantum/algorithm/qaia/SFC.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SFC(QAIA):
# pylint: disable=too-many-arguments,too-many-instance-attributes
def __init__(
self,
J, # noqa: N803
J,
h=None,
x=None,
n_iter=1000,
Expand Down
2 changes: 1 addition & 1 deletion mindquantum/algorithm/qaia/SimCIM.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SimCIM(QAIA):
# pylint: disable=too-many-arguments, too-many-instance-attributes
def __init__(
self,
J, # noqa: N803
J,
h=None,
x=None,
n_iter=1000,
Expand Down
9 changes: 9 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ per-file-ignores =
module_circuit.py: C092
test_uccsd.py: F401
test_chem_net.py: F401
CAC.py: N803
LQA.py: N803
QAIA.py: N803
SFC.py: N803
CFC.py: N803
SimCIM.py: N803
NMFA.py: N803
SB.py: N803


max-line-length = 120
exclude =
Expand Down

0 comments on commit 970bd92

Please sign in to comment.