quantum-compiler / quartz

The Quartz Quantum Compiler
Apache License 2.0
76 stars 19 forks source link

[Optimizer] Why do we use pointers in the hash function? #153

Closed xumingkuan closed 9 months ago

xumingkuan commented 9 months ago

In Graph::hash(), we have

https://github.com/quantum-compiler/quartz/blob/6c0cfd78ac7a09fa66d2dc58fc5cc52a4e970035/src/quartz/tasograph/tasograph.cpp#L441

If I understand correctly, the pointer (of type Gate *) is uniquely determined by the Context object and the GateType value. In this line, the GateType can only be GateType::input_qubit or GateType::input_param. So the resulting hash values for these Ops only have two possible values.

If we want to compare Graphs in different contexts, they will have different hash values because the Context objects are different. Is this intentional? If not, can we simply replace these pointers with gate types in the hash function?

zikun-li commented 9 months ago

The resulting hash values for these Ops only have two possible values.

I agree. This is unintentional. You can replace these pointers with gate types.