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

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  stats,
  ctx 
)

Definition at line 6238 of file z3py.py.

6238  def __init__(self, stats, ctx):
6239  self.stats = stats
6240  self.ctx = ctx
6241  Z3_stats_inc_ref(self.ctx.ref(), self.stats)
6242 
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 6246 of file z3py.py.

6246  def __del__(self):
6247  if self.ctx.ref() is not None:
6248  Z3_stats_dec_ref(self.ctx.ref(), self.stats)
6249 
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 6243 of file z3py.py.

6243  def __deepcopy__(self, memo={}):
6244  return Statistics(self.stats, self.ctx)
6245 

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

6338  def __getattr__(self, name):
6339  """Access the value of statistical using attributes.
6340 
6341  Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
6342  we should use '_' (e.g., 'nlsat_propagations').
6343 
6344  >>> x = Int('x')
6345  >>> s = Then('simplify', 'nlsat').solver()
6346  >>> s.add(x > 0)
6347  >>> s.check()
6348  sat
6349  >>> st = s.statistics()
6350  >>> st.nlsat_propagations
6351  2
6352  >>> st.nlsat_stages
6353  2
6354  """
6355  key = name.replace('_', ' ')
6356  try:
6357  return self.get_key_value(key)
6358  except Z3Exception:
6359  raise AttributeError
6360 

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

6282  def __getitem__(self, idx):
6283  """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
6284 
6285  >>> x = Int('x')
6286  >>> s = Then('simplify', 'nlsat').solver()
6287  >>> s.add(x > 0)
6288  >>> s.check()
6289  sat
6290  >>> st = s.statistics()
6291  >>> len(st)
6292  6
6293  >>> st[0]
6294  ('nlsat propagations', 2)
6295  >>> st[1]
6296  ('nlsat stages', 2)
6297  """
6298  if idx >= len(self):
6299  raise IndexError
6300  if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
6301  val = int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
6302  else:
6303  val = Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
6304  return (Z3_stats_get_key(self.ctx.ref(), self.stats, idx), val)
6305 
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 6268 of file z3py.py.

6268  def __len__(self):
6269  """Return the number of statistical counters.
6270 
6271  >>> x = Int('x')
6272  >>> s = Then('simplify', 'nlsat').solver()
6273  >>> s.add(x > 0)
6274  >>> s.check()
6275  sat
6276  >>> st = s.statistics()
6277  >>> len(st)
6278  6
6279  """
6280  return int(Z3_stats_size(self.ctx.ref(), self.stats))
6281 
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 6250 of file z3py.py.

6250  def __repr__(self):
6251  if in_html_mode():
6252  out = io.StringIO()
6253  even = True
6254  out.write(u('<table border="1" cellpadding="2" cellspacing="0">'))
6255  for k, v in self:
6256  if even:
6257  out.write(u('<tr style="background-color:#CFCFCF">'))
6258  even = False
6259  else:
6260  out.write(u('<tr>'))
6261  even = True
6262  out.write(u('<td>%s</td><td>%s</td></tr>' % (k, v)))
6263  out.write(u('</table>'))
6264  return out.getvalue()
6265  else:
6266  return Z3_stats_to_string(self.ctx.ref(), self.stats)
6267 
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 6318 of file z3py.py.

6318  def get_key_value(self, key):
6319  """Return the value of a particular statistical counter.
6320 
6321  >>> x = Int('x')
6322  >>> s = Then('simplify', 'nlsat').solver()
6323  >>> s.add(x > 0)
6324  >>> s.check()
6325  sat
6326  >>> st = s.statistics()
6327  >>> st.get_key_value('nlsat propagations')
6328  2
6329  """
6330  for idx in range(len(self)):
6331  if key == Z3_stats_get_key(self.ctx.ref(), self.stats, idx):
6332  if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
6333  return int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
6334  else:
6335  return Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
6336  raise Z3Exception("unknown key")
6337 
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:3358
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.

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

6306  def keys(self):
6307  """Return the list of statistical counters.
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  """
6316  return [Z3_stats_get_key(self.ctx.ref(), self.stats, idx) for idx in range(len(self))]
6317 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3358
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 6240 of file z3py.py.

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

◆ stats

stats

Definition at line 6239 of file z3py.py.