Z3
Public Member Functions | Data Fields
Statistics Class Reference

Statistics. More...

Public Member Functions

def __init__ (self, stats, ctx)
 
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 5544 of file z3py.py.

Constructor & Destructor Documentation

def __init__ (   self,
  stats,
  ctx 
)

Definition at line 5547 of file z3py.py.

5547  def __init__(self, stats, ctx):
5548  self.stats = stats
5549  self.ctx = ctx
5550  Z3_stats_inc_ref(self.ctx.ref(), self.stats)
5551 
void Z3_API Z3_stats_inc_ref(__in Z3_context c, __in Z3_stats s)
Increment the reference counter of the given statistics object.
def __init__(self, stats, ctx)
Definition: z3py.py:5547
def __del__ (   self)

Definition at line 5552 of file z3py.py.

5552  def __del__(self):
5553  Z3_stats_dec_ref(self.ctx.ref(), self.stats)
5554 
def __del__(self)
Definition: z3py.py:5552
void Z3_API Z3_stats_dec_ref(__in Z3_context c, __in Z3_stats s)
Decrement the reference counter of the given statistics object.

Member Function Documentation

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.keys()
['nlsat propagations', 'nlsat stages']
>>> st.nlsat_propagations
2
>>> st.nlsat_stages
2

Definition at line 5645 of file z3py.py.

5645  def __getattr__(self, name):
5646  """Access the value of statistical using attributes.
5647 
5648  Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
5649  we should use '_' (e.g., 'nlsat_propagations').
5650 
5651  >>> x = Int('x')
5652  >>> s = Then('simplify', 'nlsat').solver()
5653  >>> s.add(x > 0)
5654  >>> s.check()
5655  sat
5656  >>> st = s.statistics()
5657  >>> st.keys()
5658  ['nlsat propagations', 'nlsat stages']
5659  >>> st.nlsat_propagations
5660  2
5661  >>> st.nlsat_stages
5662  2
5663  """
5664  key = name.replace('_', ' ')
5665  try:
5666  return self.get_key_value(key)
5667  except Z3Exception:
5668  raise AttributeError
5669 
def __getattr__(self, name)
Definition: z3py.py:5645
def get_key_value(self, key)
Definition: z3py.py:5625
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)
2
>>> st[0]
('nlsat propagations', 2)
>>> st[1]
('nlsat stages', 2)

Definition at line 5587 of file z3py.py.

5587  def __getitem__(self, idx):
5588  """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
5589 
5590  >>> x = Int('x')
5591  >>> s = Then('simplify', 'nlsat').solver()
5592  >>> s.add(x > 0)
5593  >>> s.check()
5594  sat
5595  >>> st = s.statistics()
5596  >>> len(st)
5597  2
5598  >>> st[0]
5599  ('nlsat propagations', 2)
5600  >>> st[1]
5601  ('nlsat stages', 2)
5602  """
5603  if idx >= len(self):
5604  raise IndexError
5605  if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
5606  val = int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
5607  else:
5608  val = Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
5609  return (Z3_stats_get_key(self.ctx.ref(), self.stats, idx), val)
5610 
double Z3_API Z3_stats_get_double_value(__in Z3_context c, __in Z3_stats s, __in unsigned idx)
Return the double value of the given statistical data.
Z3_string Z3_API Z3_stats_get_key(__in Z3_context c, __in Z3_stats s, __in unsigned idx)
Return the key (a string) for a particular statistical data.
Z3_bool Z3_API Z3_stats_is_uint(__in Z3_context c, __in Z3_stats s, __in unsigned idx)
Return Z3_TRUE if the given statistical data is a unsigned integer.
def __getitem__(self, idx)
Definition: z3py.py:5587
unsigned Z3_API Z3_stats_get_uint_value(__in Z3_context c, __in Z3_stats s, __in unsigned idx)
Return the unsigned value of the given statistical data.
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)
2

Definition at line 5573 of file z3py.py.

5573  def __len__(self):
5574  """Return the number of statistical counters.
5575 
5576  >>> x = Int('x')
5577  >>> s = Then('simplify', 'nlsat').solver()
5578  >>> s.add(x > 0)
5579  >>> s.check()
5580  sat
5581  >>> st = s.statistics()
5582  >>> len(st)
5583  2
5584  """
5585  return int(Z3_stats_size(self.ctx.ref(), self.stats))
5586 
unsigned Z3_API Z3_stats_size(__in Z3_context c, __in Z3_stats s)
Return the number of statistical data in s.
def __len__(self)
Definition: z3py.py:5573
def __repr__ (   self)

Definition at line 5555 of file z3py.py.

5555  def __repr__(self):
5556  if in_html_mode():
5557  out = io.StringIO()
5558  even = True
5559  out.write(u('<table border="1" cellpadding="2" cellspacing="0">'))
5560  for k, v in self:
5561  if even:
5562  out.write(u('<tr style="background-color:#CFCFCF">'))
5563  even = False
5564  else:
5565  out.write(u('<tr>'))
5566  even = True
5567  out.write(u('<td>%s</td><td>%s</td></tr>' % (k, v)))
5568  out.write(u('</table>'))
5569  return out.getvalue()
5570  else:
5571  return Z3_stats_to_string(self.ctx.ref(), self.stats)
5572 
Z3_string Z3_API Z3_stats_to_string(__in Z3_context c, __in Z3_stats s)
Convert a statistics into a string.
def __repr__(self)
Definition: z3py.py:5555
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 5625 of file z3py.py.

Referenced by Statistics.__getattr__().

5625  def get_key_value(self, key):
5626  """Return the value of a particular statistical counter.
5627 
5628  >>> x = Int('x')
5629  >>> s = Then('simplify', 'nlsat').solver()
5630  >>> s.add(x > 0)
5631  >>> s.check()
5632  sat
5633  >>> st = s.statistics()
5634  >>> st.get_key_value('nlsat propagations')
5635  2
5636  """
5637  for idx in range(len(self)):
5638  if key == Z3_stats_get_key(self.ctx.ref(), self.stats, idx):
5639  if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
5640  return int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
5641  else:
5642  return Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
5643  raise Z3Exception("unknown key")
5644 
double Z3_API Z3_stats_get_double_value(__in Z3_context c, __in Z3_stats s, __in unsigned idx)
Return the double value of the given statistical data.
Z3_string Z3_API Z3_stats_get_key(__in Z3_context c, __in Z3_stats s, __in unsigned idx)
Return the key (a string) for a particular statistical data.
def get_key_value(self, key)
Definition: z3py.py:5625
Z3_bool Z3_API Z3_stats_is_uint(__in Z3_context c, __in Z3_stats s, __in unsigned idx)
Return Z3_TRUE if the given statistical data is a unsigned integer.
unsigned Z3_API Z3_stats_get_uint_value(__in Z3_context c, __in Z3_stats s, __in unsigned idx)
Return the unsigned value of the given statistical data.
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()
>>> st.keys()
['nlsat propagations', 'nlsat stages']

Definition at line 5611 of file z3py.py.

5611  def keys(self):
5612  """Return the list of statistical counters.
5613 
5614  >>> x = Int('x')
5615  >>> s = Then('simplify', 'nlsat').solver()
5616  >>> s.add(x > 0)
5617  >>> s.check()
5618  sat
5619  >>> st = s.statistics()
5620  >>> st.keys()
5621  ['nlsat propagations', 'nlsat stages']
5622  """
5623  return [Z3_stats_get_key(self.ctx.ref(), self.stats, idx) for idx in range(len(self))]
5624 
Z3_string Z3_API Z3_stats_get_key(__in Z3_context c, __in Z3_stats s, __in unsigned idx)
Return the key (a string) for a particular statistical data.
def keys(self)
Definition: z3py.py:5611

Field Documentation

ctx
stats