Download tests/test_verifier.py from codewithyug/certified-safe-neural-control: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/codewithyug/certified-safe-neural-control/resolve/main/tests/test_verifier.py
- Command line
-
hf download hf://codewithyug/certified-safe-neural-control/tests/test_verifier.py
-
curl -L -o test_verifier.py https://huggingface.co/codewithyug/certified-safe-neural-control/resolve/main/tests/test_verifier.py
1.08 kB
| """ | |
| Unit Tests for Formal Verifier (Branch-and-Bound / Regional Verification) | |
| """ | |
| import numpy as np | |
| import pytest | |
| from src.dynamics.toy_nav import DubinsCarSystem | |
| from src.cbf.network import NeuralCBF | |
| from src.verifier.symbolic_adapter import RegionalCBFVerifier | |
| def test_regional_cbf_verifier(): | |
| sys = DubinsCarSystem(tau=0.5, K=1.0, dt=0.02) | |
| cbf_net = NeuralCBF(state_dim=4, hidden_dims=[32, 32], activation="tanh") | |
| verifier = RegionalCBFVerifier(system=sys, cbf_net=cbf_net, alpha_cbf=1.0) | |
| # Define small test box | |
| box_min = np.array([2.0, -0.5, -0.5, 0.5], dtype=np.float32) | |
| box_max = np.array([3.0, 0.5, 0.5, 1.5], dtype=np.float32) | |
| lower_bound, cex = verifier.evaluate_box_lower_bound(box_min, box_max) | |
| assert isinstance(lower_bound, float) | |
| # Test small verification domain | |
| res = verifier.verify_domain( | |
| domain_min=box_min, | |
| domain_max=box_max, | |
| max_depth=3, | |
| max_boxes=10, | |
| time_limit_sec=2.0, | |
| ) | |
| assert "verified_volume_ratio" in res | |
| assert res["total_boxes_explored"] > 0 | |