clingo.stats
Functions and classes related to solver stats.
Examples
The following example shows how to add custom stats and access the stats:
>>> from clingo.core import Library
>>> from clingo.control import Control
>>>
>>> def on_stats(step, accu):
... step.update({"example": [21]})
... accu.update({"example": [lambda x: (x or 0) + 21]})
...
>>> lib = Library()
>>> ctl = Control(lib, ['--stats'])
>>> ctl.parse_string("{a}.")
>>> ctl.ground()
>>> print(ctl.solve(on_stats=on_stats))
SAT
>>> print(ctl.solve(on_stats=on_stats))
SAT
>>> ctl.stats['user_step'].nestify()
{ "example": [21.0] }
>>> ctl.stats['user_accu'].nestify()
{ "example": [42.0] }
>>> ctl.stats['summary']['times'].nestify()
{ "cpu": 0.000785999999999995,
"sat": 7.867813110351562e-06,
"solve": 2.288818359375e-05,
"total": 0.0007848739624023438,
"unsat": 0.0 }
Note that the control object is created passing options --stats; without this
option only basic stats are reported.
Class representing solver stats.
Update the statistics with the given values.
Note that values can be inserted and changed but they cannot be deleted nor can their type be changed.
Arguments:
- values: A nested structure consisting of sequencens, mappings with string
keys, floats, and functions. The latter can be used to update
existing values. They receive the previous values as argument and must
return an updated value. If there is no previous value,
Noneis passed as argument.
Class representing an array of stats.
This class partially implements the mutable sequence protocol - elements of
arrays can be modified but they cannot be deleted. Modifications are
implemented via Stats.update.
Most use cases should be implementable just using the update function of the top-level statistics object.
Class representing a read-only array of stats.
This class partially implements the mutable sequence protocol.
Class representing a map of stats.
This class partially implements the mutable mapping protocol - value of keys
can be modified but they cannot be deleted. Modifications are implemented via
Stats.update.
Most use cases should be implementable just using the update function of the top-level statistics object.
Inherited Members
Class representing a read-only map of stats.
This class partially implements the mutable mapping protocol.
The type of a stats object.
Class representing read-only solver stats.