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

circuit.insert_at_frontier crashes when inserting GlobalPhaseOperation #4225

Closed
tanujkhattar opened this issue Jun 17, 2021 · 1 comment · Fixed by #4224
Closed

circuit.insert_at_frontier crashes when inserting GlobalPhaseOperation #4225

tanujkhattar opened this issue Jun 17, 2021 · 1 comment · Fixed by #4224
Labels
area/circuits complexity/low introduces/modifies 1-2 concepts, should take 1-2 days max for an advanced contributor 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. triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add

Comments

@tanujkhattar
Copy link
Collaborator

Description of the issue
circuit.insert_at_frontier fails when trying to insert GlobalPhaseOperation because the operation does not have any qubits. As a result, PointOptimizer also fails when the new_operations contain a GlobalPhaseOperation.

How to reproduce the issue

circuit = cirq.Circuit(cirq.X(q[0]))
circuit.insert_at_frontier(cirq.GlobalPhaseOperation(1j), 1)
Traceback (most recent call last):
  File "/Users/tanujkhattar/opt/anaconda3/envs/cirq/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3417, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-42-59dcb891d749>", line 2, in <module>
    circuit.insert_at_frontier(cirq.GlobalPhaseOperation(1j), 1)
  File "/Users/tanujkhattar/quantum/Cirq/cirq-core/cirq/circuits/circuit.py", line 2119, in insert_at_frontier
    insertion_indices, _ = self._pick_inserted_ops_moment_indices(flat_ops, start, frontier)
  File "/Users/tanujkhattar/quantum/Cirq/cirq-core/cirq/circuits/circuit.py", line 2014, in _pick_inserted_ops_moment_indices
    op_start = max(start, max(frontier[q] for q in op.qubits))
ValueError: max() arg is an empty sequence

Cirq version
0.12.0.dev

@tanujkhattar tanujkhattar added kind/bug-report Something doesn't seem to work. good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. area/circuits complexity/low introduces/modifies 1-2 concepts, should take 1-2 days max for an advanced contributor labels Jun 17, 2021
@cduck
Copy link
Collaborator

cduck commented Jun 17, 2021

I just ran into this bug earlier today (and added a one-line fix for it in #4224).

@tanujkhattar tanujkhattar added the triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add label Jun 19, 2021
CirqBot pushed a commit that referenced this issue Jul 7, 2021
Follow up to #4213.  Fixes #4083.  (Also contains a one-line change to fix #4225.)

I'm open to name suggestions for `MergeInteractionsToSqrtIswap`.
rht pushed a commit to rht/Cirq that referenced this issue May 1, 2023
Follow up to quantumlib#4213.  Fixes quantumlib#4083.  (Also contains a one-line change to fix quantumlib#4225.)

I'm open to name suggestions for `MergeInteractionsToSqrtIswap`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/circuits complexity/low introduces/modifies 1-2 concepts, should take 1-2 days max for an advanced contributor 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. triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants