-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for semantic equality checking of
Expr
s in DAGCircuit
s
This adds support to semantically check the variables of `Expr` nodes that occur within `DAGCircuit` constructs, using similar logic to the remapping done by the existing condition checks. As a knock-on effect of how the control-flow introspection was added to allow these checks, the canonicalisation performed by `qiskit.test._canonical.canonicalize_control_flow` is now inherent to the `DAGCircuit` equality methods, largely removing the need for that explicit canonical form in tests. The dispatch of `QuantumCircuit.__eq__` to `DAGCircuit.__eq__` means that direct comparisons of `QuantumCircuit`s will also benefit from this change. As a partial implementation detail, the semantic checking is achieved and defined by the function `expr.structurally_equivalent`, with key functions for mapping the variables. The naming discrepancy (semantic versus structural) is deliberate. Classical expressions are considered "equal" if and only if their tree structures match exactly; there is no attempt to move the classical expressions into some canonical form, as this is not typically simple; even mathematically symmetric operations typically impact the order of sub-expression evaluation, and we don't want to get into the weeds of that. Better to just define equality as "structurally exactly equal", and have the key function just so alpha-renaming-compatible variables can still be canonicalised into something that can be compared between expressions.
- Loading branch information
1 parent
574da7e
commit fa3df7a
Showing
7 changed files
with
482 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.