Uh oh!
There was an error while loading. Please reload this page.
Fix #177: Correct pattern export to OpenQASM 3 - #404
Conversation
This commit introduces `pattern_to_qasm3`, improving the export of patterns to OpenQASM 3: - Planes YZ and XZ are now handled correctly (TeamGraphix#177). - For plane XY, the angle is no longer ignored when the s-domain is empty. - Support for |0⟩ and |+⟩ initial states. - Arithmetic expressions unsupported by `qiskit-qasm3-import` are replaced with a simpler encoding, and the `single_qubit_domains` pass ensures compatibility with Qiskit. - `test_qasm3_exporter_to_qiskit.py` verifies that the Graphix pattern simulator and Qiskit AER simulator produce equivalent statevectors for exported circuits. Additionally, this commit fixes a regression from TeamGraphix#312: statevectors are now properly normalized.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@## master #404 +/- ##
==========================================
+ Coverage 85.03% 85.57% +0.54%
==========================================
Files 46 46 Lines 6654 6691 +37 ==========================================
+ Hits 5658 5726 +68 + Misses 996 965 -31 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| yield 'include "stdgates.inc";\n' | ||
| yield "\n" | ||
| for node in pattern.input_nodes: | ||
| yield f"// prepare input qubit {node} in |+⟩\n" |
There was a problem hiding this comment.
Isn't this misleading, since input qubits may be prepared in |+> or |0> ?
I think it should be moved to the branch elif state == BasicStates.PLUS: in :func: state_to_qasm3_lines, or alternatively
f"// prepare input qubit {node} in |+⟩ or |0⟩\n"There was a problem hiding this comment.
Nice catch! This is now fixed.
Uh oh!
There was an error while loading. Please reload this page.
| if cmd.plane == Plane.XY: | ||
| yield f"h q{cmd.node};\n" | ||
| if cmd.angle != 0: | ||
| rad_angle = angle_to_rad(cmd.angle) |
There was a problem hiding this comment.
Shouldn't we use angle_to_qasm3 ? (This would prevent errors if the cmd.angle is parametric).
There was a problem hiding this comment.
Yes, you are right, angle_to_qasm3 is better here. This is fixed.
| yield f"rx({-rad_angle}) q{cmd.node};\n" | ||
| elif cmd.plane == Plane.XZ: | ||
| yield f"ry({-rad_angle}) q{cmd.node};\n" | ||
| else: |
There was a problem hiding this comment.
To improve readability, I would suggest putting elif cmd.plane == Plane.YZ followed by typing_extensions.assert_never (or match. Actually I'm not sure if there is an advantage on using match over chained if-else, or if it's just a matter of taste. Would we need typing_extensions.assert_never if we were using match ?)
There was a problem hiding this comment.
Fixed. There is no default exhaustiveness check with match in Python, any more than with chained if/elif: we need to add a default clause, case e: assert_never(e), to ensure exhaustiveness.
| See :func:`pattern_to_qasm3`. | ||
| """ | ||
| yield "// generated by graphix\n" |
There was a problem hiding this comment.
Could it be useful to add graphix version here ? Not sure if we expose it at the moment, if not, I wouldn't bother adding it to this PR.
There was a problem hiding this comment.
Good idea. Fixed.
Uh oh!
There was an error while loading. Please reload this page.
This commit introduces
pattern_to_qasm3, improving the export of patterns to OpenQASM 3:Planes YZ and XZ are now handled correctly (QASM3 export only supports XY plane measurements #177).
For plane XY, the angle is no longer ignored when the s-domain is empty.
Support for |0⟩ and |+⟩ initial states.
Arithmetic expressions unsupported by
qiskit-qasm3-importare replaced with a simpler encoding, and thesingle_qubit_domainspass ensures compatibility with Qiskit.test_qasm3_exporter_to_qiskit.pyverifies that the Graphix pattern simulator and Qiskit AER simulator produce equivalent statevectors for exported circuits.