From ea90a2b3eb82f079fa13b209e69424924791eed0 Mon Sep 17 00:00:00 2001 From: ZWGMQ Date: Thu, 1 Jul 2021 15:38:01 +0800 Subject: [PATCH] fix comment about returns and some small mistakes --- mindquantum/hiqfermion/transforms/transform.py | 4 ++-- mindquantum/nn/mindquantum_ansatz_only_layer.py | 2 +- mindquantum/nn/mindquantum_layer.py | 2 +- mindquantum/ops/_base_operator.py | 2 +- mindquantum/ops/fermion_operator.py | 2 +- mindquantum/ops/polynomial_tensor.py | 12 ++++++------ mindquantum/ops/qubit_excitation_operator.py | 6 +++--- mindquantum/third_party/interaction_operator.py | 11 ++++++----- mindquantum/third_party/unitary_cc.py | 12 ++++++------ mindquantum/utils/utils_operator.py | 10 +++++----- 10 files changed, 32 insertions(+), 31 deletions(-) diff --git a/mindquantum/hiqfermion/transforms/transform.py b/mindquantum/hiqfermion/transforms/transform.py index 1b8d8c6ee..77d3d3d49 100644 --- a/mindquantum/hiqfermion/transforms/transform.py +++ b/mindquantum/hiqfermion/transforms/transform.py @@ -122,14 +122,14 @@ def parity(self): stores the initial occupation number nonlocally. with the formular: - ..math:: + .. math:: |f_{M−1}, f_{M−2}, . . . , f_0\rangle → |q_{M−1}, q_{M−2}, . . . , q_0\rangle, where :math:`q_{m} = |(\sum{i,0,m-1}f_{i}) mod 2 \rangle`. Basically, this formular could be written as this, - ..math:: + .. math:: p_{i} = \sum{[\pi_{n}]_{i,j}} f_{j}, diff --git a/mindquantum/nn/mindquantum_ansatz_only_layer.py b/mindquantum/nn/mindquantum_ansatz_only_layer.py index 4f4be95b0..8ab6e3099 100644 --- a/mindquantum/nn/mindquantum_ansatz_only_layer.py +++ b/mindquantum/nn/mindquantum_ansatz_only_layer.py @@ -160,7 +160,7 @@ def final_state(self, measurements=None): will be used. Default: None. Returns: - numpy.ndarray: the final quantum state. + numpy.ndarray, the final quantum state. """ fake_data = Tensor(np.array([]).astype(np.float32)) return super().final_state(fake_data, diff --git a/mindquantum/nn/mindquantum_layer.py b/mindquantum/nn/mindquantum_layer.py index c7822d04f..7c16f6b14 100644 --- a/mindquantum/nn/mindquantum_layer.py +++ b/mindquantum/nn/mindquantum_layer.py @@ -117,7 +117,7 @@ def final_state(self, will be used. Default: None. Returns: - numpy.ndarray: the final quantum state. + numpy.ndarray, the final quantum state. """ if circuit is None: circuit = self.circuit diff --git a/mindquantum/ops/_base_operator.py b/mindquantum/ops/_base_operator.py index 7df210b1b..c5a5461ad 100644 --- a/mindquantum/ops/_base_operator.py +++ b/mindquantum/ops/_base_operator.py @@ -243,7 +243,7 @@ def __iadd__(self, operator): operator (QubitOperator): The operator to add. Returns: - sum (QubitOperator): Mutated self. + sum (QubitOperator), Mutated self. Raises: TypeError: Cannot add invalid operator type. diff --git a/mindquantum/ops/fermion_operator.py b/mindquantum/ops/fermion_operator.py index b211a2c94..8c97c7546 100644 --- a/mindquantum/ops/fermion_operator.py +++ b/mindquantum/ops/fermion_operator.py @@ -233,7 +233,7 @@ def _normal_ordered_term(term, coefficient): r"""Return the normal ordered term of the FermionOperator with high index and creation operator in front. - eg. a_3\dagger a_2\dagger a_1 a_0 + eg. :math:`a_3\dagger a_2\dagger a_1 a_0` """ term = list(term) diff --git a/mindquantum/ops/polynomial_tensor.py b/mindquantum/ops/polynomial_tensor.py index 992c424df..7c6f48e8e 100644 --- a/mindquantum/ops/polynomial_tensor.py +++ b/mindquantum/ops/polynomial_tensor.py @@ -234,7 +234,7 @@ def __iadd__(self, addend): addend (PolynomialTensor): The addend. Returns: - sum (PolynomialTensor): Mutated self. + sum (PolynomialTensor), Mutated self. Raises: TypeError: Cannot add invalid addend type. @@ -265,7 +265,7 @@ def __add__(self, addend): added(PolynomialTensor): The addend. Returns: - sum (PolynomialTensor): un-mutated self, but has new instance + sum (PolynomialTensor), un-mutated self, but has new instance Raises: TypeError: Cannot add invalid operator type. @@ -288,7 +288,7 @@ def __isub__(self, subtractend): subtractend (PolynomialTensor): subtractend. Returns: - subtract (PolynomialTensor): Mutated self. + subtract (PolynomialTensor), Mutated self. Raises: TypeError: Cannot sub invalid addend type. @@ -319,7 +319,7 @@ def __sub__(self, subtractend): subtractend(PolynomialTensor): The subtractend. Returns: - subtractend (PolynomialTensor): un-mutated self, + subtractend (PolynomialTensor), un-mutated self, but has new instance Raises: @@ -336,7 +336,7 @@ def __imul__(self, multiplier): terms (same operator). Args: - multiplier(complex, float, or PolynomialTensor): multiplier + multiplier(complex, float, or PolynomialTensor): multiplier Returns: products(PolynomialTensor) @@ -382,7 +382,7 @@ def __mul__(self, multiplier): multiplier (PolynomialTensor): The multiplier to multiply. Returns: - multiply (PolynomialTensor): un-Mutated self. + multiply (PolynomialTensor), un-Mutated self. Raises: TypeError: Cannot multiply invalid type. diff --git a/mindquantum/ops/qubit_excitation_operator.py b/mindquantum/ops/qubit_excitation_operator.py index 9f8ef7f50..0b40bda7a 100644 --- a/mindquantum/ops/qubit_excitation_operator.py +++ b/mindquantum/ops/qubit_excitation_operator.py @@ -115,8 +115,8 @@ def to_qubit_operator(self): Convert the Qubit excitation operator to the equivalent Qubit operator. Returns: - qubit_operator(QubitOperator): The corresponding QubitOperator - according to the definition of Qubit excitation operators. + qubit_operator(QubitOperator), The corresponding QubitOperator + according to the definition of Qubit excitation operators. Examples: >>> from mindquantum.ops import QubitExcitationOperator @@ -268,7 +268,7 @@ def normal_ordered(self): Returns: QubitExcitationOperator, the normal ordered operator. - Exmples: + Examples: >>> from mindquantum.ops import QubitExcitationOperator >>> op = QubitExcitationOperator("7 1^") >>> op diff --git a/mindquantum/third_party/interaction_operator.py b/mindquantum/third_party/interaction_operator.py index e4c655839..ee24773a5 100644 --- a/mindquantum/third_party/interaction_operator.py +++ b/mindquantum/third_party/interaction_operator.py @@ -34,22 +34,23 @@ class InteractionOperator(PolynomialTensor): and parity. In this module, the stored coefficient could be represented the molecualr Hamiltonians througth the FermionOperator class. - Notes: + Note: The operators stored in this class has the form: + .. math:: - constant + \sum_{p, q} h_[p, q] a^\dagger_p a_q + - \sum_{p, q, r, s} h_[p, q, r, s] a^\dagger_p a^\dagger_q a_r a_s. + constant + \sum_{p, q} h_[p, q] a^\dagger_p a_q + + \sum_{p, q, r, s} h_[p, q, r, s] a^\dagger_p a^\dagger_q a_r a_s. Args: constant (number.Numbers): A constant term in the operator given as a float. For instance, the nuclear repulsion energy. one_body_tensor (numpy.array): The coefficients of the one-body terms (h[p, q]). This is an n_qubits x n_qubits numpy array of floats. By default we - store the numpy array with keys: a^\dagger_p a_q (1,0). + store the numpy array with keys: :math:`a^\dagger_p a_q` (1,0). two_body_tensor (numpy.array): The coefficients of the two-body terms (h[p, q, r, s]). This is an n_qubits x n_qubits x n_qubits x n_qubits numpy array of floats.By default we store the numpy array - with keys: a^\dagger_p a^\dagger_q a_r a_s (1, 1, 0, 0). + with keys: :math:`a^\dagger_p a^\dagger_q a_r a_s` (1, 1, 0, 0). """ def __init__(self, constant, one_body_tensor, two_body_tensor): # make sure only non-zero tensor elements exist in the normal-ordered diff --git a/mindquantum/third_party/unitary_cc.py b/mindquantum/third_party/unitary_cc.py index 517eb6a3c..2b8d82523 100644 --- a/mindquantum/third_party/unitary_cc.py +++ b/mindquantum/third_party/unitary_cc.py @@ -39,10 +39,10 @@ def uccsd_singlet_get_packed_amplitudes(single_amplitudes, double_amplitudes, n_electrons(int): Number of electrons in the physical system. Returns: - packed_amplitudes(list): List storing the unique single - and double excitation amplitudes for a singlet UCCSD operator. - The ordering lists unique single excitations before double - excitations. + packed_amplitudes(list), List storing the unique single + and double excitation amplitudes for a singlet UCCSD operator. + The ordering lists unique single excitations before double + excitations. """ n_spatial_orbitals = n_qubits // 2 n_occupied = int(numpy.ceil(n_electrons / 2)) @@ -116,8 +116,8 @@ def uccsd_singlet_generator(n_qubits, n_electrons, anti_hermitian=True): rather than unitary variant, primarily for testing Returns: - generator(FermionOperator): Generator of the UCCSD operator that - builds the UCCSD wavefunction. + generator(FermionOperator), Generator of the UCCSD operator that + builds the UCCSD wavefunction. """ if n_qubits % 2 != 0: raise ValueError('The total number of spin-orbitals should be even.') diff --git a/mindquantum/utils/utils_operator.py b/mindquantum/utils/utils_operator.py index 27bf9ebce..e45704033 100644 --- a/mindquantum/utils/utils_operator.py +++ b/mindquantum/utils/utils_operator.py @@ -33,7 +33,7 @@ def count_qubits(operator): FermionOperator or QubitOperator or QubitExcitationOperator. Returns: - num_qubits (int): The minimum number of qubits on which operator acts. + num_qubits (int), The minimum number of qubits on which operator acts. Raises: TypeError: Operator of invalid type. @@ -107,7 +107,7 @@ def _normal_ordered_term(term, coefficient): r""" return the normal order order of a fermion operator with larger index and creation operator in front. - eg. a_4\dagger a3_\dagger a_2 a_1. + eg. :math:`a_4\dagger a3_\dagger a_2 a_1`. """ term = list(term) ordered_term = FermionOperator() @@ -175,7 +175,7 @@ def get_fermion_operator(operator): """Convert the tensor (PolynomialTensor) to FermionOperator. Returns: - fermion_operator: An instance of the FermionOperator class. + fermion_operator, An instance of the FermionOperator class. """ fermion_operator = FermionOperator() @@ -232,7 +232,7 @@ def hermitian_conjugated(operator): Returns: operator (Union[FermionOperator, QubitOperator, QubitExcitationOperator]), - the hermitian form of the input operator. + the hermitian form of the input operator. Examples: >>> from mindquantum.ops import QubitOperator @@ -309,7 +309,7 @@ def sz_operator(n_spatial_orbitals): n_spatial_orbitals (int): number of spatial orbitals (n_qubits // 2). Returns: - operator (FermionOperator): corresponding to the sz operator over + operator (FermionOperator), corresponding to the sz operator over n_spatial_orbitals. Note: