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

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  stats,
  ctx 
)

Definition at line 6189 of file z3py.py.

6189  def __init__(self, stats, ctx):
6190  self.stats = stats
6191  self.ctx = ctx
6192  Z3_stats_inc_ref(self.ctx.ref(), self.stats)
6193 
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 6197 of file z3py.py.

6197  def __del__(self):
6198  if self.ctx.ref() is not None:
6199  Z3_stats_dec_ref(self.ctx.ref(), self.stats)
6200 
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 6194 of file z3py.py.

6194  def __deepcopy__(self, memo={}):
6195  return Statistics(self.stats, self.ctx)
6196 

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

6289  def __getattr__(self, name):
6290  """Access the value of statistical using attributes.
6291 
6292  Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
6293  we should use '_' (e.g., 'nlsat_propagations').
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  >>> st.nlsat_propagations
6302  2
6303  >>> st.nlsat_stages
6304  2
6305  """
6306  key = name.replace('_', ' ')
6307  try:
6308  return self.get_key_value(key)
6309  except Z3Exception:
6310  raise AttributeError
6311 

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

6233  def __getitem__(self, idx):
6234  """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
6235 
6236  >>> x = Int('x')
6237  >>> s = Then('simplify', 'nlsat').solver()
6238  >>> s.add(x > 0)
6239  >>> s.check()
6240  sat
6241  >>> st = s.statistics()
6242  >>> len(st)
6243  6
6244  >>> st[0]
6245  ('nlsat propagations', 2)
6246  >>> st[1]
6247  ('nlsat stages', 2)
6248  """
6249  if idx >= len(self):
6250  raise IndexError
6251  if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
6252  val = int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
6253  else:
6254  val = Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
6255  return (Z3_stats_get_key(self.ctx.ref(), self.stats, idx), val)
6256 
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 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 6219 of file z3py.py.

6219  def __len__(self):
6220  """Return the number of statistical counters.
6221 
6222  >>> x = Int('x')
6223  >>> s = Then('simplify', 'nlsat').solver()
6224  >>> s.add(x > 0)
6225  >>> s.check()
6226  sat
6227  >>> st = s.statistics()
6228  >>> len(st)
6229  6
6230  """
6231  return int(Z3_stats_size(self.ctx.ref(), self.stats))
6232 
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 6201 of file z3py.py.

6201  def __repr__(self):
6202  if in_html_mode():
6203  out = io.StringIO()
6204  even = True
6205  out.write(u('<table border="1" cellpadding="2" cellspacing="0">'))
6206  for k, v in self:
6207  if even:
6208  out.write(u('<tr style="background-color:#CFCFCF">'))
6209  even = False
6210  else:
6211  out.write(u('<tr>'))
6212  even = True
6213  out.write(u('<td>%s</td><td>%s</td></tr>' % (k, v)))
6214  out.write(u('</table>'))
6215  return out.getvalue()
6216  else:
6217  return Z3_stats_to_string(self.ctx.ref(), self.stats)
6218 
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 6269 of file z3py.py.

6269  def get_key_value(self, key):
6270  """Return the value of a particular statistical counter.
6271 
6272  >>> x = Int('x')
6273  >>> s = Then('simplify', 'nlsat').solver()
6274  >>> s.add(x > 0)
6275  >>> s.check()
6276  sat
6277  >>> st = s.statistics()
6278  >>> st.get_key_value('nlsat propagations')
6279  2
6280  """
6281  for idx in range(len(self)):
6282  if key == Z3_stats_get_key(self.ctx.ref(), self.stats, idx):
6283  if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
6284  return int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
6285  else:
6286  return Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
6287  raise Z3Exception("unknown key")
6288 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
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 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 6257 of file z3py.py.

6257  def keys(self):
6258  """Return the list of statistical counters.
6259 
6260  >>> x = Int('x')
6261  >>> s = Then('simplify', 'nlsat').solver()
6262  >>> s.add(x > 0)
6263  >>> s.check()
6264  sat
6265  >>> st = s.statistics()
6266  """
6267  return [Z3_stats_get_key(self.ctx.ref(), self.stats, idx) for idx in range(len(self))]
6268 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3244
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 6191 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(), 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(), Optimize.unsat_core(), and Fixedpoint.update_rule().

◆ stats

stats

Definition at line 6190 of file z3py.py.