-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
31 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
) |
This file was deleted.
Oops, something went wrong.