def test_statistics():
    """
    Test that a query generated from Maraboupy can be saved and loaded correctly and return sat
    """
    ipq = MarabouCore.InputQuery()
    ipq.setNumberOfVariables(1)
    ipq.setLowerBound(0, -1)
    ipq.setUpperBound(0, 1)

    opt = createOptions(verbosity = 0) # Turn off printing
    exitCode, vals, stats = MarabouCore.solve(ipq, opt, "")
    assert(stats.getUnsignedAttribute(MarabouCore.StatisticsUnsignedAttribute.NUM_SPLITS) == 0)
    assert(stats.getLongAttribute(MarabouCore.StatisticsLongAttribute.NUM_MAIN_LOOP_ITERATIONS) == 2)
    assert(stats.getDoubleAttribute(MarabouCore.StatisticsDoubleAttribute.MAX_DEGRADATION) == 0)
 def solve(self, filename="", timeout=0):
     """
     Function to solve query represented by this network
     Arguments:
         filename: (string) path to redirect output to
     Returns:
         vals: (dict: int->float) empty if UNSAT, else the
               satisfying assignment to the input and output variables
         stats: (Statistics) the Statistics object as defined in Marabou
     """
     options = createOptions(timeoutInSeconds=timeout)
     vals, stats = MarabouCore.solve(self.ipq, options, filename)
     assignment = []
     if len(vals) > 0:
         for i in range(self.ipq.getNumInputVariables()):
             assignment.append("input {} = {}".format(
                 i, vals[self.ipq.inputVariableByIndex(i)]))
         for i in range(self.ipq.getNumOutputVariables()):
             assignment.append("Output {} = {}".format(
                 i, vals[self.ipq.outputVariableByIndex(i)]))
     return [assignment, stats]
Beispiel #3
0
equation1 = MarabouCore.Equation()
equation1.addAddend(1, 0)
equation1.addAddend(-1, 1)
equation1.setScalar(0)
inputQuery.addEquation(equation1)

equation2 = MarabouCore.Equation()
equation2.addAddend(1, 0)
equation2.addAddend(1, 3)
equation2.setScalar(0)
inputQuery.addEquation(equation2)

equation3 = MarabouCore.Equation()
equation3.addAddend(1, 2)
equation3.addAddend(1, 4)
equation3.addAddend(-1, 5)
equation3.setScalar(0)
inputQuery.addEquation(equation3)

MarabouCore.addReluConstraint(inputQuery, 1, 2)
MarabouCore.addReluConstraint(inputQuery, 3, 4)

options = createOptions()
vars1, stats1 = MarabouCore.solve(inputQuery, options, "")
if len(vars1) > 0:
    print("SAT")
    print(vars1)
else:
    print("UNSAT")
Beispiel #4
0
def test_dump_query():
    network = define_network()
    options = createOptions()
    MarabouCore.solve(network, options, "")
    network.dump()
Beispiel #5
0
def test_solve_partial_arguments():
    network = define_network()
    options = createOptions()
    MarabouCore.solve(network, options)
Beispiel #6
0
# Supress warnings caused by tensorflow
import warnings

warnings.filterwarnings('ignore', category=DeprecationWarning)
warnings.filterwarnings('ignore', category=PendingDeprecationWarning)

import pytest
from maraboupy import MarabouCore
from maraboupy.Marabou import createOptions

# Global settings
OPT = createOptions(verbosity=0)  # Turn off printing
LARGE = 100.0  # Large value for defining bounds


def test_solve_partial_arguments():
    """
    This function tests that MarabouCore.solve can be called with partial arguments, 
    and checks that an UNSAT query is solved correctly.
    """
    ipq = define_ipq(-2.0)
    # Test partial arguments to solve
    vals, stats = MarabouCore.solve(ipq, OPT)
    # Assert that Marabou returned UNSAT
    assert not stats.hasTimedOut()
    assert len(vals) == 0


def test_dump_query():
    """
    This function tests that MarabouCore.solve can be called with all arguments and