5 #include "pybind11/operators.h"
6 #include "pybind11/pybind11.h"
7 #include "pybind11/stl.h"
8 #include "pybind11/stl_bind.h"
18 #ifdef PYBIND11_MODULE
19 PYBIND11_MODULE(boolean_influence, m)
21 m.doc() =
"Set of functions to determine the influence of variables of a Boolean function on its output.";
25 py::module m(
"boolean_influence",
"Set of functions to determine the influence of variables of a Boolean function on its output.");
28 py::class_<BooleanInfluencePlugin, RawPtrWrapper<BooleanInfluencePlugin>,
BasePluginInterface> py_boolean_influence_plugin(m,
"BooleanInfluencePlugin");
31 The name of the plugin.
37 Get the name of the plugin.
39 :returns: The name of the plugin.
44 The version of the plugin.
50 Get the version of the plugin.
52 :returns: The version of the plugin.
57 The description of the plugin.
63 Get the description of the plugin.
65 :returns: The description of the plugin.
70 A set of plugin names that this plugin depends on.
76 Get a set of plugin names that this plugin depends on.
78 :returns: A set of plugin names that this plugin depends on.
83 "get_boolean_influence",
84 [](
const BooleanFunction& bf,
const u32 num_evaluations = 32000) -> std::optional<std::unordered_map<std::string, double>> {
92 log_error(
"python_context",
"cannot get Boolean influence of Boolean function:\n{}", res.get_error().get());
97 py::arg(
"num_evaluations") = 32000,
99 Compute the Boolean influence of each input variable of a Boolean function.
100 The influence is approximated by evaluating the function on randomly sampled input assignments.
102 :param hal_py.BooleanFunction bf: The Boolean function.
103 :param int num_evaluations: The number of evaluations that are performed for each input variable.
104 :returns: A dict from each variable of the function to its Boolean influence on success, ``None`` otherwise.
105 :rtype: dict[str,float] or None
109 "get_boolean_influence_with_hal_boolean_function_class",
110 [](
const BooleanFunction& bf,
const u32 num_evaluations = 32000) -> std::optional<std::unordered_map<std::string, double>> {
118 log_error(
"python_context",
"cannot get Boolean influence of Boolean function:\n{}", res.get_error().get());
123 py::arg(
"num_evaluations") = 32000,
125 Compute the Boolean influence of each input variable of a Boolean function using only HAL-internal functionality.
126 The influence is approximated by evaluating the function on randomly sampled input assignments.
127 This variant is slower than ``get_boolean_influence``, but it is better suited for use in a multi-threaded environment.
129 :param hal_py.BooleanFunction bf: The Boolean function.
130 :param int num_evaluations: The number of evaluations that are performed for each input variable.
131 :returns: A dict from each variable of the function to its Boolean influence on success, ``None`` otherwise.
132 :rtype: dict[str,float] or None
136 "get_boolean_influence_with_z3_expr",
137 [](
const BooleanFunction& bf,
const u32 num_evaluations = 32000) -> std::optional<std::unordered_map<std::string, double>> {
145 log_error(
"python_context",
"cannot get Boolean influence of Boolean function:\n{}", res.get_error().get());
150 py::arg(
"num_evaluations") = 32000,
152 Compute the Boolean influence of each input variable of a Boolean function using only z3 substitution and simplification.
153 The influence is approximated by evaluating the function on randomly sampled input assignments.
154 This variant is slower than ``get_boolean_influence``, but it is better suited for use in a multi-threaded environment.
156 :param hal_py.BooleanFunction bf: The Boolean function.
157 :param int num_evaluations: The number of evaluations that are performed for each input variable.
158 :returns: A dict from each variable of the function to its Boolean influence on success, ``None`` otherwise.
159 :rtype: dict[str,float] or None
163 "get_boolean_influences_of_subcircuit",
164 [](
const std::vector<Gate*>& gates,
const Net* start_net,
const u32 num_evaluations = 32000) -> std::optional<std::map<Net*, double>> {
172 log_error(
"python_context",
"cannot get Boolean influence of subcircuit function:\n{}", res.get_error().get());
177 py::arg(
"start_net"),
178 py::arg(
"num_evaluations") = 32000,
181 Compute the Boolean influence of each input net of a subcircuit on one of its output nets.
182 The Boolean function of the start net is built from the given gates, translated into C code, and then compiled and executed for speed.
183 The influence is approximated by evaluating that function on randomly sampled input assignments.
185 :param list[hal_py.Gate] gates: The gates of the subcircuit.
186 :param hal_py.Net start_net: The output net of the subcircuit at which to start the analysis.
187 :param int num_evaluations: The number of evaluations that are performed for each input variable.
188 :returns: A dict from each input net of the subcircuit to its Boolean influence on the start net on success, ``None`` otherwise.
189 :rtype: dict[hal_py.Net,float] or None
193 "get_boolean_influences_of_gate",
194 [](
const Gate* gate,
const u32 num_evaluations = 32000) -> std::optional<std::map<Net*, double>> {
202 log_error(
"python_context",
"cannot get Boolean influence of flip-flop data fan-in:\n{}", res.get_error().get());
207 py::arg(
"num_evaluations") = 32000,
210 Compute the Boolean influence of each net that drives the data input of the given flip-flop.
211 The Boolean function of the data input net is built, translated into C code, and then compiled and executed for speed.
212 The influence is approximated by evaluating that function on randomly sampled input assignments.
214 :param hal_py.Gate gate: The flip-flop whose data input net is used to build the Boolean function.
215 :param int num_evaluations: The number of evaluations that are performed for each input variable.
216 :returns: A dict from each net of the function to its Boolean influence on the data input net on success, ``None`` otherwise.
217 :rtype: dict[hal_py.Net,float]
221 "get_boolean_influence_deterministic",
222 [](
const BooleanFunction& bf) -> std::optional<std::unordered_map<std::string, double>> {
230 log_error(
"python_context",
"cannot get Boolean influence of Boolean function:\n{}", res.get_error().get());
236 Compute the exact Boolean influence of each input variable of a Boolean function.
237 In contrast to ``get_boolean_influence``, the function is evaluated on every possible input assignment instead of a random sample.
238 This is only feasible for functions of at most 16 variables.
240 :param hal_py.BooleanFunction bf: The Boolean function.
241 :returns: A dict from each variable of the function to its Boolean influence on success, ``None`` otherwise.
242 :rtype: dict[str,float] or None
246 "get_boolean_influences_of_subcircuit_deterministic",
247 [](
const std::vector<Gate*>& gates,
const Net* start_net) -> std::optional<std::map<Net*, double>> {
255 log_error(
"python_context",
"cannot get Boolean influence of subcircuit function:\n{}", res.get_error().get());
260 py::arg(
"start_net"),
263 Compute the exact Boolean influence of each input net of a subcircuit on one of its output nets.
264 In contrast to ``get_boolean_influences_of_subcircuit``, the function is evaluated on every possible input assignment instead of a random sample.
265 This is only feasible for subcircuits with at most 16 input nets.
267 :param list[hal_py.Gate] gates: The gates of the subcircuit.
268 :param hal_py.Net start_net: The output net of the subcircuit at which to start the analysis.
269 :returns: A dict from each input net of the subcircuit to its Boolean influence on the start net on success, ``None`` otherwise.
270 :rtype: dict[hal_py.Net,float] or None
274 "get_boolean_influences_of_gate_deterministic",
275 [](
const Gate* gate) -> std::optional<std::map<Net*, double>> {
283 log_error(
"python_context",
"cannot get Boolean influence of flip-flop data fan-in:\n{}", res.get_error().get());
290 Compute the exact Boolean influence of each net that drives the data input of the given flip-flop.
291 In contrast to ``get_boolean_influences_of_gate``, the function is evaluated on every possible input assignment instead of a random sample.
292 This is only feasible for data input functions of at most 16 nets.
294 :param hal_py.Gate gate: The flip-flop whose data input net is used to build the Boolean function.
295 :returns: A dict from each net of the function to its Boolean influence on the data input net on success, ``None`` otherwise.
296 :rtype: dict[hal_py.Net,float]
300 "get_ff_dependency_matrix",
301 [](
const Netlist* nl,
bool with_boolean_influence) -> std::optional<std::pair<std::map<u32, Gate*>, std::vector<std::vector<double>>>> {
309 log_error(
"python_context",
"{}", res.get_error().get());
314 py::arg(
"with_boolean_influence"),
316 Get the flip-flop dependency matrix of a netlist, i.e., a matrix that holds an entry for every pair of flip-flops that are connected through combinational logic.
318 :param hal_py.Netlist netlist: The netlist to extract the dependency matrix from.
319 :param bool with_boolean_influence: Set ``True`` to use the Boolean influence as the matrix entry, ``False`` to use ``1.0`` for every connection.
320 :returns: A tuple consisting of a dict from the original gate IDs to the corresponding matrix indices and the flip-flop dependency matrix itself, ``None`` otherwise.
321 :rtype: tuple(dict[int,hal_py.Gate], list[list[float]]) or None
325 #ifndef PYBIND11_MODULE
std::string get_name() const override
Get the name of the plugin.
std::string get_version() const override
Get the version of the plugin.
std::string get_description() const override
Get a short description of the plugin.
std::set< std::string > get_dependencies() const override
Get the plugin dependencies.
#define log_error(channel,...)
const Module * module(const Gate *g, const NodeBoxes &boxes)
Result< std::map< Net *, double > > get_boolean_influences_of_subcircuit(const std::vector< Gate * > &gates, const Net *start_net, const u32 num_evaluations=32000)
Result< std::map< Net *, double > > get_boolean_influences_of_gate(const Gate *gate, const u32 num_evaluations=32000)
Result< std::unordered_map< std::string, double > > get_boolean_influence_with_z3_expr(const BooleanFunction &bf, const u32 num_evaluations)
Result< std::map< Net *, double > > get_boolean_influences_of_subcircuit_deterministic(const std::vector< Gate * > &gates, const Net *start_net)
Result< std::unordered_map< std::string, double > > get_boolean_influence_deterministic(const BooleanFunction &bf)
Result< std::unordered_map< std::string, double > > get_boolean_influence(const BooleanFunction &bf, const u32 num_evaluations=32000)
Result< std::map< Net *, double > > get_boolean_influences_of_gate_deterministic(const Gate *gate)
Result< std::pair< std::map< u32, Gate * >, std::vector< std::vector< double > > > > get_ff_dependency_matrix(const Netlist *netlist, bool with_boolean_influence)
Result< std::unordered_map< std::string, double > > get_boolean_influence_with_hal_boolean_function_class(const BooleanFunction &bf, const u32 num_evaluations)
This file contains all functions related to the HAL plugin API.