3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 09:05:31 +00:00

working on new parameter framework

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2012-12-01 15:54:34 -08:00
parent be5f933201
commit 589f096e6e
36 changed files with 436 additions and 377 deletions

View file

@ -36,9 +36,45 @@ namespace api {
};
extern "C" {
void Z3_API Z3_global_param_set(Z3_string param_id, Z3_string param_value) {
memory::initialize(UINT_MAX);
LOG_Z3_global_param_set(param_id, param_value);
try {
gparams::set(param_id, param_value);
}
catch (z3_exception & ex) {
// The error handler is only available for contexts
// Just throw a warning.
std::ostringstream buffer;
buffer << "Error setting " << param_id << ", " << ex.msg();
warning_msg(buffer.str().c_str());
}
}
std::string g_Z3_global_param_get_buffer;
Z3_bool_opt Z3_API Z3_global_param_get(Z3_string param_id, Z3_string_ptr param_value) {
memory::initialize(UINT_MAX);
LOG_Z3_global_param_get(param_id, param_value);
*param_value = 0;
try {
g_Z3_global_param_get_buffer = gparams::get_value(param_id);
*param_value = g_Z3_global_param_get_buffer.c_str();
return Z3_TRUE;
}
catch (z3_exception & ex) {
// The error handler is only available for contexts
// Just throw a warning.
std::ostringstream buffer;
buffer << "Error setting " << param_id << ", " << ex.msg();
warning_msg(buffer.str().c_str());
return Z3_FALSE;
}
}
Z3_config Z3_API Z3_mk_config() {
memory::initialize(UINT_MAX);
LOG_Z3_mk_config();
memory::initialize(0);
Z3_config r = reinterpret_cast<Z3_config>(alloc(api::config_params));
RETURN_Z3(r);
}
@ -49,35 +85,19 @@ extern "C" {
}
void Z3_API Z3_set_param_value(Z3_config c, char const * param_id, char const * param_value) {
// REMARK: we don't need Z3_config anymore
try {
LOG_Z3_set_param_value(c, param_id, param_value);
gparams::set(param_id, param_value);
}
catch (gparams::exception & ex) {
// The error handler was not set yet.
// Just throw a warning.
std::ostringstream buffer;
buffer << "Error setting " << param_id << ", " << ex.msg();
warning_msg(buffer.str().c_str());
}
LOG_Z3_set_param_value(c, param_id, param_value);
// PARAM-TODO save the parameter
}
void Z3_API Z3_update_param_value(Z3_context c, Z3_string param_id, Z3_string param_value) {
Z3_TRY;
LOG_Z3_update_param_value(c, param_id, param_value);
RESET_ERROR_CODE();
gparams::set(param_id, param_value);
// TODO: set memory limits
// memory::set_high_watermark(static_cast<size_t>(mk_c(c)->fparams().m_memory_high_watermark)*1024*1024);
// memory::set_max_size(static_cast<size_t>(mk_c(c)->fparams().m_memory_max_size)*1024*1024);
Z3_CATCH;
// NOOP in the current version
}
Z3_bool Z3_API Z3_get_param_value(Z3_context c, Z3_string param_id, Z3_string* param_value) {
LOG_Z3_get_param_value(c, param_id, param_value);
// TODO: we don't really have support for that anymore.
return false;
return Z3_FALSE;
}
};

View file

@ -344,7 +344,7 @@ extern "C" {
std::istream& s) {
ast_manager& m = mk_c(c)->m();
dl_collected_cmds coll(m);
cmd_context ctx(&mk_c(c)->fparams(), false, &m);
cmd_context ctx(false, &m);
install_dl_collect_cmds(coll, ctx);
ctx.set_ignore_check(true);
if (!parse_smt2_commands(ctx, s)) {

View file

@ -25,6 +25,7 @@ Revision History:
#include"model.h"
#include"model_v2_pp.h"
#include"model_smt2_pp.h"
#include"model_params.hpp"
extern "C" {
@ -488,7 +489,8 @@ extern "C" {
Z3_model m,
Z3_ast t,
Z3_ast * v) {
return Z3_model_eval(c, m, t, mk_c(c)->fparams().m_model_completion, v);
model_params p;
return Z3_model_eval(c, m, t, p.completion(), v);
}
Z3_bool Z3_API Z3_eval_func_decl(Z3_context c,
@ -660,7 +662,8 @@ extern "C" {
result.resize(result.size()-1);
}
else {
model_v2_pp(buffer, *(to_model_ref(m)), mk_c(c)->fparams().m_model_partial);
model_params p;
model_v2_pp(buffer, *(to_model_ref(m)), p.partial());
result = buffer.str();
}
return mk_c(c)->mk_external_string(result);

View file

@ -296,7 +296,7 @@ extern "C" {
Z3_symbol const decl_names[],
Z3_func_decl const decls[]) {
Z3_TRY;
cmd_context ctx(&mk_c(c)->fparams(), false, &(mk_c(c)->m()));
cmd_context ctx(false, &(mk_c(c)->m()));
ctx.set_ignore_check(true);
if (exec) {
ctx.set_solver(alloc(z3_context_solver, *mk_c(c)));
@ -362,7 +362,7 @@ extern "C" {
Z3_symbol decl_names[],
Z3_func_decl decls[]) {
Z3_TRY;
cmd_context ctx(&mk_c(c)->fparams(), false, &(mk_c(c)->m()));
cmd_context ctx(false, &(mk_c(c)->m()));
std::string s(str);
std::istringstream is(s);
// No logging for this one, since it private.

View file

@ -169,28 +169,6 @@ class Context:
"""
Z3_interrupt(self.ref())
def set(self, *args, **kws):
"""Set global configuration options.
Z3 command line options can be set using this method.
The option names can be specified in different ways:
>>> ctx = Context()
>>> ctx.set('WELL_SORTED_CHECK', True)
>>> ctx.set(':well-sorted-check', True)
>>> ctx.set(well_sorted_check=True)
"""
if __debug__:
_z3_assert(len(args) % 2 == 0, "Argument list must have an even number of elements.")
for key, value in kws.iteritems():
Z3_update_param_value(self.ctx, str(key).upper(), _to_param_value(value))
prev = None
for a in args:
if prev == None:
prev = a
else:
Z3_update_param_value(self.ctx, str(prev), _to_param_value(a))
prev = None
# Global Z3 context
_main_ctx = None
@ -221,15 +199,37 @@ def _get_ctx(ctx):
return ctx
def set_option(*args, **kws):
"""Update parameters of the global context `main_ctx()`, and global configuration options of Z3Py. See `Context.set()`.
"""Set Z3 global (or module) parameters.
>>> set_option(precision=10)
"""
if __debug__:
_z3_assert(len(args) % 2 == 0, "Argument list must have an even number of elements.")
new_kws = {}
for k, v in kws.iteritems():
if not set_pp_option(k, v):
new_kws[k] = v
main_ctx().set(*args, **new_kws)
for key, value in new_kws.iteritems():
Z3_global_param_set(str(key).upper(), _to_param_value(value))
prev = None
for a in args:
if prev == None:
prev = a
else:
Z3_global_param_set(str(prev), _to_param_value(a))
prev = None
def get_option(name):
"""Return the value of a Z3 global (or module) parameter
>>> get_option('nlsat.reorder')
true
"""
ptr = (ctypes.c_char_p * 1)()
if Z3_global_param_get(str(name), ptr):
r = str(ptr[0])
return r
raise Z3Exception("failed to retrieve value for '%s'" % name)
#########################################
#

View file

@ -1233,25 +1233,82 @@ extern "C" {
#endif // CAMLIDL
#ifdef CorML3
/**
@name Configuration
*/
/*@{*/
/**
\brief Set a global (or module) parameter.
This setting is shared by all Z3 contexts.
When a Z3 module is initialized it will use the value of these parameters
when Z3_params objects are not provided.
The name of parameter can be composed of characters [a-z][A-Z], digits [0-9], '-' and '_'.
The character '.' is a delimiter (more later).
The parameter names are case-insensitive. The character '-' should be viewed as an "alias" for '_'.
Thus, the following parameter names are considered equivalent: "pp.decimal-precision" and "PP.DECIMAL_PRECISION".
This function can be used to set parameters for a specific Z3 module.
This can be done by using <module-name>.<parameter-name>.
For example:
Z3_global_param_set('pp.decimal', 'true')
will set the parameter "decimal" in the module "pp" to true.
def_API('Z3_global_param_set', VOID, (_in(STRING), _in(STRING)))
*/
void Z3_API Z3_global_param_set(__in Z3_string param_id, __in Z3_string param_value);
/**
\brief Get a global (or module) parameter.
Returns \mlonly \c None \endmlonly \conly \c Z3_FALSE
if the parameter value does not exist.
\sa Z3_global_param_set
The caller must invoke #Z3_global_param_del_value to delete the value returned at \c param_value.
\remark This function cannot be invoked simultaneously from different threads without synchronization.
The result string stored in param_value is stored in shared location.
def_API('Z3_global_param_get', BOOL, (_in(STRING), _out(STRING)))
*/
Z3_bool_opt Z3_API Z3_global_param_get(__in Z3_string param_id, __out_opt Z3_string_ptr param_value);
/*@}*/
/**
@name Create configuration
*/
/*@{*/
/**
\brief Create a configuration.
\brief Create a configuration object for the Z3 context object.
Configurations are created in order to assign parameters prior to creating
contexts for Z3 interaction. For example, if the users wishes to use model
contexts for Z3 interaction. For example, if the users wishes to use proof
generation, then call:
\ccode{Z3_set_param_value(cfg\, "MODEL"\, "true")}
\ccode{Z3_set_param_value(cfg\, "proof"\, "true")}
\mlonly \remark Consider using {!mk_context_x} instead of using
explicit configuration objects. The function {!mk_context_x}
receives an array of string pairs. This array represents the
configuration options. \endmlonly
\remark In previous versions of Z3, the \c Z3_config was used to store
global and module configurations. Now, we should use \c Z3_global_param_set.
The following parameters can be set:
- proof (Boolean) Enable proof generation
- debug_ref_count (Boolean) Enable debug support for Z3_ast reference counting
- trace (Boolean) Tracing support for VCC
- trace_file_name (String) Trace out file for VCC traces
\sa Z3_set_param_value
\sa Z3_del_config
@ -1271,18 +1328,14 @@ extern "C" {
/**
\brief Set a configuration parameter.
The list of all configuration parameters can be obtained using the Z3 executable:
\verbatim
z3.exe -ini?
\endverbatim
The following parameters can be set for
\sa Z3_mk_config
def_API('Z3_set_param_value', VOID, (_in(CONFIG), _in(STRING), _in(STRING)))
*/
void Z3_API Z3_set_param_value(__in Z3_config c, __in Z3_string param_id, __in Z3_string param_value);
/*@}*/
#endif
@ -1367,33 +1420,19 @@ extern "C" {
#endif
/**
\brief Update a mutable configuration parameter.
\brief This is a deprecated function. This is a NOOP in the current version of Z3.
The list of all configuration parameters can be obtained using the Z3 executable:
\verbatim
z3.exe -ini?
\endverbatim
Only a few configuration parameters are mutable once the context is created.
The error handler is invoked when trying to modify an immutable parameter.
\conly \sa Z3_set_param_value
\mlonly \sa Z3_mk_context \endmlonly
\deprecated Use #Z3_global_param_set.
def_API('Z3_update_param_value', VOID, (_in(CONTEXT), _in(STRING), _in(STRING)))
*/
void Z3_API Z3_update_param_value(__in Z3_context c, __in Z3_string param_id, __in Z3_string param_value);
/**
\brief Get a configuration parameter.
\brief This is a deprecated function. This is a NOOP in the current version of Z3.
It always return Z3_FALSE.
Returns \mlonly \c None \endmlonly \conly \c Z3_FALSE
if the parameter value does not exist.
\conly \sa Z3_mk_config
\conly \sa Z3_set_param_value
\mlonly \sa Z3_mk_context \endmlonly
\deprecated Use #Z3_global_param_get
def_API('Z3_get_param_value', BOOL, (_in(CONTEXT), _in(STRING), _out(STRING)))
*/