Ejemplo n.º 1
0
def verify(dnn: OperationGraph, phi: Expression):
    logger = logging.getLogger(__name__)
    dnn = dnn.simplify()
    phi.networks[0].concretize(dnn)

    result = UNSAT
    property_extractor = ConvexPolytopeExtractor()
    with tempfile.TemporaryDirectory() as dirname:
        for prop in property_extractor.extract_from(phi):
            layers = prop.output_constraint.as_layers(
                prop.network, translator_error=ReluplexTranslatorError
            )
            input_interval = prop.input_constraint.as_hyperrectangle()
            nnet_file_name = to_nnet_file(
                input_interval,
                layers,
                dirname=dirname,
                translator_error=ReluplexTranslatorError,
            )
            logger.debug("Running reluplex")
            executor = CommandLineExecutor(
                "reluplex", f"{nnet_file_name}", verifier_error=ReluplexError
            )
            out, err = executor.run()
            logger.debug("Parsing results")
            result |= parse_results(out, err)
            if result == SAT:
                logger.debug("SAT! Validating counter example.")
                validate_counter_example(prop, out, err)
            if result == SAT or result == UNKNOWN:
                return result

    return result
Ejemplo n.º 2
0
def verify(dnn: OperationGraph, phi: Expression, **kwargs: Dict[str, Any]):
    logger = logging.getLogger(__name__)
    dnn = dnn.simplify()
    phi.networks[0].concretize(dnn)

    result = UNSAT
    property_extractor = ConvexPolytopeExtractor()
    with tempfile.TemporaryDirectory() as dirname:
        for prop in property_extractor.extract_from(phi):
            layers = prop.output_constraint.as_layers(
                prop.network,
                extra_layer_types=MIPVERIFY_LAYER_TYPES,
                translator_error=MIPVerifyTranslatorError,
            )
            input_interval = prop.input_constraint.as_hyperrectangle()
            mipverify_inputs = to_mipverify_inputs(
                input_interval,
                layers,
                dirname=dirname,
                translator_error=MIPVerifyTranslatorError,
            )
            logger.debug("Running mipverify")
            executor = CommandLineExecutor(
                "julia",
                mipverify_inputs["property_path"],
                verifier_error=MIPVerifyError,
            )
            out, err = executor.run()
            logger.debug("Parsing results")
            result |= parse_results(out, err)
            if result == SAT or result == UNKNOWN:
                return result

    return result
Ejemplo n.º 3
0
def verify(dnn: OperationGraph, phi: Expression):
    dnn = dnn.simplify()
    phi.networks[0].concretize(dnn)

    result = UNSAT
    property_extractor = ConvexPolytopeExtractor()
    with tempfile.TemporaryDirectory() as dirname:
        for prop in property_extractor.extract_from(phi):
            layers = prop.output_constraint.as_layers(
                prop.network,
                extra_layer_types=PLANET_LAYER_TYPES,
                translator_error=PlanetTranslatorError,
            )
            input_interval = prop.input_constraint.as_hyperrectangle()
            rlv_file_name = to_rlv_file(
                input_interval,
                layers,
                dirname=dirname,
                translator_error=PlanetTranslatorError,
            )
            executor = CommandLineExecutor("planet",
                                           f"{rlv_file_name}",
                                           verifier_error=PlanetError)
            out, err = executor.run()
            result |= parse_results(out, err)
            if result == SAT:
                validate_counter_example(prop, out, err)
            if result == SAT or result == UNKNOWN:
                return result

    return result
Ejemplo n.º 4
0
def verify(dnn: OperationGraph, phi: Expression):
    dnn = dnn.simplify()
    phi.networks[0].concretize(dnn)

    result = UNSAT
    property_extractor = HalfspacePolytopePropertyExtractor(
        HyperRectangle, HalfspacePolytope)
    with tempfile.TemporaryDirectory() as dirname:
        for prop in property_extractor.extract_from(~phi):
            if prop.input_constraint.num_variables > 1:
                raise PlanetTranslatorError(
                    "Unsupported network: More than 1 input variable")
            layers = as_layers(
                prop.suffixed_op_graph(),
                extra_layer_types=PLANET_LAYER_TYPES,
                translator_error=PlanetTranslatorError,
            )
            rlv_file_name = to_rlv_file(
                prop.input_constraint,
                layers,
                dirname=dirname,
                translator_error=PlanetTranslatorError,
            )
            executor = CommandLineExecutor("planet",
                                           f"{rlv_file_name}",
                                           verifier_error=PlanetError)
            out, err = executor.run()
            result |= parse_results(out, err)
            if result == SAT:
                validate_counter_example(prop, out, err)
            if result == SAT or result == UNKNOWN:
                return result

    return result
Ejemplo n.º 5
0
def verify(dnn: OperationGraph, phi: Expression, **kwargs: Dict[str, Any]):
    logger = logging.getLogger(__name__)
    dnn = dnn.simplify()
    phi.networks[0].concretize(dnn)

    result = UNSAT
    property_extractor = HalfspacePolytopePropertyExtractor(
        HyperRectangle, HalfspacePolytope)
    with tempfile.TemporaryDirectory() as dirname:
        for prop in property_extractor.extract_from(~phi):
            if prop.input_constraint.num_variables > 1:
                raise NeurifyTranslatorError(
                    "Unsupported network: More than 1 input variable")
            layers = as_layers(
                prop.suffixed_op_graph(),
                translator_error=NeurifyTranslatorError,
            )
            neurify_inputs = to_neurify_inputs(
                prop.input_constraint,
                layers,
                dirname=dirname,
                translator_error=NeurifyTranslatorError,
            )
            logger.debug("Running neurify")
            executor = CommandLineExecutor(
                "neurify",
                "-n",
                neurify_inputs["nnet_path"],
                "-x",
                neurify_inputs["input_path"],
                "-sl",
                "0.0000000000001",  # TODO: remove magic number
                "-I",
                neurify_inputs["input_interval_path"],
                "-v",
                *[f"--{k}={v}" for k, v in kwargs.items() if v is not None],
                verifier_error=NeurifyError,
            )
            out, err = executor.run()
            logger.debug("Parsing results")
            result |= parse_results(out, err)
            if result == SAT:
                logger.debug("SAT! Validating counter example.")
                validate_counter_example(prop, out, err)
            if result == SAT or result == UNKNOWN:
                return result

    return result
Ejemplo n.º 6
0
def verify(dnn: OperationGraph, phi: Expression, **kwargs: Dict[str, Any]):
    logger = logging.getLogger(__name__)
    dnn = dnn.simplify()
    phi.networks[0].concretize(dnn)

    result = UNSAT
    property_extractor = ConvexPolytopeExtractor()
    with tempfile.TemporaryDirectory() as dirname:
        for prop in property_extractor.extract_from(phi):
            layers = prop.output_constraint.as_layers(
                prop.network, translator_error=NeurifyTranslatorError)
            input_interval = prop.input_constraint.as_hyperrectangle()
            neurify_inputs = to_neurify_inputs(
                input_interval,
                layers,
                dirname=dirname,
                translator_error=NeurifyTranslatorError,
            )
            epsilon = neurify_inputs["epsilon"]
            logger.debug("Running neurify")
            executor = CommandLineExecutor(
                "neurify",
                "-n",
                neurify_inputs["nnet_path"],
                "-x",
                neurify_inputs["input_path"],
                "-sl",
                "0.000000000001",  # TODO: remove magic number
                f"--linf={epsilon}",
                "-v",
                *[f"--{k}={v}" for k, v in kwargs.items() if v is not None],
                verifier_error=NeurifyError,
            )
            out, err = executor.run()
            logger.debug("Parsing results")
            result |= parse_results(out, err)
            if result == SAT:
                logger.debug("SAT! Validating counter example.")
                validate_counter_example(prop, out, err)
            if result == SAT or result == UNKNOWN:
                return result

    return result
Ejemplo n.º 7
0
def verify(dnn: OperationGraph, phi: Expression, **kwargs: Dict[str, Any]):
    logger = logging.getLogger(__name__)
    dnn = dnn.simplify()
    phi.networks[0].concretize(dnn)

    result = UNSAT
    property_extractor = HalfspacePolytopePropertyExtractor(
        HyperRectangle, HalfspacePolytope)
    with tempfile.TemporaryDirectory() as dirname:
        for prop in property_extractor.extract_from(~phi):
            if prop.input_constraint.num_variables > 1:
                raise MIPVerifyTranslatorError(
                    "Unsupported network: More than 1 input variable")
            layers = as_layers(
                prop.suffixed_op_graph(),
                extra_layer_types=MIPVERIFY_LAYER_TYPES,
                translator_error=MIPVerifyTranslatorError,
            )
            mipverify_inputs = to_mipverify_inputs(
                prop.input_constraint,
                layers,
                dirname=dirname,
                translator_error=MIPVerifyTranslatorError,
            )
            logger.debug("Running mipverify")
            executor = CommandLineExecutor(
                "julia",
                mipverify_inputs["property_path"],
                verifier_error=MIPVerifyError,
            )
            out, err = executor.run()
            logger.debug("Parsing results")
            result |= parse_results(out, err)
            if result == SAT or result == UNKNOWN:
                return result

    return result