Z3
Public Member Functions | Data Fields
Statistics Class Reference

Statistics. More...

Public Member Functions

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

Constructor & Destructor Documentation

def __init__ (   self,
  stats,
  ctx 
)

Definition at line 6616 of file z3py.py.

6616  def __init__(self, stats, ctx):
6617  self.stats = stats
6618  self.ctx = ctx
6619  Z3_stats_inc_ref(self.ctx.ref(), self.stats)
6620 
void Z3_API Z3_stats_inc_ref(Z3_context c, Z3_stats s)
Increment the reference counter of the given statistics object.
def __init__(self, stats, ctx)
Definition: z3py.py:6616
def __del__ (   self)

Definition at line 6624 of file z3py.py.

6624  def __del__(self):
6625  if self.ctx.ref() is not None:
6626  Z3_stats_dec_ref(self.ctx.ref(), self.stats)
6627 
void Z3_API Z3_stats_dec_ref(Z3_context c, Z3_stats s)
Decrement the reference counter of the given statistics object.
def __del__(self)
Definition: z3py.py:6624

Member Function Documentation

def __deepcopy__ (   self,
  memo = {} 
)

Definition at line 6621 of file z3py.py.

6621  def __deepcopy__(self, memo={}):
6622  return Statistics(self.stats, self.ctx)
6623 
def __deepcopy__
Definition: z3py.py:6621
Statistics.
Definition: z3py.py:6613
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 6716 of file z3py.py.

6716  def __getattr__(self, name):
6717  """Access the value of statistical using attributes.
6718 
6719  Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
6720  we should use '_' (e.g., 'nlsat_propagations').
6721 
6722  >>> x = Int('x')
6723  >>> s = Then('simplify', 'nlsat').solver()
6724  >>> s.add(x > 0)
6725  >>> s.check()
6726  sat
6727  >>> st = s.statistics()
6728  >>> st.nlsat_propagations
6729  2
6730  >>> st.nlsat_stages
6731  2
6732  """
6733  key = name.replace("_", " ")
6734  try:
6735  return self.get_key_value(key)
6736  except Z3Exception:
6737  raise AttributeError
6738 
def __getattr__(self, name)
Definition: z3py.py:6716
def get_key_value(self, key)
Definition: z3py.py:6696
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 6660 of file z3py.py.

6660  def __getitem__(self, idx):
6661  """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
6662 
6663  >>> x = Int('x')
6664  >>> s = Then('simplify', 'nlsat').solver()
6665  >>> s.add(x > 0)
6666  >>> s.check()
6667  sat
6668  >>> st = s.statistics()
6669  >>> len(st)
6670  6
6671  >>> st[0]
6672  ('nlsat propagations', 2)
6673  >>> st[1]
6674  ('nlsat stages', 2)
6675  """
6676  if idx >= len(self):
6677  raise IndexError
6678  if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
6679  val = int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
6680  else:
6681  val = Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
6682  return (Z3_stats_get_key(self.ctx.ref(), self.stats, idx), val)
6683 
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.
def __getitem__(self, idx)
Definition: z3py.py:6660
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 6646 of file z3py.py.

6646  def __len__(self):
6647  """Return the number of statistical counters.
6648 
6649  >>> x = Int('x')
6650  >>> s = Then('simplify', 'nlsat').solver()
6651  >>> s.add(x > 0)
6652  >>> s.check()
6653  sat
6654  >>> st = s.statistics()
6655  >>> len(st)
6656  6
6657  """
6658  return int(Z3_stats_size(self.ctx.ref(), self.stats))
6659 
unsigned Z3_API Z3_stats_size(Z3_context c, Z3_stats s)
Return the number of statistical data in s.
def __len__(self)
Definition: z3py.py:6646
def __repr__ (   self)

Definition at line 6628 of file z3py.py.

6628  def __repr__(self):
6629  if in_html_mode():
6630  out = io.StringIO()
6631  even = True
6632  out.write(u('<table border="1" cellpadding="2" cellspacing="0">'))
6633  for k, v in self:
6634  if even:
6635  out.write(u('<tr style="background-color:#CFCFCF">'))
6636  even = False
6637  else:
6638  out.write(u("<tr>"))
6639  even = True
6640  out.write(u("<td>%s</td><td>%s</td></tr>" % (k, v)))
6641  out.write(u("</table>"))
6642  return out.getvalue()
6643  else:
6644  return Z3_stats_to_string(self.ctx.ref(), self.stats)
6645 
def __repr__(self)
Definition: z3py.py:6628
Z3_string Z3_API Z3_stats_to_string(Z3_context c, Z3_stats s)
Convert a statistics into a string.
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 6696 of file z3py.py.

Referenced by Statistics.__getattr__().

6696  def get_key_value(self, key):
6697  """Return the value of a particular statistical counter.
6698 
6699  >>> x = Int('x')
6700  >>> s = Then('simplify', 'nlsat').solver()
6701  >>> s.add(x > 0)
6702  >>> s.check()
6703  sat
6704  >>> st = s.statistics()
6705  >>> st.get_key_value('nlsat propagations')
6706  2
6707  """
6708  for idx in range(len(self)):
6709  if key == Z3_stats_get_key(self.ctx.ref(), self.stats, idx):
6710  if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
6711  return int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
6712  else:
6713  return Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
6714  raise Z3Exception("unknown key")
6715 
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:3794
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.
def get_key_value(self, key)
Definition: z3py.py:6696
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.
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 6684 of file z3py.py.

6684  def keys(self):
6685  """Return the list of statistical counters.
6686 
6687  >>> x = Int('x')
6688  >>> s = Then('simplify', 'nlsat').solver()
6689  >>> s.add(x > 0)
6690  >>> s.check()
6691  sat
6692  >>> st = s.statistics()
6693  """
6694  return [Z3_stats_get_key(self.ctx.ref(), self.stats, idx) for idx in range(len(self))]
6695 
expr range(expr const &lo, expr const &hi)
Definition: z3++.h:3794
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.
def keys(self)
Definition: z3py.py:6684

Field Documentation

ctx
stats