Exemple #1
0
def configure_environment(config_filename, environment):
    """
    Reads a configuration file from the given path and configures the
    given environment accordingly.
    """
    factory = environment.factory

    if not os.path.exists(config_filename):
        raise IOError("File '%s' does not exists." % config_filename)

    # We do not use variable inside the config file
    config = cp.RawConfigParser()
    config.read(config_filename)

    new_solvers_sections = [
        s for s in config.sections() if s.lower().startswith("smtlibsolver ")
    ]

    for s in new_solvers_sections:
        name = s[len("smtlibsolver "):]

        cmd = config.get(s, "command")
        assert cmd is not None, ("Missing 'command' value in definition"
                                 "of '%s' solver" % name)

        logics_string = config.get(s, "logics")
        if logics_string is None:
            warn("Missing 'logics' value in definition of '%s' solver" % name)
            continue

        logics = [get_logic_by_name(l) for l in logics_string.split()]

        factory.add_generic_solver(name, cmd.split(), logics)

    if "global" in config.sections():
        infix = config.get("global", "use_infix_notation")
        pref_list = config.get("global", "solver_preference_list")
        if infix is not None:
            if infix.lower() == "true":
                environment.enable_infix_notation = True
            elif infix.lower() == "false":
                environment.enable_infix_notation = True
            else:
                warn("Unknown value for 'use_infix_notation': %s" % infix)

        if pref_list != None:
            prefs = pref_list.split()
            for s in prefs:
                if s not in factory.all_solvers():
                    warn("Unknown solver '%s' in solver_preference_list" % s)

            for s in factory.all_solvers():
                if s not in prefs:
                    warn("Solver '%s' is not in the preference list, "\
                         "and will be disabled." % s)

            factory.set_solver_preference_list(prefs)
Exemple #2
0
def configure_environment(config_filename, environment):
    """
    Reads a configuration file from the given path and configures the
    given environment accordingly.
    """
    factory = environment.factory

    if not os.path.exists(config_filename):
        raise IOError("File '%s' does not exists." % config_filename)

    # We do not use variable inside the config file
    config = cp.RawConfigParser()
    config.read(config_filename)

    new_solvers_sections = [s for s in config.sections()
                            if s.lower().startswith("smtlibsolver ")]

    for s in new_solvers_sections:
        name = s[len("smtlibsolver "):]

        cmd = config.get(s, "command")
        assert cmd is not None, ("Missing 'command' value in definition"
                                 "of '%s' solver" % name)

        logics_string = config.get(s, "logics")
        if logics_string is None:
            warn("Missing 'logics' value in definition of '%s' solver" % name)
            continue

        logics = [get_logic_by_name(l) for l in logics_string.split()]

        factory.add_generic_solver(name, cmd.split(), logics)


    if "global" in config.sections():
        infix = config.get("global", "use_infix_notation")
        pref_list = config.get("global", "solver_preference_list")
        if infix is not None:
            if infix.lower() == "true":
                environment.enable_infix_notation = True
            elif infix.lower() == "false":
                environment.enable_infix_notation = True
            else:
                warn("Unknown value for 'use_infix_notation': %s" % infix)

        if pref_list is not None:
            prefs = pref_list.split()
            for s in prefs:
                if s not in factory.all_solvers():
                    warn("Unknown solver '%s' in solver_preference_list" % s)

            for s in factory.all_solvers():
                if s not in prefs:
                    warn("Solver '%s' is not in the preference list, "\
                         "and will be disabled." % s)

            factory.set_solver_preference_list(prefs)
Exemple #3
0
    def _cmd_set_logic(self, current, tokens):
        elements = self.parse_atoms(tokens, current, 1)

        name = elements[0]
        try:
            self.logic = get_logic_by_name(name)
            return SmtLibCommand(current, [self.logic])
        except UndefinedLogicError:
            warn("Unknown logic '" + name + "'. Ignoring set-logic command.")
            return SmtLibCommand(current, [None])
Exemple #4
0
    def _cmd_set_logic(self, current, tokens):
        elements = self.parse_atoms(tokens, current, 1)

        name = elements[0]
        try:
            self.logic = get_logic_by_name(name)
            return SmtLibCommand(current, [self.logic])
        except UndefinedLogicError:
            warn("Unknown logic '" + name + \
                 "'. Ignoring set-logic command.")
            return SmtLibCommand(current, [None])
Exemple #5
0
 def test_get_logic_by_name_error(self):
     with self.assertRaises(UndefinedLogicError):
         get_logic_by_name("SuperLogic")
Exemple #6
0
 def test_get_logic_by_name(self):
     for l in pysmt.logics.LOGICS:
         l_out = get_logic_by_name(l.name)
         self.assertEqual(l_out, l,
                           "Expecting %s, got %s instead" % \
                           (l, l_out))
Exemple #7
0
 def test_get_logic_by_name_error(self):
     with self.assertRaises(UndefinedLogicError):
         get_logic_by_name("SuperLogic")
Exemple #8
0
 def test_get_logic_by_name(self):
     for l in pysmt.logics.LOGICS:
         l_out = get_logic_by_name(l.name)
         self.assertEqual(l_out, l,
                           "Expecting %s, got %s instead" % \
                           (l, l_out))
Exemple #9
0
    def get_command(self, tokens):
        """Builds an SmtLibCommand instance out of a parsed term."""

        while True:
            self.consume_opening(tokens, "<main>")
            current = next(tokens)
            if current in [smtcmd.SET_INFO, smtcmd.SET_OPTION]:
                elements = self.parse_atoms(tokens, current, 2)
                yield SmtLibCommand(current, elements)

            elif current == smtcmd.ASSERT:
                expr = self.get_expression(tokens)
                self.consume_closing(tokens, current)
                yield SmtLibCommand(current, [expr])

            elif current == smtcmd.CHECK_SAT:
                self.parse_atoms(tokens, current, 0)
                yield SmtLibCommand(current, [])

            elif current == smtcmd.PUSH:
                elements = self.parse_atoms(tokens, current, 0, 1)

                levels = 1
                if len(elements) > 0:
                    levels = int(elements[0])
                yield SmtLibCommand(current, [levels])

            elif current == smtcmd.POP:
                elements = self.parse_atoms(tokens, current, 0, 1)

                levels = 1
                if len(elements) > 0:
                    levels = int(elements[0])
                yield SmtLibCommand(current, [levels])

            elif current == smtcmd.EXIT:
                self.parse_atoms(tokens, current, 0)
                yield SmtLibCommand(current, [])

            elif current == smtcmd.SET_LOGIC:
                elements = self.parse_atoms(tokens, current, 1)

                name = elements[0]
                try:
                    self.logic = get_logic_by_name(name)
                    yield SmtLibCommand(current, [self.logic])
                except UndefinedLogicError:
                    warn("Unknown logic '" + name + "'. Ignoring set-logic command.")
                    yield SmtLibCommand(current, [None])

            elif current == smtcmd.DECLARE_CONST:
                elements = self.parse_atoms(tokens, current, 2)

                (var, typename) = elements
                v = self._get_var(var, typename)
                self.cache.bind(var, v)
                yield SmtLibCommand(current, [v])

            elif current == smtcmd.GET_VALUE:
                params = self.parse_expr_list(tokens, current)
                self.consume_closing(tokens, current)
                yield SmtLibCommand(current, params)

            elif current == smtcmd.DECLARE_FUN:
                var = self.parse_atom(tokens, current)
                params = self.parse_params(tokens, current)
                typename = self.parse_type(tokens, current)
                self.consume_closing(tokens, current)

                v = self._get_var(var, typename, params)
                if v.symbol_type().is_function_type():
                    self.cache.bind(var, functools.partial(self._function_call_helper, v))
                else:
                    self.cache.bind(var, v)
                yield SmtLibCommand(current, [v])

            elif current == smtcmd.DEFINE_FUN:
                var = self.parse_atom(tokens, current)
                params = self.parse_params(tokens, current)
                self.parse_type(tokens, current)
                ebody = self.get_expression(tokens)
                self.consume_closing(tokens, current)

                formal = []
                for k in params:
                    (x, t) = k[0], k[1]
                    v = self._get_var(x, t)
                    self.cache.bind(x, v)
                    formal.append(v)

                for x in formal:
                    self.cache.unbind(x.symbol_name())

                self.cache.define(var, formal, ebody)
                yield SmtLibCommand(current, [var, formal, ebody])

            else:
                raise UnknownSmtLibCommandError(current)
Exemple #10
0
    def get_command(self, tokens):
        """Builds an SmtLibCommand instance out of a parsed term."""

        while True:
            self.consume_opening(tokens, "<main>")
            current = next(tokens)
            if current in [smtcmd.SET_INFO, smtcmd.SET_OPTION]:
                elements = self.parse_atoms(tokens, current, 2)
                yield SmtLibCommand(current, elements)

            elif current == smtcmd.ASSERT:
                expr = self.get_expression(tokens)
                self.consume_closing(tokens, current)
                yield SmtLibCommand(current, [expr])

            elif current == smtcmd.CHECK_SAT:
                self.parse_atoms(tokens, current, 0)
                yield SmtLibCommand(current, [])

            elif current == smtcmd.PUSH:
                elements = self.parse_atoms(tokens, current, 0, 1)

                levels = 1
                if len(elements) > 0:
                    levels = int(elements[0])
                yield SmtLibCommand(current, [levels])

            elif current == smtcmd.POP:
                elements = self.parse_atoms(tokens, current, 0, 1)

                levels = 1
                if len(elements) > 0:
                    levels = int(elements[0])
                yield SmtLibCommand(current, [levels])

            elif current == smtcmd.EXIT:
                self.parse_atoms(tokens, current, 0)
                yield SmtLibCommand(current, [])

            elif current == smtcmd.SET_LOGIC:
                elements = self.parse_atoms(tokens, current, 1)

                name = elements[0]
                try:
                    self.logic = get_logic_by_name(name)
                    yield SmtLibCommand(current, [self.logic])
                except UndefinedLogicError:
                    warn("Unknown logic '" + name + \
                         "'. Ignoring set-logic command.")
                    yield SmtLibCommand(current, [None])

            elif current == smtcmd.DECLARE_CONST:
                elements = self.parse_atoms(tokens, current, 2)

                (var, typename) = elements
                v = self._get_var(var, typename)
                self.cache.bind(var, v)
                yield SmtLibCommand(current, [v])

            elif current == smtcmd.GET_VALUE:
                params = self.parse_expr_list(tokens, current)
                self.consume_closing(tokens, current)
                yield SmtLibCommand(current, params)

            elif current == smtcmd.DECLARE_FUN:
                var = self.parse_atom(tokens, current)
                params = self.parse_params(tokens, current)
                typename = self.parse_atom(tokens, current)
                self.consume_closing(tokens, current)

                v = self._get_var(var, typename, params)
                if v.symbol_type().is_function_type():
                    self.cache.bind(var, \
                            functools.partial(self._function_call_helper, v))
                else:
                    self.cache.bind(var, v)
                yield SmtLibCommand(current, [v])

            elif current == smtcmd.DEFINE_FUN:
                var = self.parse_atom(tokens, current)
                params = self.parse_params(tokens, current)
                typename = self.parse_atom(tokens, current)
                ebody = self.get_expression(tokens)
                self.consume_closing(tokens, current)

                formal = []
                for k in params:
                    (x, t) = k[0], k[1]
                    v = self._get_var(x, t)
                    self.cache.bind(x, v)
                    formal.append(v)

                for x in formal:
                    self.cache.unbind(x.symbol_name())

                self.cache.define(var, formal, ebody)
                yield SmtLibCommand(current, [var, formal, ebody])

            else:
                raise UnknownSmtLibCommandError(current)