File size: 1,077 Bytes
0210a65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
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