Z3
Public Member Functions | Data Fields
Statistics Class Reference

Statistics. More...

Public Member Functions

def __init__ (self, stats, ctx)
 
def __deepcopy__ (self, memo={})
 
def __del__ (self)
 
def __repr__ (self)
 
def __len__ (self)
 
def __getitem__ (self, idx)
 
def keys (self)
 
def get_key_value (self, key)
 
def __getattr__ (self, name)
 

Data Fields

 stats
 
 ctx
 

Detailed Description

Statistics.

Statistics for `Solver.check()`.

Definition at line 6259 of file z3py.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  stats,
  ctx 
)

Definition at line 6262 of file z3py.py.

6262  def __init__(self, stats, ctx):
6263  self.stats = stats
6264  self.ctx = ctx
6265  Z3_stats_inc_ref(self.ctx.ref(), self.stats)
6266 
void Z3_API Z3_stats_inc_ref(Z3_context c, Z3_stats s)
Increment the reference counter of the given statistics object.

◆ __del__()

def __del__ (   self)

Definition at line 6270 of file z3py.py.

6270  def __del__(self):
6271  if self.ctx.ref() is not None:
6272  Z3_stats_dec_ref(self.ctx.ref(), self.stats)
6273 
void Z3_API Z3_stats_dec_ref(Z3_context c, Z3_stats s)
Decrement the reference counter of the given statistics object.

Member Function Documentation

◆ __deepcopy__()

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 6267 of file z3py.py.

6267  def __deepcopy__(self, memo={}):
6268  return Statistics(self.stats, self.ctx)
6269 

◆ __getattr__()

def __getattr__ (   self,
  name 
)
Access the value of statistical using attributes.

Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
we should use '_' (e.g., 'nlsat_propagations').

>>> x = Int('x')
>>> s = Then('simplify', 'nlsat').solver()
>>> s.add(x > 0)
>>> s.check()
sat
>>> st = s.statistics()
>>> st.nlsat_propagations
2
>>> st.nlsat_stages
2

Definition at line 6362 of file z3py.py.

6362  def __getattr__(self, name):
6363  """Access the value of statistical using attributes.
6364 
6365  Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
6366  we should use '_' (e.g., 'nlsat_propagations').
6367 
6368  >>> x = Int('x')
6369  >>> s = Then('simplify', 'nlsat').solver()
6370  >>> s.add(x > 0)
6371  >>> s.check()
6372  sat
6373  >>> st = s.statistics()
6374  >>> st.nlsat_propagations
6375  2
6376  >>> st.nlsat_stages
6377  2
6378  """
6379  key = name.replace('_', ' ')
6380  try:
6381  return self.get_key_value(key)
6382  except Z3Exception:
6383  raise AttributeError
6384 

◆ __getitem__()

def __getitem__ (   self,
  idx 
)
Return the value of statistical counter at position `idx`. The result is a pair (key, value).

>>> x = Int('x')
>>> s = Then('simplify', 'nlsat').solver()
>>> s.add(x > 0)
>>> s.check()
sat
>>> st = s.statistics()
>>> len(st)
6
>>> st[0]
('nlsat propagations', 2)
>>> st[1]
('nlsat stages', 2)

Definition at line 6306 of file z3py.py.

6306  def __getitem__(self, idx):
6307  """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
6308 
6309  >>> x = Int('x')
6310  >>> s = Then('simplify', 'nlsat').solver()
6311  >>> s.add(x > 0)
6312  >>> s.check()
6313  sat
6314  >>> st = s.statistics()
6315  >>> len(st)
6316  6
6317  >>> st[0]
6318  ('nlsat propagations', 2)
6319  >>> st[1]
6320  ('nlsat stages', 2)
6321  """
6322  if idx >= len(self):
6323  raise IndexError
6324  if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
6325  val = int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
6326  else:
6327  val = Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
6328  return (Z3_stats_get_key(self.ctx.ref(), self.stats, idx), val)
6329 
bool Z3_API Z3_stats_is_uint(Z3_context c, Z3_stats s, unsigned idx)
Return true if the given statistical data is a unsigned integer.
Z3_string Z3_API Z3_stats_get_key(Z3_context c, Z3_stats s, unsigned idx)
Return the key (a string) for a particular statistical data.
unsigned Z3_API Z3_stats_get_uint_value(Z3_context c, Z3_stats s, unsigned idx)
Return the unsigned value of the given statistical data.
double Z3_API Z3_stats_get_double_value(Z3_context c, Z3_stats s, unsigned idx)
Return the double value of the given statistical data.

◆ __len__()

def __len__ (   self)
Return the number of statistical counters.

>>> x = Int('x')
>>> s = Then('simplify', 'nlsat').solver()
>>> s.add(x > 0)
>>> s.check()
sat
>>> st = s.statistics()
>>> len(st)
6

Definition at line 6292 of file z3py.py.

6292  def __len__(self):
6293  """Return the number of statistical counters.
6294 
6295  >>> x = Int('x')
6296  >>> s = Then('simplify', 'nlsat').solver()
6297  >>> s.add(x > 0)
6298  >>> s.check()
6299  sat
6300  >>> st = s.statistics()
6301  >>> len(st)
6302  6
6303  """
6304  return int(Z3_stats_size(self.ctx.ref(), self.stats))
6305 
unsigned Z3_API Z3_stats_size(Z3_context c, Z3_stats s)
Return the number of statistical data in s.

◆ __repr__()

def __repr__ (   self)

Definition at line 6274 of file z3py.py.

6274  def __repr__(self):
6275  if in_html_mode():
6276  out = io.StringIO()
6277  even = True
6278  out.write(u('<table border="1" cellpadding="2" cellspacing="0">'))
6279  for k, v in self:
6280  if even:
6281  out.write(u('<tr style="background-color:#CFCFCF">'))
6282  even = False
6283  else:
6284  out.write(u('<tr>'))
6285  even = True
6286  out.write(u('<td>%s</td><td>%s</td></tr>' % (k, v)))
6287  out.write(u('</table>'))
6288  return out.getvalue()
6289  else:
6290  return Z3_stats_to_string(self.ctx.ref(), self.stats)
6291 
Z3_string Z3_API Z3_stats_to_string(Z3_context c, Z3_stats s)
Convert a statistics into a string.

◆ get_key_value()

def get_key_value (   self,
  key 
)
Return the value of a particular statistical counter.

>>> x = Int('x')
>>> s = Then('simplify', 'nlsat').solver()
>>> s.add(x > 0)
>>> s.check()
sat
>>> st = s.statistics()
>>> st.get_key_value('nlsat propagations')
2

Definition at line 6342 of file z3py.py.

6342  def get_key_value(self, key):
6343  """Return the value of a particular statistical counter.
6344 
6345  >>> x = Int('x')
6346  >>> s = Then('simplify', 'nlsat').solver()
6347  >>> s.add(x > 0)
6348  >>> s.check()
6349  sat
6350  >>> st = s.statistics()
6351  >>> st.get_key_value('nlsat propagations')
6352  2
6353  """
6354  for idx in range(len(self)):
6355  if key == Z3_stats_get_key(self.ctx.ref(), self.stats, idx):
6356  if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
6357  return int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
6358  else:
6359  return Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
6360  raise Z3Exception("unknown key")
6361 
bool Z3_API Z3_stats_is_uint(Z3_context c, Z3_stats s, unsigned idx)
Return true if the given statistical data is a unsigned integer.
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
Z3_string Z3_API Z3_stats_get_key(Z3_context c, Z3_stats s, unsigned idx)
Return the key (a string) for a particular statistical data.
unsigned Z3_API Z3_stats_get_uint_value(Z3_context c, Z3_stats s, unsigned idx)
Return the unsigned value of the given statistical data.
double Z3_API Z3_stats_get_double_value(Z3_context c, Z3_stats s, unsigned idx)
Return the double value of the given statistical data.

Referenced by Statistics.__getattr__().

◆ keys()

def keys (   self)
Return the list of statistical counters.

>>> x = Int('x')
>>> s = Then('simplify', 'nlsat').solver()
>>> s.add(x > 0)
>>> s.check()
sat
>>> st = s.statistics()

Definition at line 6330 of file z3py.py.

6330  def keys(self):
6331  """Return the list of statistical counters.
6332 
6333  >>> x = Int('x')
6334  >>> s = Then('simplify', 'nlsat').solver()
6335  >>> s.add(x > 0)
6336  >>> s.check()
6337  sat
6338  >>> st = s.statistics()
6339  """
6340  return [Z3_stats_get_key(self.ctx.ref(), self.stats, idx) for idx in range(len(self))]
6341 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3370
Z3_string Z3_API Z3_stats_get_key(Z3_context c, Z3_stats s, unsigned idx)
Return the key (a string) for a particular statistical data.

Field Documentation

◆ ctx

ctx

Definition at line 6264 of file z3py.py.

Referenced by Probe.__call__(), Solver.__copy__(), Statistics.__deepcopy__(), Solver.__deepcopy__(), Fixedpoint.__deepcopy__(), Optimize.__deepcopy__(), ApplyResult.__deepcopy__(), Tactic.__deepcopy__(), Probe.__deepcopy__(), Statistics.__del__(), Solver.__del__(), Fixedpoint.__del__(), Optimize.__del__(), ApplyResult.__del__(), Tactic.__del__(), Probe.__del__(), Probe.__eq__(), Probe.__ge__(), Statistics.__getitem__(), ApplyResult.__getitem__(), Probe.__gt__(), Probe.__le__(), Statistics.__len__(), ApplyResult.__len__(), Probe.__lt__(), Probe.__ne__(), Statistics.__repr__(), Fixedpoint.add_cover(), Fixedpoint.add_rule(), Optimize.add_soft(), Tactic.apply(), ApplyResult.as_expr(), Solver.assert_and_track(), Optimize.assert_and_track(), Solver.assert_exprs(), Fixedpoint.assert_exprs(), Optimize.assert_exprs(), Solver.assertions(), Optimize.assertions(), Solver.check(), Optimize.check(), Solver.consequences(), Solver.dimacs(), Solver.from_file(), Optimize.from_file(), Solver.from_string(), Optimize.from_string(), Fixedpoint.get_answer(), Fixedpoint.get_assertions(), Fixedpoint.get_cover_delta(), Fixedpoint.get_ground_sat_answer(), Statistics.get_key_value(), Fixedpoint.get_num_levels(), Fixedpoint.get_rule_names_along_trace(), Fixedpoint.get_rules(), Fixedpoint.get_rules_along_trace(), Solver.help(), Fixedpoint.help(), Optimize.help(), Tactic.help(), Solver.import_model_converter(), Statistics.keys(), Optimize.maximize(), Optimize.minimize(), Solver.model(), Optimize.model(), Solver.non_units(), Solver.num_scopes(), Optimize.objectives(), Solver.param_descrs(), Fixedpoint.param_descrs(), Optimize.param_descrs(), Tactic.param_descrs(), Fixedpoint.parse_file(), Fixedpoint.parse_string(), Solver.pop(), Optimize.pop(), Solver.proof(), Solver.push(), Optimize.push(), Fixedpoint.query(), Fixedpoint.query_from_lvl(), Solver.reason_unknown(), Fixedpoint.reason_unknown(), Optimize.reason_unknown(), Fixedpoint.register_relation(), Solver.reset(), Solver.set(), Fixedpoint.set(), Optimize.set(), Fixedpoint.set_predicate_representation(), Solver.sexpr(), Fixedpoint.sexpr(), Optimize.sexpr(), ApplyResult.sexpr(), Tactic.solver(), Solver.statistics(), Fixedpoint.statistics(), Optimize.statistics(), Solver.to_smt2(), Fixedpoint.to_string(), Solver.trail(), Solver.trail_levels(), Solver.translate(), Solver.units(), Solver.unsat_core(), Optimize.unsat_core(), and Fixedpoint.update_rule().

◆ stats

stats