From 04246536148e9391f2378352c5ec8aa99729ba15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20Ja=C5=82owiecki?= Date: Mon, 2 Jan 2023 21:28:03 +0100 Subject: [PATCH] fix: incorrectly formatted docstrings (#36) * fix: incorrectly formatted docstrings * fix: shorten formula in docstring to be less than 88 chars --- src/orquestra/vqa/ansatz/singlet_uccsd.py | 3 ++- src/orquestra/vqa/cost_function/cost_function.py | 3 +++ .../vqa/cost_function/qcbm_cost_function.py | 4 ++-- .../vqa/shot_allocation/_shot_allocation.py | 16 ++++++++-------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/orquestra/vqa/ansatz/singlet_uccsd.py b/src/orquestra/vqa/ansatz/singlet_uccsd.py index 3052007..d092ec9 100644 --- a/src/orquestra/vqa/ansatz/singlet_uccsd.py +++ b/src/orquestra/vqa/ansatz/singlet_uccsd.py @@ -116,6 +116,7 @@ def screen_out_operator_terms_below_threshold( ) -> Tuple[np.ndarray, FermionOperator]: """Screen single and double excitation operators based on a guess for the amplitudes + Args: threshold (float): threshold to select excitations. Only those with absolute amplitudes above the threshold are kept. @@ -124,7 +125,7 @@ def screen_out_operator_terms_below_threshold( Returns: amplitudes (np.array): screened amplitudes new_fermion_generator (openfermion.FermionOperator): screened - Fermion Operator + Fermion Operator """ new_fermion_generator = FermionOperator() diff --git a/src/orquestra/vqa/cost_function/cost_function.py b/src/orquestra/vqa/cost_function/cost_function.py index b2763c9..b97bbdb 100644 --- a/src/orquestra/vqa/cost_function/cost_function.py +++ b/src/orquestra/vqa/cost_function/cost_function.py @@ -151,6 +151,9 @@ def create_cost_function( A callable CostFunction object. Example use case: + + .. code:: python + target_operator = ... ansatz = ... diff --git a/src/orquestra/vqa/cost_function/qcbm_cost_function.py b/src/orquestra/vqa/cost_function/qcbm_cost_function.py index cb9eb76..108018e 100644 --- a/src/orquestra/vqa/cost_function/qcbm_cost_function.py +++ b/src/orquestra/vqa/cost_function/qcbm_cost_function.py @@ -31,6 +31,7 @@ def create_QCBM_cost_function( gradient_function: GradientFactory = finite_differences_gradient, ) -> CostFunction: """Cost function used for evaluating QCBM. + Args: ansatz: the ansatz used to construct the variational circuits runner: runner used for QCBM evaluation @@ -74,8 +75,7 @@ def _create_QCBM_cost_function( def cost_function( parameters: np.ndarray, store_artifact: Optional[StoreArtifact] = None ) -> ValueEstimate: - """ - Evaluates the value of the cost function for given parameters. + """Evaluates the value of the cost function for given parameters. Args: parameters: parameters for which the evaluation should occur. diff --git a/src/orquestra/vqa/shot_allocation/_shot_allocation.py b/src/orquestra/vqa/shot_allocation/_shot_allocation.py index 3387a50..bc4a166 100644 --- a/src/orquestra/vqa/shot_allocation/_shot_allocation.py +++ b/src/orquestra/vqa/shot_allocation/_shot_allocation.py @@ -86,18 +86,18 @@ def estimate_nmeas_for_frames( We are assuming the exact expectation values are provided (i.e. infinite number of measurements or simulations without noise) - M ~ (sum_{i} prec(H_i)) ** 2.0 / (epsilon ** 2.0) - where prec(H_i) is the precision (square root of the variance) + :math:`M ~ (sum_{i} prec(H_i)) ** 2.0 / (epsilon ** 2.0)` + where :math:`prec(H_i)` is the precision (square root of the variance) for each group of co-measurable terms H_{i}. It is computed as - prec(H_{i}) = sum{ab} |h_{a}^{i}||h_{b}^{i}| cov(O_{a}^{i}, O_{b}^{i}) - where h_{a}^{i} is the coefficient of the a-th operator, O_{a}^{i}, in the - i-th group. Covariances are assumed to be zero for a != b: - cov(O_{a}^{i}, O_{b}^{i}) = - = 0 + :math:`prec(H_{i}) = sum{ab} |h_{a}^{i}||h_{b}^{i}| cov(O_{a}^{i}, O_{b}^{i})` + where :math:`h_{a}^{i}` is the coefficient of the a-th operator, :math:`O_{a}^{i}`, + in the i-th group. Covariances are assumed to be zero for a != b: + :math:`cov(O_{a}^{i},O_{b}^{i})=-=0` Args: - frame_operators (List[PauliRepresentation]): A list of pauli operators, where + frame_operators: A list of pauli operators, where each element in the list is a group of co-measurable terms. - expecval (Optional[ExpectationValues]): An ExpectationValues object containing + expecval: An ExpectationValues object containing the expectation values of all operators in frame_operators. If absent, variances are assumed to be maximal (i.e. equal to the square of the term's coefficient). Note that the term coefficients should be