Skip to content

Commit

Permalink
lint and format
Browse files Browse the repository at this point in the history
  • Loading branch information
inafergra committed Apr 19, 2024
1 parent fa93d70 commit 46f04e7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
11 changes: 8 additions & 3 deletions qadence_libs/qinfo_tools/qng.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/qinfo_tools/test_qfi.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/qinfo_tools/test_qng.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))))

Expand Down
5 changes: 1 addition & 4 deletions tests/qinfo_tools/test_spsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 46f04e7

Please sign in to comment.