File size: 880 Bytes
25c6e75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""Recommended performance-sensitive interface: already-existing real ndarrays.

This is an integration example, not a benchmark or a production certificate.
"""
from pathlib import Path
import sys
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
import numpy as np
from qzguard import PreparedBank

x = np.linspace(-1.0, 1.0, 4096, dtype=np.float64)
values = np.column_stack((x, x + 0.25, x - 0.5, 2*x))
bank = PreparedBank(values - 0.01, values + 0.01, backend='filtered')
threshold = np.array([-0.2, 0.05, -0.7, -0.4], dtype=np.float64)
for step in range(3):
    lower = np.ones(len(x), dtype=np.float64)
    upper = lower * (1.1 + step * 0.05)
    result = bank.evaluate(lower, upper, threshold, relation='>=')
    assert result.all_guaranteed
    print({'step': step, 'backend': result.backend,
           'guaranteed': result.guaranteed, 'modes': result.modes})