-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add warning when converting global phase operator to OpenQASM 2.0 #6476
Add warning when converting global phase operator to OpenQASM 2.0 #6476
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6476 +/- ##
=======================================
Coverage 97.75% 97.76%
=======================================
Files 1105 1105
Lines 94924 94936 +12
=======================================
+ Hits 92793 92810 +17
+ Misses 2131 2126 -5 ☔ View full report in Codecov by Sentry. |
@kenya-sk thanks for taking care of this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do the measurements need to change position?
@NoureldinYosri |
@@ -191,6 +191,24 @@ def test_h_gate_with_parameter(): | |||
) | |||
|
|||
|
|||
def test_qasm_global_pahse(): | |||
(q0,) = _make_qubits(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change this test into testing a use case. the example from the original issue should suffice
def test_qasm_global_pahse():
c = cirq.Circuit([cirq.global_phase_operation(np.exp(1j * 5))])
assert cirq.qasm(c) == ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for comment.
I changed test case for suitable issue. An if statement is added to qasm_output.py
to maintain compatibility of the output string with other cases. If this branch was not included, the output of a circuit consisting only of global phase gates would look like this. In this case, the global phase gate has no qubit to apply, but two newlines are added at the end because it is recognized as one of the operations.
Any comments on which representation is more appropriate would be appreciated.
"""OPENQASM 2.0;
include "qelib1.inc";
// Qubits: []
"""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just one more small change
output_line_gap(2) | ||
# In OpenQASM 2.0, the transformation of global phase gates is ignored. | ||
# Therefore, no newline is created when the operations contained in a circuit consist only of global phase gates. | ||
if not ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change the condition so that it works for the when the circuit has multiple global phases
if all(isinstance(op, ops.GlobalPhaseGate) for op in self.operations):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I overlooked that pattern. I've addressed it now.
Thank you for pointing it out!
Thank you @kenya-sk @NoureldinYosri. |
OpenQASM 2.0 does not support global phase (Qiskit/qiskit#7167 (comment)).
Therefore, the current implementation generated an error and terminated the program. Since the global phase does not affect the observation results, I have changed it to be supported as a warning and the program can be executed.
The following is how to handle the situation.
fixes #6457