Skip to content

Commit

Permalink
added python bindings for new core decorator functionalities
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonKlx committed Nov 5, 2024
1 parent 8c9ce51 commit 07a5251
Show file tree
Hide file tree
Showing 8 changed files with 979 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ namespace hal
/**
* @brief Constructs a `NetlistAbstraction` from a set of gates.
*
* @param[in] netlist - The netlist to abstract.
* @param[in] gates - The gates to include in the abstraction.
* @param[in] include_all_netlist_gates - If this flag is set, for all gates in the netlist, edges are created to the nearest gates that are part of the abstraction, otherwise this is only done for gates part of the abstraction.
* @param[in] exit_endpoint_filter - Filter condition to stop traversal on a fan-in/out endpoint.
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
*/
NetlistAbstraction(const std::vector<Gate*>& gates,
NetlistAbstraction(const Netlist* netlist,
const std::vector<Gate*>& gates,
const bool include_all_netlist_gates = false,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr);

Expand Down Expand Up @@ -244,7 +248,7 @@ namespace hal
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
* @returns OK() and a set of gates fulfilling the `target_gate_filter` condition on success, an error otherwise.
*/
Result<std::set<Gate*>> get_next_matching_gates(const Endpoint* endpoint,
Result<std::set<Gate*>> get_next_matching_gates(Endpoint* endpoint,
const PinDirection& direction,
const std::function<bool(const Gate*)>& target_gate_filter,
bool continue_on_match = false,
Expand Down Expand Up @@ -286,7 +290,7 @@ namespace hal
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
* @returns OK() and a set of gates fulfilling the `target_gate_filter` condition on success, an error otherwise.
*/
Result<std::set<Gate*>> get_next_matching_gates_until(const Endpoint* endpoint,
Result<std::set<Gate*>> get_next_matching_gates_until(Endpoint* endpoint,
const PinDirection& direction,
const std::function<bool(const Gate*)>& target_gate_filter,
bool continue_on_mismatch = false,
Expand Down Expand Up @@ -342,7 +346,7 @@ namespace hal
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
* @returns OK() and a set of gates fulfilling the `target_gate_filter` condition on success, an error otherwise.
*/
Result<std::set<Gate*>> get_next_matching_gates_internal(const std::vector<const Endpoint*>& start,
Result<std::set<Gate*>> get_next_matching_gates_internal(const std::vector<Endpoint*>& start,
const PinDirection& direction,
const std::function<bool(const Gate*)>& target_gate_filter,
bool continue_on_match,
Expand All @@ -360,7 +364,7 @@ namespace hal
* @param[in] entry_endpoint_filter - Filter condition to stop traversal on a successor/predecessor endpoint.
* @returns OK() and a set of gates fulfilling the `target_gate_filter` condition on success, an error otherwise.
*/
Result<std::set<Gate*>> get_next_matching_gates_until_internal(const std::vector<const Endpoint*>& start,
Result<std::set<Gate*>> get_next_matching_gates_until_internal(const std::vector<Endpoint*>& start,
const PinDirection& direction,
const std::function<bool(const Gate*)>& target_gate_filter,
bool continue_on_mismatch = false,
Expand Down
21 changes: 21 additions & 0 deletions include/hal_core/netlist/decorators/netlist_traversal_decorator.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,27 @@ namespace hal
*/
Result<std::set<Gate*>> get_next_matching_gates_until_depth(const Gate* gate, bool successors, u32 max_depth, const std::function<bool(const Gate*)>& target_gate_filter = nullptr) const;

/**
* Starting from the given endpoint, traverse the netlist and return only the successor/predecessor endpoints for which the `target_endpoint_filter` evaluates to `true`.
* Traverse over gates that do not meet the `target_endpoint_filter` condition.
* Stop traversal if (1) `continue_on_match` is `false` the `target_endpoint_filter` evaluates to `true`, (2) the `exit_endpoint_filter` evaluates to `false` on a fan-in/out endpoint (i.e., when exiting the current gate during traversal), or (3) the `entry_endpoint_filter` evaluates to `false` on a successor/predecessor endpoint (i.e., when entering the next gate during traversal).
* Both the `entry_endpoint_filter` and the `exit_endpoint_filter` may be omitted.
*
* @param[in] net - Start net.
* @param[in] successors - Set `true` to get successors, set `false` to get predecessors.
* @param[in] target_endpoint_filter - Filter condition that must be met for the target endpoints.
* @param[in] continue_on_match - Set `true` to continue even if `target_endpoint_filter` evaluated to `true`, `false` otherwise. Defaults to `false`.
* @param[in] exit_endpoint_filter - Filter condition that determines whether to stop traversal on a fan-in/out endpoint.
* @param[in] entry_endpoint_filter - Filter condition that determines whether to stop traversal on a successor/predecessor endpoint.
* @returns The next endpoints fulfilling the target endpoint filter condition on success, an error otherwise.
*/
Result<std::set<Endpoint*>> get_next_matching_endpoints(Endpoint* endpoint,
bool successors,
const std::function<bool(const Endpoint*)>& target_endpoint_filter,
bool continue_on_match = false,
const std::function<bool(const Endpoint*, const u32 current_depth)>& exit_endpoint_filter = nullptr,
const std::function<bool(const Endpoint*, const u32 current_depth)>& entry_endpoint_filter = nullptr) const;

/**
* Starting from the given net, traverse the netlist and return only the successor/predecessor endpoints for which the `target_endpoint_filter` evaluates to `true`.
* Traverse over gates that do not meet the `target_endpoint_filter` condition.
Expand Down
8 changes: 8 additions & 0 deletions include/hal_core/python_bindings/python_bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "hal_core/netlist/boolean_function/types.h"
#include "hal_core/netlist/decorators/boolean_function_decorator.h"
#include "hal_core/netlist/decorators/boolean_function_net_decorator.h"
#include "hal_core/netlist/decorators/netlist_abstraction_decorator.h"
#include "hal_core/netlist/decorators/netlist_modification_decorator.h"
#include "hal_core/netlist/decorators/netlist_traversal_decorator.h"
#include "hal_core/netlist/decorators/subgraph_netlist_decorator.h"
Expand Down Expand Up @@ -327,6 +328,13 @@ namespace hal
*/
void netlist_traversal_decorator_init(py::module& m);

/**
* Initializes Python bindings for the HAL netlist abstraction decorator in a python module.
*
* @param[in] m - the python module
*/
void netlist_abstraction_decorator_init(py::module& m);

/**
* Initializes Python bindings for the HAL LogManager in a python module.
*
Expand Down
12 changes: 12 additions & 0 deletions include/hal_core/utilities/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,18 @@ namespace hal
return std::set<T>(container.begin(), container.end());
}

/**
* Turn a given iterable collection into a unordered_set.
*
* @param[in] container - The input collection.
* @returns The unordered_set containing all items copied from the collection.
*/
template<typename T, template<typename, typename...> class Container, typename... Args>
CORE_API inline std::unordered_set<T> to_unordered_set(const Container<T, Args...>& container)
{
return std::unordered_set<T>(container.begin(), container.end());
}

/**
* Check whether one container is a subset of another container.
* The function checks whether all elements of the subset container are contained in the superset container.
Expand Down
Loading

0 comments on commit 07a5251

Please sign in to comment.