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 6278 of file z3py.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  stats,
  ctx 
)

Definition at line 6281 of file z3py.py.

6281  def __init__(self, stats, ctx):
6282  self.stats = stats
6283  self.ctx = ctx
6284  Z3_stats_inc_ref(self.ctx.ref(), self.stats)
6285 

◆ __del__()

def __del__ (   self)

Definition at line 6289 of file z3py.py.

6289  def __del__(self):
6290  if self.ctx.ref() is not None:
6291  Z3_stats_dec_ref(self.ctx.ref(), self.stats)
6292 

Member Function Documentation

◆ __deepcopy__()

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 6286 of file z3py.py.

6286  def __deepcopy__(self, memo={}):
6287  return Statistics(self.stats, self.ctx)
6288 

◆ __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 6381 of file z3py.py.

6381  def __getattr__(self, name):
6382  """Access the value of statistical using attributes.
6383 
6384  Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
6385  we should use '_' (e.g., 'nlsat_propagations').
6386 
6387  >>> x = Int('x')
6388  >>> s = Then('simplify', 'nlsat').solver()
6389  >>> s.add(x > 0)
6390  >>> s.check()
6391  sat
6392  >>> st = s.statistics()
6393  >>> st.nlsat_propagations
6394  2
6395  >>> st.nlsat_stages
6396  2
6397  """
6398  key = name.replace('_', ' ')
6399  try:
6400  return self.get_key_value(key)
6401  except Z3Exception:
6402  raise AttributeError
6403 

◆ __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 6325 of file z3py.py.

6325  def __getitem__(self, idx):
6326  """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
6327 
6328  >>> x = Int('x')
6329  >>> s = Then('simplify', 'nlsat').solver()
6330  >>> s.add(x > 0)
6331  >>> s.check()
6332  sat
6333  >>> st = s.statistics()
6334  >>> len(st)
6335  6
6336  >>> st[0]
6337  ('nlsat propagations', 2)
6338  >>> st[1]
6339  ('nlsat stages', 2)
6340  """
6341  if idx >= len(self):
6342  raise IndexError
6343  if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
6344  val = int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
6345  else:
6346  val = Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
6347  return (Z3_stats_get_key(self.ctx.ref(), self.stats, idx), val)
6348 

◆ __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 6311 of file z3py.py.

6311  def __len__(self):
6312  """Return the number of statistical counters.
6313 
6314  >>> x = Int('x')
6315  >>> s = Then('simplify', 'nlsat').solver()
6316  >>> s.add(x > 0)
6317  >>> s.check()
6318  sat
6319  >>> st = s.statistics()
6320  >>> len(st)
6321  6
6322  """
6323  return int(Z3_stats_size(self.ctx.ref(), self.stats))
6324 

◆ __repr__()

def __repr__ (   self)

Definition at line 6293 of file z3py.py.

6293  def __repr__(self):
6294  if in_html_mode():
6295  out = io.StringIO()
6296  even = True
6297  out.write(u('<table border="1" cellpadding="2" cellspacing="0">'))
6298  for k, v in self:
6299  if even:
6300  out.write(u('<tr style="background-color:#CFCFCF">'))
6301  even = False
6302  else:
6303  out.write(u('<tr>'))
6304  even = True
6305  out.write(u('<td>%s</td><td>%s</td></tr>' % (k, v)))
6306  out.write(u('</table>'))
6307  return out.getvalue()
6308  else:
6309  return Z3_stats_to_string(self.ctx.ref(), self.stats)
6310 

◆ 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 6361 of file z3py.py.

6361  def get_key_value(self, key):
6362  """Return the value of a particular statistical counter.
6363 
6364  >>> x = Int('x')
6365  >>> s = Then('simplify', 'nlsat').solver()
6366  >>> s.add(x > 0)
6367  >>> s.check()
6368  sat
6369  >>> st = s.statistics()
6370  >>> st.get_key_value('nlsat propagations')
6371  2
6372  """
6373  for idx in range(len(self)):
6374  if key == Z3_stats_get_key(self.ctx.ref(), self.stats, idx):
6375  if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
6376  return int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
6377  else:
6378  return Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
6379  raise Z3Exception("unknown key")
6380 

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 6349 of file z3py.py.

6349  def keys(self):
6350  """Return the list of statistical counters.
6351 
6352  >>> x = Int('x')
6353  >>> s = Then('simplify', 'nlsat').solver()
6354  >>> s.add(x > 0)
6355  >>> s.check()
6356  sat
6357  >>> st = s.statistics()
6358  """
6359  return [Z3_stats_get_key(self.ctx.ref(), self.stats, idx) for idx in range(len(self))]
6360 

Field Documentation

◆ ctx

ctx

Definition at line 6283 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(), Optimize.pop(), Solver.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
Z3_stats_get_double_value
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.
z3::range
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3488
Z3_stats_is_uint
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_stats_get_uint_value
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.
Z3_stats_size
unsigned Z3_API Z3_stats_size(Z3_context c, Z3_stats s)
Return the number of statistical data in s.
Z3_stats_to_string
Z3_string Z3_API Z3_stats_to_string(Z3_context c, Z3_stats s)
Convert a statistics into a string.
Z3_stats_dec_ref
void Z3_API Z3_stats_dec_ref(Z3_context c, Z3_stats s)
Decrement the reference counter of the given statistics object.
Z3_stats_inc_ref
void Z3_API Z3_stats_inc_ref(Z3_context c, Z3_stats s)
Increment the reference counter of the given statistics object.
Z3_stats_get_key
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.