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

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  stats,
  ctx 
)

Definition at line 5921 of file z3py.py.

5921  def __init__(self, stats, ctx):
5922  self.stats = stats
5923  self.ctx = ctx
5924  Z3_stats_inc_ref(self.ctx.ref(), self.stats)
5925 
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 5929 of file z3py.py.

5929  def __del__(self):
5930  if self.ctx.ref() is not None:
5931  Z3_stats_dec_ref(self.ctx.ref(), self.stats)
5932 
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 5926 of file z3py.py.

5926  def __deepcopy__(self, memo={}):
5927  return Statistics(self.stats, self.ctx)
5928 

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

6021  def __getattr__(self, name):
6022  """Access the value of statistical using attributes.
6023 
6024  Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
6025  we should use '_' (e.g., 'nlsat_propagations').
6026 
6027  >>> x = Int('x')
6028  >>> s = Then('simplify', 'nlsat').solver()
6029  >>> s.add(x > 0)
6030  >>> s.check()
6031  sat
6032  >>> st = s.statistics()
6033  >>> st.nlsat_propagations
6034  2
6035  >>> st.nlsat_stages
6036  2
6037  """
6038  key = name.replace('_', ' ')
6039  try:
6040  return self.get_key_value(key)
6041  except Z3Exception:
6042  raise AttributeError
6043 

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

5965  def __getitem__(self, idx):
5966  """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
5967 
5968  >>> x = Int('x')
5969  >>> s = Then('simplify', 'nlsat').solver()
5970  >>> s.add(x > 0)
5971  >>> s.check()
5972  sat
5973  >>> st = s.statistics()
5974  >>> len(st)
5975  6
5976  >>> st[0]
5977  ('nlsat propagations', 2)
5978  >>> st[1]
5979  ('nlsat stages', 2)
5980  """
5981  if idx >= len(self):
5982  raise IndexError
5983  if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
5984  val = int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
5985  else:
5986  val = Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
5987  return (Z3_stats_get_key(self.ctx.ref(), self.stats, idx), val)
5988 
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.
Z3_bool Z3_API Z3_stats_is_uint(Z3_context c, Z3_stats s, unsigned idx)
Return Z3_TRUE if the given statistical data is a unsigned integer.
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 5951 of file z3py.py.

5951  def __len__(self):
5952  """Return the number of statistical counters.
5953 
5954  >>> x = Int('x')
5955  >>> s = Then('simplify', 'nlsat').solver()
5956  >>> s.add(x > 0)
5957  >>> s.check()
5958  sat
5959  >>> st = s.statistics()
5960  >>> len(st)
5961  6
5962  """
5963  return int(Z3_stats_size(self.ctx.ref(), self.stats))
5964 
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 5933 of file z3py.py.

5933  def __repr__(self):
5934  if in_html_mode():
5935  out = io.StringIO()
5936  even = True
5937  out.write(u('<table border="1" cellpadding="2" cellspacing="0">'))
5938  for k, v in self:
5939  if even:
5940  out.write(u('<tr style="background-color:#CFCFCF">'))
5941  even = False
5942  else:
5943  out.write(u('<tr>'))
5944  even = True
5945  out.write(u('<td>%s</td><td>%s</td></tr>' % (k, v)))
5946  out.write(u('</table>'))
5947  return out.getvalue()
5948  else:
5949  return Z3_stats_to_string(self.ctx.ref(), self.stats)
5950 
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 6001 of file z3py.py.

6001  def get_key_value(self, key):
6002  """Return the value of a particular statistical counter.
6003 
6004  >>> x = Int('x')
6005  >>> s = Then('simplify', 'nlsat').solver()
6006  >>> s.add(x > 0)
6007  >>> s.check()
6008  sat
6009  >>> st = s.statistics()
6010  >>> st.get_key_value('nlsat propagations')
6011  2
6012  """
6013  for idx in range(len(self)):
6014  if key == Z3_stats_get_key(self.ctx.ref(), self.stats, idx):
6015  if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
6016  return int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
6017  else:
6018  return Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
6019  raise Z3Exception("unknown key")
6020 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
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.
Z3_bool Z3_API Z3_stats_is_uint(Z3_context c, Z3_stats s, unsigned idx)
Return Z3_TRUE if the given statistical data is a unsigned integer.
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 5989 of file z3py.py.

5989  def keys(self):
5990  """Return the list of statistical counters.
5991 
5992  >>> x = Int('x')
5993  >>> s = Then('simplify', 'nlsat').solver()
5994  >>> s.add(x > 0)
5995  >>> s.check()
5996  sat
5997  >>> st = s.statistics()
5998  """
5999  return [Z3_stats_get_key(self.ctx.ref(), self.stats, idx) for idx in range(len(self))]
6000 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:2868
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 5923 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(), Fixedpoint.assert_exprs(), Optimize.assert_exprs(), Optimize.assertions(), Optimize.check(), ApplyResult.convert_model(), 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(), Fixedpoint.pop(), Optimize.pop(), Fixedpoint.push(), 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(), and Fixedpoint.update_rule().

◆ stats

stats

Definition at line 5922 of file z3py.py.