@@ -112,6 +112,35 @@ namespace hal
112112 :rtype: hal_py.machine_learning.graph.NetlistGraph
113113 )" );
114114
115+ m.def (
116+ " construct_sequential_netlist_graph" ,
117+ [](const Netlist* nl, const std::vector<Gate*>& gates, const machine_learning::GraphDirection& dir) -> std::optional<machine_learning::NetlistGraph> {
118+ auto res = machine_learning::construct_sequential_netlist_graph (nl, gates, dir);
119+ if (res.is_ok ())
120+ {
121+ return res.get ();
122+ }
123+ else
124+ {
125+ log_error (" python_context" , " error encountered while constructing sequential netlist graph:\n {}" , res.get_error ().get ());
126+ return std::nullopt ;
127+ }
128+ },
129+ py::arg (" nl" ),
130+ py::arg (" gates" ),
131+ py::arg (" dir" ),
132+ R"(
133+ Constructs a sequential netlist graph representation. The connections are an edge list of indices representing the position of the gates in the gates vector.
134+
135+ This function constructs a sequential graph representation of the netlist, capturing only the sequential dependencies between gates.
136+
137+ :param hal_py.Netlist nl: The netlist to operate on.
138+ :param list[hal_py.Gate] gates: The order of the gates, needed for the index representation.
139+ :param machine_learning.GraphDirection dir: The direction of the graph.
140+ :returns: A NetlistGraph representing the sequential connections within the netlist on success, None otherwise.
141+ :rtype: machine_learning.NetlistGraph or None
142+ )" );
143+
115144 // Bindings for annotate_netlist_graph
116145 m.def (" annotate_netlist_graph" ,
117146 &machine_learning::annotate_netlist_graph,
@@ -1099,7 +1128,7 @@ namespace hal
10991128
11001129 py_gate_pair_feature.def (
11011130 " build_feature_vec" ,
1102- [](const std::vector<const machine_learning::gate_pair_feature::GatePairFeature*>& features, const std::pair<const Gate*, const Gate*>& gate_pair) -> std::optional<std::vector<u32 >> {
1131+ [](const std::vector<const machine_learning::gate_pair_feature::GatePairFeature*>& features, const std::pair<Gate*, Gate*>& gate_pair) -> std::optional<std::vector<u32 >> {
11031132 auto res = machine_learning::gate_pair_feature::build_feature_vec (features, gate_pair);
11041133 if (res.is_ok ())
11051134 {
@@ -1126,7 +1155,7 @@ namespace hal
11261155 " build_feature_vec" ,
11271156 [](machine_learning::gate_pair_feature::FeatureContext& fc,
11281157 const std::vector<const machine_learning::gate_pair_feature::GatePairFeature*>& features,
1129- const std::pair<const Gate*, const Gate*>& gate_pair) -> std::optional<std::vector<u32 >> {
1158+ const std::pair<Gate*, Gate*>& gate_pair) -> std::optional<std::vector<u32 >> {
11301159 auto res = machine_learning::gate_pair_feature::build_feature_vec (fc, features, gate_pair);
11311160 if (res.is_ok ())
11321161 {
@@ -1154,7 +1183,7 @@ namespace hal
11541183 py_gate_pair_feature.def (
11551184 " build_feature_vecs" ,
11561185 [](const std::vector<const machine_learning::gate_pair_feature::GatePairFeature*>& features,
1157- const std::vector<std::pair<const Gate*, const Gate*>>& gate_pairs) -> std::optional<std::vector<std::vector<u32 >>> {
1186+ const std::vector<std::pair<Gate*, Gate*>>& gate_pairs) -> std::optional<std::vector<std::vector<u32 >>> {
11581187 auto res = machine_learning::gate_pair_feature::build_feature_vecs (features, gate_pairs);
11591188 if (res.is_ok ())
11601189 {
@@ -1181,7 +1210,7 @@ namespace hal
11811210 " build_feature_vecs" ,
11821211 [](machine_learning::gate_pair_feature::FeatureContext& fc,
11831212 const std::vector<const machine_learning::gate_pair_feature::GatePairFeature*>& features,
1184- const std::vector<std::pair<const Gate*, const Gate*>>& gate_pairs) -> std::optional<std::vector<std::vector<u32 >>> {
1213+ const std::vector<std::pair<Gate*, Gate*>>& gate_pairs) -> std::optional<std::vector<std::vector<u32 >>> {
11851214 auto res = machine_learning::gate_pair_feature::build_feature_vecs (fc, features, gate_pairs);
11861215 if (res.is_ok ())
11871216 {
@@ -1297,7 +1326,7 @@ namespace hal
12971326 py_gate_pair_label_class.def (
12981327 " calculate_gate_pairs" ,
12991328 [](const machine_learning::gate_pair_label::GatePairLabel& self, machine_learning::gate_pair_label::LabelContext& lc, const Netlist* nl, const std::vector<Gate*>& gates)
1300- -> std::optional<std::vector<std::pair<const Gate*, const Gate*>>> {
1329+ -> std::optional<std::vector<std::pair<Gate*, Gate*>>> {
13011330 auto res = self.calculate_gate_pairs (lc, nl, gates);
13021331 if (res.is_ok ())
13031332 {
@@ -1378,9 +1407,8 @@ namespace hal
13781407
13791408 py_gate_pair_label_class.def (
13801409 " calculate_labels" ,
1381- [](const machine_learning::gate_pair_label::GatePairLabel& self,
1382- machine_learning::gate_pair_label::LabelContext& lc) -> std::optional<std::pair<std::vector<std::pair<const Gate*, const Gate*>>, std::vector<std::vector<u32 >>>> {
1383- auto res = self.calculate_labels (lc);
1410+ [](const machine_learning::gate_pair_label::GatePairLabel& self, const Netlist* netlist) -> std::optional<std::pair<std::vector<std::pair<Gate*, Gate*>>, std::vector<std::vector<u32 >>>> {
1411+ auto res = self.calculate_labels (netlist);
13841412 if (res.is_ok ())
13851413 {
13861414 return res.get ();
@@ -1395,26 +1423,43 @@ namespace hal
13951423 R"(
13961424 Calculate both gate pairs and their labels within the labeling context.
13971425
1398- :param machine_learning.gate_pair_label.LabelContext lc : The labeling context .
1426+ :param hal_py.netlist : The netlist to create labels for .
13991427 :returns: A pair containing gate pairs and corresponding labels on success, None otherwise.
14001428 :rtype: tuple[list[tuple[hal_py.Gate, hal_py.Gate]], list[list[int]]] or None
14011429 )" );
14021430
1431+ py_gate_pair_label_class.def (" to_string" ,
1432+ &machine_learning::gate_pair_label::GatePairLabel::to_string,
1433+ R"(
1434+ Get the string representation of the gate pair label.
1435+
1436+ :returns: The string representation.
1437+ :rtype: str
1438+ )" );
1439+
14031440 py::class_<machine_learning::gate_pair_label::SharedSignalGroup, machine_learning::gate_pair_label::GatePairLabel> py_shared_signal_group (py_gate_pair_label,
14041441 " SharedSignalGroup" ,
14051442 R"(
14061443 Labels gate pairs based on shared signal groups.
14071444 )" );
14081445
1409- py_shared_signal_group.def (py::init<>(),
1446+ py_shared_signal_group.def (py::init<const PinDirection&, const u32 , const double >(),
1447+ py::arg (" direction" ),
1448+ py::arg (" min_pair_count" ),
1449+ py::arg (" negative_to_positive_factor" ),
14101450 R"(
1411- Default constructor.
1412- )" );
1451+ Construct a SharedSignalGroup.
1452+
1453+ :param hal_py.PinDirection direction: The pin direction.
1454+ :param int min_pair_count: The minimum pair count.
1455+ :param float negative_to_positive_factor: The negative to positive factor.
1456+ )" );
1457+ ;
14131458
14141459 py_shared_signal_group.def (
14151460 " calculate_gate_pairs" ,
14161461 [](const machine_learning::gate_pair_label::SharedSignalGroup& self, machine_learning::gate_pair_label::LabelContext& lc, const Netlist* nl, const std::vector<Gate*>& gates)
1417- -> std::optional<std::vector<std::pair<const Gate*, const Gate*>>> {
1462+ -> std::optional<std::vector<std::pair<Gate*, Gate*>>> {
14181463 auto res = self.calculate_gate_pairs (lc, nl, gates);
14191464 if (res.is_ok ())
14201465 {
@@ -1497,8 +1542,8 @@ namespace hal
14971542 py_shared_signal_group.def (
14981543 " calculate_labels" ,
14991544 [](const machine_learning::gate_pair_label::SharedSignalGroup& self,
1500- machine_learning::gate_pair_label::LabelContext& lc ) -> std::optional<std::pair<std::vector<std::pair<const Gate*, const Gate*>>, std::vector<std::vector<u32 >>>> {
1501- auto res = self.calculate_labels (lc );
1545+ const Netlist* netlist ) -> std::optional<std::pair<std::vector<std::pair<Gate*, Gate*>>, std::vector<std::vector<u32 >>>> {
1546+ auto res = self.calculate_labels (netlist );
15021547 if (res.is_ok ())
15031548 {
15041549 return res.get ();
@@ -1513,11 +1558,20 @@ namespace hal
15131558 R"(
15141559 Calculate both gate pairs and their labels based on shared signal groups within the labeling context.
15151560
1516- :param machine_learning.gate_pair_label.LabelContext lc : The labeling context .
1561+ :param hal_py.netlist : The netlist to create labels for .
15171562 :returns: A pair containing gate pairs and corresponding labels on success, None otherwise.
15181563 :rtype: tuple[list[tuple[hal_py.Gate, hal_py.Gate]], list[list[int]]] or None
15191564 )" );
15201565
1566+ py_shared_signal_group.def (" to_string" ,
1567+ &machine_learning::gate_pair_label::SharedSignalGroup::to_string,
1568+ R"(
1569+ Get the string representation of the gate pair label.
1570+
1571+ :returns: The string representation.
1572+ :rtype: str
1573+ )" );
1574+
15211575 py::class_<machine_learning::gate_pair_label::SharedConnection, machine_learning::gate_pair_label::GatePairLabel> py_shared_connection (py_gate_pair_label,
15221576 " SharedConnection" ,
15231577 R"(
@@ -1532,7 +1586,7 @@ namespace hal
15321586 py_shared_connection.def (
15331587 " calculate_gate_pairs" ,
15341588 [](const machine_learning::gate_pair_label::SharedConnection& self, machine_learning::gate_pair_label::LabelContext& lc, const Netlist* nl, const std::vector<Gate*>& gates)
1535- -> std::optional<std::vector<std::pair<const Gate*, const Gate*>>> {
1589+ -> std::optional<std::vector<std::pair<Gate*, Gate*>>> {
15361590 auto res = self.calculate_gate_pairs (lc, nl, gates);
15371591 if (res.is_ok ())
15381592 {
@@ -1615,8 +1669,8 @@ namespace hal
16151669 py_shared_connection.def (
16161670 " calculate_labels" ,
16171671 [](const machine_learning::gate_pair_label::SharedConnection& self,
1618- machine_learning::gate_pair_label::LabelContext& lc ) -> std::optional<std::pair<std::vector<std::pair<const Gate*, const Gate*>>, std::vector<std::vector<u32 >>>> {
1619- auto res = self.calculate_labels (lc );
1672+ const Netlist* netlist ) -> std::optional<std::pair<std::vector<std::pair<Gate*, Gate*>>, std::vector<std::vector<u32 >>>> {
1673+ auto res = self.calculate_labels (netlist );
16201674 if (res.is_ok ())
16211675 {
16221676 return res.get ();
@@ -1631,11 +1685,20 @@ namespace hal
16311685 R"(
16321686 Calculate both gate pairs and their labels based on shared connections within the labeling context.
16331687
1634- :param machine_learning.gate_pair_label.LabelContext lc : The labeling context .
1688+ :param hal_py.netlist : The netlist to create labels for .
16351689 :returns: A pair containing gate pairs and corresponding labels on success, None otherwise.
16361690 :rtype: tuple[list[tuple[hal_py.Gate, hal_py.Gate]], list[list[int]]] or None
16371691 )" );
16381692
1693+ py_shared_connection.def (" to_string" ,
1694+ &machine_learning::gate_pair_label::SharedConnection::to_string,
1695+ R"(
1696+ Get the string representation of the gate pair label.
1697+
1698+ :returns: The string representation.
1699+ :rtype: str
1700+ )" );
1701+
16391702#ifndef PYBIND11_MODULE
16401703 return m.ptr ();
16411704#endif // PYBIND11_MODULE
0 commit comments