Skip to content
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

ValueError: Cannot output operation as QASM: cirq.global_phase_operation #6457

Closed
rht opened this issue Feb 10, 2024 · 4 comments · Fixed by #6476
Closed

ValueError: Cannot output operation as QASM: cirq.global_phase_operation #6457

rht opened this issue Feb 10, 2024 · 4 comments · Fixed by #6476
Assignees
Labels
good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. kind/bug-report Something doesn't seem to work. no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you. triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on

Comments

@rht
Copy link

rht commented Feb 10, 2024

Description of the issue

Circuits containing cirq.global_phase_operation can't be converted to QASM

How to reproduce the issue

import cirq
import numpy as np

c = cirq.Circuit([cirq.global_phase_operation(np.exp(1j * 5))])
cirq.qasm(c)
Traceback (most recent call last):
  File "/workspace/delete_global_phase_problem.py", line 5, in <module>
    cirq.qasm(c)
  File "/workspace/venv/lib/python3.11/site-packages/cirq/protocols/qasm.py", line 165, in qasm
    result = method(**kwargs)
             ^^^^^^^^^^^^^^^^
  File "/workspace/venv/lib/python3.11/site-packages/cirq/circuits/circuit.py", line 1315, in _qasm_
    return self.to_qasm()
           ^^^^^^^^^^^^^^
  File "/workspace/venv/lib/python3.11/site-packages/cirq/circuits/circuit.py", line 1359, in to_qasm
    return str(self._to_qasm_output(header, precision, qubit_order))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/venv/lib/python3.11/site-packages/cirq/circuits/qasm_output.py", line 245, in __str__
    self._write_qasm(lambda s: output.append(s))
  File "/workspace/venv/lib/python3.11/site-packages/cirq/circuits/qasm_output.py", line 299, in _write_qasm
    self._write_operations(self.operations, output, output_line_gap)
  File "/workspace/venv/lib/python3.11/site-packages/cirq/circuits/qasm_output.py", line 326, in _write_operations
    decomposed = protocols.decompose(
                 ^^^^^^^^^^^^^^^^^^^^
  File "/workspace/venv/lib/python3.11/site-packages/cirq/protocols/decompose_protocol.py", line 315, in decompose
    return [*_decompose_dfs(val, args)]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/venv/lib/python3.11/site-packages/cirq/protocols/decompose_protocol.py", line 223, in _decompose_dfs
    raise error
ValueError: Cannot output operation as QASM: cirq.global_phase_operation((0.28366218546322625-0.9589242746631385j))

Cirq version
1.3.0

@rht rht added the kind/bug-report Something doesn't seem to work. label Feb 10, 2024
@NoureldinYosri NoureldinYosri added the triage/discuss Needs decision / discussion, bring these up during Cirq Cynque label Feb 12, 2024
@NoureldinYosri
Copy link
Collaborator

cirq-cynk: global phase is a non qubit operation. AI: check if qasm has a way to represent non qubit operations. if yes add support for it.

short term solution: drop the operation and print a warning.

@verult verult added triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you. and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Feb 14, 2024
@tanujkhattar
Copy link
Collaborator

Qiskit/qiskit#7167 (comment) suggests that OpenQASM 2 doesn't support global phase operations. In the short term, we should just add a warning and ignore global phase operations when converting to OpenQASM.

We should also add support for OpenQASM 3 in Cirq. This has been requested for a while now - #4509

@kenya-sk
Copy link
Contributor

@NoureldinYosri @tanujkhattar
I'm interested in this issue. Can I try to implement a warning process?

@NoureldinYosri
Copy link
Collaborator

hi @kenya-sk , thanks for offering to help with this. I assigned the task to you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. kind/bug-report Something doesn't seem to work. no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you. triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants