Z3
Public Member Functions | Data Fields
Context Class Reference

Public Member Functions

def __init__ (self, args, kws)
 
def __del__ (self)
 
def ref (self)
 
def interrupt (self)
 

Data Fields

 lib
 
 ctx
 

Detailed Description

A Context manages all other Z3 objects, global configuration options, etc.

Z3Py uses a default global context. For most applications this is sufficient.
An application may use multiple Z3 contexts. Objects created in one context
cannot be used in another one. However, several objects may be "translated" from
one context to another. It is not safe to access Z3 objects from multiple threads.
The only exception is the method `interrupt()` that can be used to interrupt() a long
computation.
The initialization method receives global configuration options for the new context.

Definition at line 145 of file z3py.py.

Constructor & Destructor Documentation

§ __init__()

def __init__ (   self,
  args,
  kws 
)

Definition at line 156 of file z3py.py.

156  def __init__(self, *args, **kws):
157  if __debug__:
158  _z3_assert(len(args) % 2 == 0, "Argument list must have an even number of elements.")
159  conf = Z3_mk_config()
160  for key in kws:
161  value = kws[key]
162  Z3_set_param_value(conf, str(key).upper(), _to_param_value(value))
163  prev = None
164  for a in args:
165  if prev is None:
166  prev = a
167  else:
168  Z3_set_param_value(conf, str(prev), _to_param_value(a))
169  prev = None
170  self.lib = lib()
171  self.ctx = Z3_mk_context_rc(conf)
172  Z3_set_ast_print_mode(self.ctx, Z3_PRINT_SMTLIB2_COMPLIANT)
173  lib().Z3_set_error_handler.restype = None
174  lib().Z3_set_error_handler.argtypes = [ContextObj, _error_handler_fptr]
175  lib().Z3_set_error_handler(self.ctx, _Z3Python_error_handler)
176  Z3_del_config(conf)
177 
Z3_context Z3_API Z3_mk_context_rc(Z3_config c)
Create a context using the given configuration. This function is similar to Z3_mk_context. However, in the context returned by this function, the user is responsible for managing Z3_ast reference counters. Managing reference counters is a burden and error-prone, but allows the user to use the memory more efficiently. The user must invoke Z3_inc_ref for any Z3_ast returned by Z3, and Z3_dec_ref whenever the Z3_ast is not needed anymore. This idiom is similar to the one used in BDD (binary decision diagrams) packages such as CUDD.
void Z3_API Z3_set_ast_print_mode(Z3_context c, Z3_ast_print_mode mode)
Select mode for the format used for pretty-printing AST nodes.
void Z3_API Z3_del_config(Z3_config c)
Delete the given configuration object.
void Z3_API Z3_set_error_handler(Z3_context c, Z3_error_handler h)
Register a Z3 error handler.
Z3_config Z3_API Z3_mk_config(void)
Create a configuration object for the Z3 context object.
void Z3_API Z3_set_param_value(Z3_config c, Z3_string param_id, Z3_string param_value)
Set a configuration parameter.

§ __del__()

def __del__ (   self)

Definition at line 178 of file z3py.py.

178  def __del__(self):
179  self.lib.Z3_del_context(self.ctx)
180  self.ctx = None
181 
void Z3_API Z3_del_context(Z3_context c)
Delete the given logical context.

Member Function Documentation

§ interrupt()

def interrupt (   self)
Interrupt a solver performing a satisfiability test, a tactic processing a goal, or simplify functions.

This method can be invoked from a thread different from the one executing the
interruptable procedure.

Definition at line 186 of file z3py.py.

186  def interrupt(self):
187  """Interrupt a solver performing a satisfiability test, a tactic processing a goal, or simplify functions.
188 
189  This method can be invoked from a thread different from the one executing the
190  interruptable procedure.
191  """
192  Z3_interrupt(self.ref())
193 
194 
195 # Global Z3 context
void Z3_API Z3_interrupt(Z3_context c)
Interrupt the execution of a Z3 procedure. This procedure can be used to interrupt: solvers...

§ ref()

def ref (   self)
Return a reference to the actual C pointer to the Z3 context.

Definition at line 182 of file z3py.py.

Referenced by Context.interrupt().

182  def ref(self):
183  """Return a reference to the actual C pointer to the Z3 context."""
184  return self.ctx
185 

Field Documentation

§ ctx

ctx

Definition at line 171 of file z3py.py.

Referenced by FuncDeclRef.__call__(), Probe.__call__(), Context.__del__(), AstRef.__del__(), Fixedpoint.__del__(), Optimize.__del__(), ApplyResult.__del__(), Tactic.__del__(), Probe.__del__(), ExprRef.__eq__(), Probe.__eq__(), Probe.__ge__(), ApplyResult.__getitem__(), Probe.__gt__(), Probe.__le__(), ApplyResult.__len__(), Probe.__lt__(), ExprRef.__ne__(), Probe.__ne__(), Fixedpoint.add_cover(), Fixedpoint.add_rule(), Optimize.add_soft(), Tactic.apply(), ExprRef.arg(), ApplyResult.as_expr(), Fixedpoint.assert_exprs(), Optimize.assert_exprs(), Optimize.assertions(), BoolSortRef.cast(), Optimize.check(), ApplyResult.convert_model(), AstRef.ctx_ref(), ExprRef.decl(), FuncDeclRef.domain(), Optimize.from_file(), Optimize.from_string(), Fixedpoint.get_answer(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), Fixedpoint.get_num_levels(), Fixedpoint.get_rules(), Fixedpoint.help(), Optimize.help(), Tactic.help(), SortRef.kind(), Optimize.maximize(), Optimize.minimize(), Optimize.model(), SortRef.name(), FuncDeclRef.name(), Optimize.objectives(), Fixedpoint.param_descrs(), Optimize.param_descrs(), Tactic.param_descrs(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), Fixedpoint.pop(), Optimize.pop(), Fixedpoint.push(), Optimize.push(), Fixedpoint.query(), FuncDeclRef.range(), Fixedpoint.reason_unknown(), Optimize.reason_unknown(), Context.ref(), Fixedpoint.register_relation(), Fixedpoint.set(), Optimize.set(), Fixedpoint.set_predicate_representation(), Fixedpoint.sexpr(), Optimize.sexpr(), ApplyResult.sexpr(), Tactic.solver(), ExprRef.sort(), BoolRef.sort(), FiniteDomainRef.sort(), Fixedpoint.statistics(), Optimize.statistics(), Solver.to_smt2(), Fixedpoint.to_string(), AstRef.translate(), and Fixedpoint.update_rule().

§ lib

lib

Definition at line 170 of file z3py.py.

Referenced by Context.__del__().