codewithyug's picture
Release: Certified-Safe Neural Control MODEL v1.0
0210a65 verified
Raw History Blame Contribute Delete
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