Download source/docs/COOKBOOK.md from PureOne/Qyxo-Zhaenivoth-Guard: direct link, hf CLI and curl.
- Browser
- Download file 6.39 kB
-
https://huggingface.co/datasets/PureOne/Qyxo-Zhaenivoth-Guard/resolve/main/source/docs/COOKBOOK.md
- Command line
-
hf download hf://datasets/PureOne/Qyxo-Zhaenivoth-Guard/source/docs/COOKBOOK.md
-
curl -L -o COOKBOOK.md https://huggingface.co/datasets/PureOne/Qyxo-Zhaenivoth-Guard/resolve/main/source/docs/COOKBOOK.md
Guard integration cookbook
Use a prepared static value bank, new weight bounds and one threshold vector
per update. This is the narrow measured workload. The commands below use the
bundled wheel; they do not assume that this package is published on PyPI.
Python 3.10+ is required. See PUBLIC_INTERFACE.md for the complete contract.
Install in an application directory
These commands work from your application's directory, outside the release folder. Replace the quoted release path with the path where you unpacked it. The first installation is offline and uses only the bundled wheel. The NumPy command is optional and may download packages.
Windows PowerShell:
py -3 -m venv .venv
.\.venv\Scripts\python.exe -m pip install --no-index "C:\path\Guard\wheels\qyxo_zhaenivoth_guard-1.0.0-py3-none-any.whl"
.\.venv\Scripts\python.exe -m pip install "numpy>=1.24"
.\.venv\Scripts\python.exe -m qzguard doctor --backend filtered
Linux/macOS:
python3 -m venv .venv
.venv/bin/python -m pip install --no-index "/path/Guard/wheels/qyxo_zhaenivoth_guard-1.0.0-py3-none-any.whl"
.venv/bin/python -m pip install 'numpy>=1.24'
.venv/bin/python -m qzguard doctor --backend filtered
For exact-only use, omit NumPy installation and run doctor with
--backend exact. Run a saved Python example with your environment's interpreter:
.venv/bin/python example.py or .\.venv\Scripts\python.exe example.py.
Doctor checks a few deterministic fixtures; it does not certify every hardware
or compiler premise of the floating filter.
Exact policy check with a counterexample
This complete example needs no NumPy. Values are fixed here; supplying
value_upper would make them independent value intervals.
from qzguard import PreparedBank
bank = PreparedBank([0., 1.], backend='exact')
assert bank.evaluate([1., 100.], [1., 1_000_000.], .9,
relation='>=').all_guaranteed
answer = bank.evaluate([1., 0.], [1., 1_000_000.], .9, relation='>=')
assert answer.guaranteed == (False,)
witness = answer.exact(witness=True).witnesses[0]
assert witness.ratio < .9
print('admissible counterexample mean:', witness.ratio)
False means a violating configuration exists inside the independent input box. It does not mean every configuration violates the policy. A witness from a box that ignores physical correlations may be impossible in the original system.
Recommended ndarray service loop
This is the installed-package form of examples/fast_array_service.py. It is
an executable integration example, not a benchmark or a production certificate.
Application-provided numeric NumPy arrays use the best measured public Python
path. Inputs are copied into immutable snapshots; keep the value bank outside
the update loop.
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})
del result
One ambiguous coordinate currently triggers the full exact vector calculation.
witness=True, exact_margins=True and .exact() explicitly pay exact work;
leave them off the frequent path when decisions alone suffice. Route counts
count sign-decision routes, not arithmetic operations. An Evaluation retains
its weight snapshot and any exact fallback state. Store compact decision tuples
or serialized records instead of accumulating whole Evaluations indefinitely.
The filter requires the stated IEEE round-to-nearest binary64/gradual-underflow
and NumPy reduction premises. Use backend='exact' when those premises are
unavailable. auto selects once and reports bank.backend; explicit selection
is preferable for a fixed application contract. All guarantees concern the
exact real values of finite converted binary64 inputs, valid independent
intervals and a strictly positive minimum denominator.
JSONL without a Python integration
From the release root, the no-install exact path is:
python START_HERE.py check --bank examples/json/bank_exact.json \
--updates examples/json/updates.jsonl --output decisions.jsonl
For an installed environment, commands work from any directory. Use absolute
paths to the data files and your environment's interpreter in place of python:
python -m qzguard check --bank /path/Guard/examples/json/bank_exact.json \
--updates /path/Guard/examples/json/updates.jsonl --output decisions.jsonl
python -m qzguard check --bank /path/Guard/examples/json/bank_fast.json \
--updates /path/Guard/examples/json/updates.jsonl --backend filtered \
--output filtered_decisions.jsonl
On Windows, use quoted Windows paths instead. The CLI defaults to exact unless
the bank or --backend explicitly selects another backend. JSONL prepares one
bank and processes one new weight box per line. Array speed measurements do
not describe JSON parsing, file I/O or process startup. Invalid update lines
produce error records and exit code 2 after the stream; valid false decisions
are successful results. Check status as well as guaranteed.
Many thresholds on one unchanged box
Use cached sharp endpoints instead of repeated fresh-box evaluation:
from fractions import Fraction
from qzguard import NormalizedBox
box = NormalizedBox([1., 100.], [1., 1_000_000.], [0., 1.])
bounds = box.enclose()
assert bounds.lower[0] == Fraction(100, 101)
for threshold in (.9, .99, 1.):
cached = box.guard_from_bounds(threshold, relation='>=')
assert cached.guaranteed == box.guard(threshold, relation='>=').guaranteed
print(threshold, cached.guaranteed)
The cached path applies only while values, masses and bases stay unchanged.
Tiny boxes, boundary-heavy arithmetic, value-bank reconstruction and repeated
unchanged-box queries can favor exact methods. Consult PUBLIC_API_RESULTS.md
for measured scope and negative controls before making a runtime budget claim.