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

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  stats,
  ctx 
)

Definition at line 6195 of file z3py.py.

6195  def __init__(self, stats, ctx):
6196  self.stats = stats
6197  self.ctx = ctx
6198  Z3_stats_inc_ref(self.ctx.ref(), self.stats)
6199 
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 6203 of file z3py.py.

6203  def __del__(self):
6204  if self.ctx.ref() is not None:
6205  Z3_stats_dec_ref(self.ctx.ref(), self.stats)
6206 
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 6200 of file z3py.py.

6200  def __deepcopy__(self, memo={}):
6201  return Statistics(self.stats, self.ctx)
6202 

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

6295  def __getattr__(self, name):
6296  """Access the value of statistical using attributes.
6297 
6298  Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
6299  we should use '_' (e.g., 'nlsat_propagations').
6300 
6301  >>> x = Int('x')
6302  >>> s = Then('simplify', 'nlsat').solver()
6303  >>> s.add(x > 0)
6304  >>> s.check()
6305  sat
6306  >>> st = s.statistics()
6307  >>> st.nlsat_propagations
6308  2
6309  >>> st.nlsat_stages
6310  2
6311  """
6312  key = name.replace('_', ' ')
6313  try:
6314  return self.get_key_value(key)
6315  except Z3Exception:
6316  raise AttributeError
6317 

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

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

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

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

6275  def get_key_value(self, key):
6276  """Return the value of a particular statistical counter.
6277 
6278  >>> x = Int('x')
6279  >>> s = Then('simplify', 'nlsat').solver()
6280  >>> s.add(x > 0)
6281  >>> s.check()
6282  sat
6283  >>> st = s.statistics()
6284  >>> st.get_key_value('nlsat propagations')
6285  2
6286  """
6287  for idx in range(len(self)):
6288  if key == Z3_stats_get_key(self.ctx.ref(), self.stats, idx):
6289  if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
6290  return int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
6291  else:
6292  return Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
6293  raise Z3Exception("unknown key")
6294 
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: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.
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 6263 of file z3py.py.

6263  def keys(self):
6264  """Return the list of statistical counters.
6265 
6266  >>> x = Int('x')
6267  >>> s = Then('simplify', 'nlsat').solver()
6268  >>> s.add(x > 0)
6269  >>> s.check()
6270  sat
6271  >>> st = s.statistics()
6272  """
6273  return [Z3_stats_get_key(self.ctx.ref(), self.stats, idx) for idx in range(len(self))]
6274 
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 6197 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(), Solver.assert_exprs(), Fixedpoint.assert_exprs(), Optimize.assert_exprs(), Solver.assertions(), Optimize.assertions(), Solver.check(), Optimize.check(), Solver.consequences(), 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(), 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(), Fixedpoint.pop(), Optimize.pop(), Solver.proof(), Solver.push(), Fixedpoint.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.translate(), Solver.units(), Solver.unsat_core(), Optimize.unsat_core(), and Fixedpoint.update_rule().

◆ stats

stats