@@ -53,39 +53,16 @@ namespace DecompGraph::Core {
5353 * when adding support for operators with dynamic numbers of wires/params.
5454 */
5555struct OperatorNode {
56- std::string name;
57- int numWires{-1 };
58- int numParams{-1 };
56+ std::string id;
5957 bool adjoint{false };
6058
61- // Optional static arguments for operators that require additional data.
59+ // optional params, primarily for debug use
60+ std::string name{" " };
61+ int numWires{-1 };
62+ int numParams{-1 };
6263 std::unordered_map<std::string, std::string> staticNamedArgs{};
63- std::string id{" " };
6464
65- bool operator ==(const OperatorNode &other) const
66- {
67- // id match
68- if (!id.empty () && !other.id .empty () && id == other.id ) {
69- return true ;
70- }
71- // legacy fallback if either op is missing ID
72-
73- // For equality, we consider numWires and numParams conditionally equal
74- // if they are not set to -1 (which indicates a wildcard that can match any value).
75- const bool default_wires =
76- (numWires == -1 || other.numWires == -1 || numWires == other.numWires );
77- const bool default_params =
78- (numParams == -1 || other.numParams == -1 || numParams == other.numParams );
79-
80- // Static arguments are optional: if either side has no static args, they
81- // are treated as matching (wildcard). When both sides provide entries, the maps must
82- // be equal element-wise for the operators to be considered equivalent.
83- const bool static_args_match = staticNamedArgs.empty () || other.staticNamedArgs .empty () ||
84- staticNamedArgs == other.staticNamedArgs ;
85-
86- return name == other.name && default_wires && default_params && adjoint == other.adjoint &&
87- static_args_match;
88- }
65+ bool operator ==(const OperatorNode &other) const { return id == other.id ; }
8966 bool operator !=(const OperatorNode &other) const { return !(*this == other); }
9067};
9168
@@ -107,45 +84,24 @@ struct OperatorNode {
10784struct OperatorNodeHash {
10885 std::size_t operator ()(const OperatorNode &node) const
10986 {
110- // prefer id if available
111- if (!node.id .empty ()) {
112- return std::hash<std::string>{}(node.id );
113- }
114- return std::hash<std::string>{}(node.name );
87+ return std::hash<std::string>{}(node.id );
11588 }
11689};
11790
11891/* *
11992 * @brief This represents the weighted target gateset for the graph decomposition problem.
12093 */
12194struct WeightedGateset {
95+ // TODO: using ID here mandates that gatesets specify all legal IDs, rather than generic class
96+ // like "PauliRot". This should be updated to work on generic names
12297 std::unordered_map<OperatorNode, double , OperatorNodeHash> ops;
12398
124- [[nodiscard]] bool contains (const OperatorNode &op) const
125- {
126- // hash match
127- if (ops.find (op) != ops.end ()) {
128- return true ;
129- }
130-
131- // use op-matching if hashes failed (could be id vs name)
132- for (auto [gatesetOp, cost] : ops) {
133- if (gatesetOp == op) {
134- return true ;
135- }
136- }
137-
138- return false ;
139- }
99+ [[nodiscard]] bool contains (const OperatorNode &op) const { return ops.find (op) != ops.end (); }
140100
141101 [[nodiscard]] double getCost (const OperatorNode &op) const
142102 {
143103 auto it = ops.find (op);
144- if (it != ops.end ()) {
145- return it->second ;
146- }
147-
148- return std::numeric_limits<double >::infinity ();
104+ return it != ops.end () ? it->second : std::numeric_limits<double >::infinity ();
149105 }
150106};
151107
0 commit comments