Skip to content

Commit

Permalink
use v0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
anurudhp committed Feb 11, 2024
1 parent 808632c commit 2ff7782
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ all: ci extra

format:
black --quiet --check .
isort --quiet --check .
test:
pytest --doctest-modules -q
lint:
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ ignore = ["E501"] # line length enforced by black

[tool.mypy]
plugins = ["numpy.typing.mypy_plugin"]

[tool.isort]
profile = "black"
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
qubrabench@git+https://github.com/qubrabench/qubrabench.git#egg=3844bc51f3f142c7175aae5c5e0a1ce7d5e86a01
qubrabench@git+https://github.com/qubrabench/qubrabench.git#egg=v0.2.0
numpy~=1.24
matplotlib~=3.7
black[jupyter]
isort
pytest~=7.3
ruff~=0.0
mypy~=1.2
Expand Down
30 changes: 25 additions & 5 deletions usecase/use_max.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
from typing import Callable, Sequence

import numpy as np
import pytest
from qubrabench.algorithms.max import max
from qubrabench.benchmark import track_queries, named_oracle
from qubrabench.benchmark import QueryStats, oracle, track_queries


def max_value_of_function(it: Sequence[float], f: Callable[[float], float]):
return max(it, key=f, error=1e-5)


def test_use_max_quadratic():
@oracle
def f(x: float):
return 4 * x - x**2

N = 10000

def max_value_of_function(it, f):
with track_queries() as tracker:
result = max(it, key=named_oracle("max_key")(f), error=1e-5)
stats = tracker.get_stats("max_key")
domain = np.linspace(-10, 10, num=N)
result = max_value_of_function(domain, f)
assert result == pytest.approx(2, rel=1e-3)

return result, stats
assert tracker.get_stats(f) == QueryStats(
classical_actual_queries=N,
classical_expected_queries=N,
quantum_expected_classical_queries=0,
quantum_expected_quantum_queries=pytest.approx(15610.0172),
)
12 changes: 0 additions & 12 deletions usecase/use_max_test.py

This file was deleted.

0 comments on commit 2ff7782

Please sign in to comment.