-
Notifications
You must be signed in to change notification settings - Fork 129
Open
Description
Summary
Currently, different circuit conversion functions handle circuit simplification differently:
- QASM compiler (
qasm()): Now usesOptimise.canonicalize()upfront to recursively simplify the entire circuit before conversion - YaoToEinsum (
yao2einsum()): Only callsOptimise.to_basictypes()as a fallback on individual unsupported blocks
Concern
This inconsistency can lead to:
- Different conversion functions failing on the same circuit for different reasons
- Harder to maintain - each converter has its own simplification logic
- Potential bugs when new block types are added (need to update multiple places)
Proposal
Consider using Optimise.canonicalize() (or a similar standardized pre-processing step) consistently across all circuit conversion functions:
qasm()- ✅ already usescanonicalizeyao2einsum()- could benefit from upfront canonicalization- Any future converters
This would:
- Make conversions more robust and predictable
- Centralize simplification logic in one place
- Ensure all converters handle the same normalized circuit structure
Related
This issue was discovered while adding OpenQASM support (PR #578). The QASM compiler needed canonicalize to handle nested chains and convert gates like SqrtX, SqrtY, SqrtW to basic rotation gates.
Questions
- Should
canonicalizebe the standard pre-processing for all converters? - Are there cases where we explicitly don't want canonicalization?
- Should we document this as a convention for future converters?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels