From 46f04e7467567a08836e89e955a33c91ff26db5a Mon Sep 17 00:00:00 2001 From: Ignacio Date: Fri, 19 Apr 2024 17:22:57 +0200 Subject: [PATCH] lint and format --- qadence_libs/qinfo_tools/qng.py | 11 ++++++++--- tests/conftest.py | 7 ++++--- tests/qinfo_tools/test_qfi.py | 3 ++- tests/qinfo_tools/test_qng.py | 8 ++++---- tests/qinfo_tools/test_spsa.py | 5 +---- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/qadence_libs/qinfo_tools/qng.py b/qadence_libs/qinfo_tools/qng.py index b507715..6b83189 100644 --- a/qadence_libs/qinfo_tools/qng.py +++ b/qadence_libs/qinfo_tools/qng.py @@ -28,11 +28,13 @@ def __init__( ): """ Args: + params (tuple | torch.Tensor): Variational parameters to be updated circuit (QuantumCircuit): Quantum circuit. Needed to compute the QFI matrix lr (float): Learning rate. beta (float): - Shift applied to the QFI matrix before inversion to ensure numerical stability. Defaults to 10e-3. + Shift applied to the QFI matrix before inversion to ensure numerical stability. + Defaults to 10e-3. """ if not 0.0 <= lr: @@ -105,13 +107,16 @@ def __init__( ): """ Args: + params (tuple | torch.Tensor): Variational parameters to be updated circuit (QuantumCircuit): Quantum circuit. Required to compute the QFI matrix. lr (float): Learning rate. iteration (int): Current iteration. Required to compute the SPSA estimator of the QFI. beta (float): - Shift applied to the QFI matrix before inversion to ensure numerical stability. Defaults to 10e-3. - epsilon (float): Finite shift applied when computing the SPSA derivatives. + Shift applied to the QFI matrix before inversion to ensure numerical stability. + Defaults to 10e-3. + epsilon (float): + Finite shift applied when computing the SPSA derivatives. Defaults to 10e-2. """ if not 0.0 <= lr: diff --git a/tests/conftest.py b/tests/conftest.py index 05658ac..e3e4aff 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,10 @@ # use this file for configuring test fixtures and # functions common to every test -from pytest import fixture +from __future__ import annotations -from qadence import BasisSet, QuantumCircuit, QNN -from qadence.constructors import feature_map, hea, hamiltonian_factory +from pytest import fixture +from qadence import QNN, BasisSet, QuantumCircuit +from qadence.constructors import feature_map, hamiltonian_factory, hea from qadence.operations import RX, RY, Z N_QUBITS_OPTIM = 2 diff --git a/tests/qinfo_tools/test_qfi.py b/tests/qinfo_tools/test_qfi.py index f2fe3e4..123db54 100644 --- a/tests/qinfo_tools/test_qfi.py +++ b/tests/qinfo_tools/test_qfi.py @@ -1,11 +1,12 @@ from __future__ import annotations import random + import numpy as np import torch +from qadence import QuantumCircuit from torch import Size, allclose -from qadence import QuantumCircuit from qadence_libs.qinfo_tools import get_quantum_fisher, get_quantum_fisher_spsa SEED = 42 diff --git a/tests/qinfo_tools/test_qng.py b/tests/qinfo_tools/test_qng.py index 2630bff..2f31851 100644 --- a/tests/qinfo_tools/test_qng.py +++ b/tests/qinfo_tools/test_qng.py @@ -5,9 +5,7 @@ import numpy as np import pytest import torch -from qadence import QNN, BasisSet, QuantumCircuit, hamiltonian_factory -from qadence.constructors import feature_map, hea -from qadence.operations import RX, RY, Z +from qadence import QuantumCircuit from torch import Tensor from qadence_libs.qinfo_tools import QNG, QNG_SPSA @@ -39,7 +37,9 @@ def sin_dataset(samples: int) -> tuple[Tensor, Tensor]: @pytest.mark.parametrize("dataset", DATASETS) @pytest.mark.parametrize("optim_config", OPTIMIZERS_CONFIG) -def test_optims(dataset: tuple[Tensor, Tensor], optim_config: dict, basic_optim_model) -> None: +def test_optims( + dataset: tuple[Tensor, Tensor], optim_config: dict, basic_optim_model: QuantumCircuit +) -> None: circuit, model = basic_optim_model model.reset_vparams(torch.rand((len(model.vparams)))) diff --git a/tests/qinfo_tools/test_spsa.py b/tests/qinfo_tools/test_spsa.py index a514ae4..9d50147 100644 --- a/tests/qinfo_tools/test_spsa.py +++ b/tests/qinfo_tools/test_spsa.py @@ -5,12 +5,9 @@ import numpy as np import pytest import torch -from qadence import BasisSet, Overlap, QuantumCircuit -from qadence.constructors import feature_map, hea -from qadence.operations import RX, RY +from qadence import Overlap, QuantumCircuit from torch import Size -from qadence import QuantumCircuit from qadence_libs.qinfo_tools.spsa import _shifted_overlap, spsa_2gradient_step SEED = 42