def __init__(self, spec, domain=AbstractDomain.SYMBOLIC2, difference=0.25, widening=2, cpu=None, analysis=True): super().__init__() self.spec = spec self.domain = domain self.difference = difference self.widening = widening self.analysis = analysis self.cpu = cpu self.inputs: Set[VariableIdentifier] = None # input variables self.outputs: Set[VariableIdentifier] = None # output variables self.activations: Set[Node] = None # activations self.splits: Dict[int, Dict[VariableIdentifier, PyTexpr1]] = None # partitioning information self.relus: Dict[VariableIdentifier, Node] = None # relus information self.man1: PyManager = PyBoxMPQManager() self.man2: PyManager = PyPolkaMPQstrictManager() min_int = (-ctypes.c_uint(-1).value) // 2 self.man2.manager.contents.option.funopt[ FunId.AP_FUNID_IS_BOTTOM].algorithm = min_int self.man2.manager.contents.option.funopt[ FunId.AP_FUNID_IS_TOP].algorithm = min_int self.man2.manager.contents.option.funopt[ FunId.AP_FUNID_MEET].algorithm = min_int self.man2.manager.contents.option.funopt[ FunId.AP_FUNID_JOIN].algorithm = min_int self.man2.manager.contents.option.funopt[ FunId.AP_FUNID_FORGET_ARRAY].algorithm = min_int
def test_bound_variable(self): e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')]) man: PyManager = PyBoxMPQManager() variables = [PyVar('x0'), PyVar('y')] intervals = [PyMPQInterval(-3, 2), PyMPQInterval(-2, 2, 1, 1)] b = PyBox(man, e, variables=variables, intervals=intervals) self.assertEqual(str(b.bound_variable(PyVar('y'))), '[-2,2]')
def test_forget(self): e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')]) man: PyManager = PyBoxMPQManager() variables = [PyVar('x0'), PyVar('y')] intervals = [PyMPQInterval(-3, 2), PyMPQInterval(-2, 2, 1, 1)] b = PyBox(man, e, variables=variables, intervals=intervals) self.assertEqual(str(b.forget([PyVar('y')])), '1·x0 + 3 >= 0 ∧ -1·x0 + 2 >= 0')
def __init__(self, spec, domain=AbstractDomain.SYMBOLIC2, log=False): super().__init__() self.spec = spec self.domain = domain self.outputs: Set[VariableIdentifier] = None self.man1: PyManager = PyBoxMPQManager() # legacy, for symbolic domain self.log = log
def test_bound_texpr(self): e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')]) man: PyManager = PyBoxMPQManager() variables = [PyVar('x0'), PyVar('y')] intervals = [PyMPQInterval(-3, 2), PyMPQInterval(-2, 2, 1, 1)] b = PyBox(man, e, variables=variables, intervals=intervals) x0 = PyTexpr1.var(e, PyVar('x0')) x1 = PyTexpr1.var(e, PyVar('y')) add = PyTexpr1.binop(TexprOp.AP_TEXPR_ADD, x0, x1, TexprRtype.AP_RTYPE_REAL, TexprRdir.AP_RDIR_RND) self.assertEqual(str(b.bound_texpr(add)), '[-5,4]')
def test_top(self): e = PyEnvironment([PyVar('x0'), PyVar('y')], [PyVar('z')]) man: PyManager = PyBoxMPQManager() self.assertFalse(PyBox.bottom(man, e).is_top()) b1 = PyBox(man, e, variables=[PyVar('x0')], intervals=[PyDoubleInterval(-2.5, 2.5)]) self.assertFalse(b1.is_bottom()) b2 = PyBox(man, e, variables=[PyVar('y')], intervals=[PyMPQInterval(-5, 5, 2, 2)]) self.assertFalse(b2.is_bottom()) b3 = PyBox(man, e, variables=[PyVar('z')], intervals=[PyMPFRInterval(-2.5, 2.5)]) self.assertFalse(b3.is_bottom()) self.assertTrue(PyBox.top(man, e).is_top())
def __init__(self, spec, domain=AbstractDomain.SYMBOLIC3, steps=None, minL=None, startL=0.25, startU=2, maxU=None, cpu=None, analysis=True): super().__init__() self.spec = spec self.domain = domain self.steps = (1, 1) if steps is None else steps self.minL = startL if minL is None else minL self.startL = startL self.startU = startU self.maxU = startU if maxU is None else maxU self.analysis = analysis self.cpu = cpu self.inputs: Set[VariableIdentifier] = None # input variables self.outputs: Set[VariableIdentifier] = None # output variables self.activations: Set[Node] = None # activations self.splits: Dict[int, Dict[VariableIdentifier, PyTexpr1]] = None # partitioning information self.relus: Dict[VariableIdentifier, Node] = None # relus information self.man1: PyManager = PyBoxMPQManager() self.man2: PyManager = PyPolkaMPQstrictManager() min_int = (-ctypes.c_uint(-1).value) // 2 self.man2.manager.contents.option.funopt[ FunId.AP_FUNID_IS_BOTTOM].algorithm = min_int self.man2.manager.contents.option.funopt[ FunId.AP_FUNID_IS_TOP].algorithm = min_int self.man2.manager.contents.option.funopt[ FunId.AP_FUNID_MEET].algorithm = min_int self.man2.manager.contents.option.funopt[ FunId.AP_FUNID_JOIN].algorithm = min_int self.man2.manager.contents.option.funopt[ FunId.AP_FUNID_FORGET_ARRAY].algorithm = min_int