Z3
Loading...
Searching...
No Matches
Statistics Class Reference

Statistics. More...

Public Member Functions

 __init__ (self, stats, ctx)
 __deepcopy__ (self, memo={})
 __del__ (self)
 __repr__ (self)
 __len__ (self)
 __getitem__ (self, idx)
 keys (self)
 get_key_value (self, key)
 __getattr__ (self, name)

Data Fields

 stats = stats
 ctx = ctx

Detailed Description

Statistics.

Statistics for `Solver.check()`.

Definition at line 6953 of file z3py.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
stats,
ctx )

Definition at line 6956 of file z3py.py.

6956 def __init__(self, stats, ctx):
6957 self.stats = stats
6958 self.ctx = ctx
6959 Z3_stats_inc_ref(self.ctx.ref(), self.stats)
6960
void Z3_API Z3_stats_inc_ref(Z3_context c, Z3_stats s)
Increment the reference counter of the given statistics object.

◆ __del__()

__del__ ( self)

Definition at line 6964 of file z3py.py.

6964 def __del__(self):
6965 if self.ctx.ref() is not None and Z3_stats_dec_ref is not None:
6966 Z3_stats_dec_ref(self.ctx.ref(), self.stats)
6967
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__()

__deepcopy__ ( self,
memo = {} )

Definition at line 6961 of file z3py.py.

6961 def __deepcopy__(self, memo={}):
6962 return Statistics(self.stats, self.ctx)
6963

◆ __getattr__()

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

7056 def __getattr__(self, name):
7057 """Access the value of statistical using attributes.
7058
7059 Remark: to access a counter containing blank spaces (e.g., 'nlsat propagations'),
7060 we should use '_' (e.g., 'nlsat_propagations').
7061
7062 >>> x = Int('x')
7063 >>> s = Then('simplify', 'nlsat').solver()
7064 >>> s.add(x > 0)
7065 >>> s.check()
7066 sat
7067 >>> st = s.statistics()
7068 >>> st.nlsat_propagations
7069 2
7070 >>> st.nlsat_stages
7071 2
7072 """
7073 key = name.replace("_", " ")
7074 try:
7075 return self.get_key_value(key)
7076 except Z3Exception:
7077 raise AttributeError
7078

◆ __getitem__()

__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)
7
>>> st[0]
('nlsat propagations', 2)
>>> st[1]
('nlsat restarts', 1)

Definition at line 7000 of file z3py.py.

7000 def __getitem__(self, idx):
7001 """Return the value of statistical counter at position `idx`. The result is a pair (key, value).
7002
7003 >>> x = Int('x')
7004 >>> s = Then('simplify', 'nlsat').solver()
7005 >>> s.add(x > 0)
7006 >>> s.check()
7007 sat
7008 >>> st = s.statistics()
7009 >>> len(st)
7010 7
7011 >>> st[0]
7012 ('nlsat propagations', 2)
7013 >>> st[1]
7014 ('nlsat restarts', 1)
7015 """
7016 if idx >= len(self):
7017 raise IndexError
7018 if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
7019 val = int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
7020 else:
7021 val = Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
7022 return (Z3_stats_get_key(self.ctx.ref(), self.stats, idx), val)
7023
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.
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.

◆ __len__()

__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)
7

Definition at line 6986 of file z3py.py.

6986 def __len__(self):
6987 """Return the number of statistical counters.
6988
6989 >>> x = Int('x')
6990 >>> s = Then('simplify', 'nlsat').solver()
6991 >>> s.add(x > 0)
6992 >>> s.check()
6993 sat
6994 >>> st = s.statistics()
6995 >>> len(st)
6996 7
6997 """
6998 return int(Z3_stats_size(self.ctx.ref(), self.stats))
6999
unsigned Z3_API Z3_stats_size(Z3_context c, Z3_stats s)
Return the number of statistical data in s.

◆ __repr__()

__repr__ ( self)

Definition at line 6968 of file z3py.py.

6968 def __repr__(self):
6969 if in_html_mode():
6970 out = io.StringIO()
6971 even = True
6972 out.write(u('<table border="1" cellpadding="2" cellspacing="0">'))
6973 for k, v in self:
6974 if even:
6975 out.write(u('<tr style="background-color:#CFCFCF">'))
6976 even = False
6977 else:
6978 out.write(u("<tr>"))
6979 even = True
6980 out.write(u("<td>%s</td><td>%s</td></tr>" % (k, v)))
6981 out.write(u("</table>"))
6982 return out.getvalue()
6983 else:
6984 return Z3_stats_to_string(self.ctx.ref(), self.stats)
6985
Z3_string Z3_API Z3_stats_to_string(Z3_context c, Z3_stats s)
Convert a statistics into a string.

◆ get_key_value()

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

7036 def get_key_value(self, key):
7037 """Return the value of a particular statistical counter.
7038
7039 >>> x = Int('x')
7040 >>> s = Then('simplify', 'nlsat').solver()
7041 >>> s.add(x > 0)
7042 >>> s.check()
7043 sat
7044 >>> st = s.statistics()
7045 >>> st.get_key_value('nlsat propagations')
7046 2
7047 """
7048 for idx in range(len(self)):
7049 if key == Z3_stats_get_key(self.ctx.ref(), self.stats, idx):
7050 if Z3_stats_is_uint(self.ctx.ref(), self.stats, idx):
7051 return int(Z3_stats_get_uint_value(self.ctx.ref(), self.stats, idx))
7052 else:
7053 return Z3_stats_get_double_value(self.ctx.ref(), self.stats, idx)
7054 raise Z3Exception("unknown key")
7055

Referenced by __getattr__().

◆ keys()

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

7024 def keys(self):
7025 """Return the list of statistical counters.
7026
7027 >>> x = Int('x')
7028 >>> s = Then('simplify', 'nlsat').solver()
7029 >>> s.add(x > 0)
7030 >>> s.check()
7031 sat
7032 >>> st = s.statistics()
7033 """
7034 return [Z3_stats_get_key(self.ctx.ref(), self.stats, idx) for idx in range(len(self))]
7035

Field Documentation

◆ ctx

◆ stats

stats = stats

Definition at line 6957 of file z3py.py.

Referenced by __deepcopy__(), __del__(), __getitem__(), __len__(), __repr__(), get_key_value(), and keys().