5 #include "pybind11/operators.h"
6 #include "pybind11/pybind11.h"
7 #include "pybind11/stl.h"
8 #include "pybind11/stl_bind.h"
10 namespace py = pybind11;
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 Generates the Boolean influence of each input variable of a Boolean function using the internal HAL functions only
100 The function is slower, but can be better used in multithreading enviroment.
102 :param hal_py.BooleanFunction bf: The Boolean function.
103 :param int num_evaluations: The amount of evaluations that are performed for each input variable.
104 :returns: A dict from the variables that appear in the function to their Boolean influence on said function 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 The Boolean function gets translated to a z3::expr and afterwards efficient c code.
126 The program is compiled and executed many times to measure the Boolean influence of each input variable.
128 :param hal_py.BooleanFunction bf: The Boolean function.
129 :param int num_evaluations: The amount of evaluations that are performed for each input variable.
130 :returns: A dict from the variables that appear in the function to their Boolean influence on said function on success, None otherwise.
131 :rtype: dict[str,float] or None
135 "get_boolean_influence_with_z3_expr",
136 [](
const BooleanFunction& bf,
const u32 num_evaluations = 32000) -> std::optional<std::unordered_map<std::string, double>> {
144 log_error(
"python_context",
"cannot get Boolean influence of Boolean function:\n{}", res.get_error().get());
149 py::arg(
"num_evaluations") = 32000,
151 Generates the Boolean influence of each input variable of a Boolean function using z3 expressions and substitutions/simplifications only.
152 The function is slower, but can be better used in multithreading environment.
154 :param hal_py.BooleanFunction bf: The Boolean function.
155 :param int num_evaluations: The amount of evaluations that are performed for each input variable.
156 :returns: A dict from the variables that appear in the function to their Boolean influence on said function on success, None otherwise.
157 :rtype: dict[str,float] or None
161 "get_boolean_influences_of_subcircuit",
162 [](
const std::vector<Gate*>& gates,
const Net* start_net,
const u32 num_evaluations = 32000) -> std::optional<std::map<Net*, double>> {
170 log_error(
"python_context",
"cannot get Boolean influence of subcircuit function:\n{}", res.get_error().get());
175 py::arg(
"start_net"),
176 py::arg(
"num_evaluations") = 32000,
178 Generates the function of the net using only the given gates.
179 Afterwards the generated function gets translated from a z3::expr to efficient c code, compiled, executed and evaluated.
181 :param list[hal_py.Gate] gates: The gates of the subcircuit.
182 :param hal_py.Net start_net: The output net of the subcircuit at which to start the analysis.
183 :param int num_evaluations: The amount of evaluations that are performed for each input variable.
184 :returns: A dict from the nets that appear in the function of the start net to their Boolean influence on said function on success, None otherwise.
185 :rtype: dict[hal_py.Net,float] or None
189 "get_boolean_influences_of_gate",
190 [](
const Gate* gate,
const u32 num_evaluations = 32000) -> std::optional<std::map<Net*, double>> {
198 log_error(
"python_context",
"cannot get Boolean influence of flip-flop data fan-in:\n{}", res.get_error().get());
203 py::arg(
"num_evaluations") = 32000,
205 Generates the function of the dataport net of the given flip-flop.
206 Afterwards the generated function gets translated from a z3::expr to efficient c code, compiled, executed and evaluated.
208 :param hal_py.Gate gate: The flip-flop which data input net is used to build the boolean function.
209 :param int num_evaluations: The amount of evaluations that are performed for each input variable.
210 :returns: A dict from the nets that appear in the function of the data net to their Boolean influence on said function on success, None otherwise.
211 :rtype: dict[hal_py.Net,float]
215 "get_boolean_influence_deterministic",
216 [](
const BooleanFunction& bf) -> std::optional<std::unordered_map<std::string, double>> {
224 log_error(
"python_context",
"cannot get Boolean influence of Boolean function:\n{}", res.get_error().get());
230 The Boolean function gets translated to a z3::expr and afterwards efficient c code.
231 The program is compiled and executed exactly once for every possible input mapping to accurately determine the boolean influence of each variable.
233 :param hal_py.BooleanFunction bf: The Boolean function.
234 :returns: A dict from the variables that appear in the function to their Boolean influence on said function on success, None otherwise.
235 :rtype: dict[str,float] or None
239 "get_boolean_influences_of_subcircuit_deterministic",
240 [](
const std::vector<Gate*>& gates,
const Net* start_net) -> std::optional<std::map<Net*, double>> {
248 log_error(
"python_context",
"cannot get Boolean influence of subcircuit function:\n{}", res.get_error().get());
253 py::arg(
"start_net"),
255 Generates the function of the net using only the given gates.
256 Afterwards the generated function gets translated from a z3::expr to efficient c code, compiled, executed and evaluated.
258 :param list[hal_py.Gate] gates: The gates of the subcircuit.
259 :param hal_py.Net start_net: The output net of the subcircuit at which to start the analysis.
260 :returns: A dict from the nets that appear in the function of the start net to their Boolean influence on said function on success, None otherwise.
261 :rtype: dict[hal_py.Net,float] or None
265 "get_boolean_influences_of_gate_deterministic",
266 [](
const Gate* gate) -> std::optional<std::map<Net*, double>> {
274 log_error(
"python_context",
"cannot get Boolean influence of flip-flop data fan-in:\n{}", res.get_error().get());
280 Generates the function of the dataport net of the given flip-flop.
281 Afterwards the generated function gets translated from a z3::expr to efficient c code, compiled, executed and evaluated.
283 :param hal_py.Gate gate: The flip-flop which data input net is used to build the boolean function.
284 :returns: A dict from the nets that appear in the function of the data net to their Boolean influence on said function on success, None otherwise.
285 :rtype: dict[hal_py.Net,float]
289 "get_ff_dependency_matrix",
290 [](
const Netlist* nl,
bool with_boolean_influence) -> std::optional<std::pair<std::map<u32, Gate*>, std::vector<std::vector<double>>>> {
298 log_error(
"python_context",
"{}", res.get_error().get());
303 py::arg(
"with_boolean_influence"),
305 Get the FF dependency matrix of a netlist, with or without boolean influences.
307 :param hal_py.Netlist netlist: The netlist to extract the dependency matrix from.
308 :param bool with_boolean_influence: True -- set boolean influence, False -- sets 1.0 if connection between FFs
309 :returns: A pair consisting of std::map<u32, Gate*>, which includes the mapping from the original gate
310 :rtype: pair(dict(int, hal_py.Gate), list[list[double]])
314 #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.