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

Fixes a bug causing infinite run when using conditional with empty body #2243

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gadial
Copy link
Contributor

@gadial gadial commented Oct 6, 2024

Summary

This PR fixes a bug where using a conditional with an empty body causes an infinite loop when running the simulator.

Fixes #2230

Details and comments

When using a conditional with an empty body, e.g.

with main_circ.if_test((creg_0[0],0)) as else_1:
    pass
with else_1:
    pass

The simulator gets stuck in an infinite loop.

It seems the underlying cause of the problem is that when a conditional command has an empty body, it has empty qargs list as well. This means that the jump and mark commands generated by Aer will have empty qubits list and hence after a transpiler pass they may be relocated nondeterministically to any part of the circuit (they are usually placed between two barriers, but without qubits the DAG-to-circuit algorithm will not consider the barriers part of their topological order).

The attempted fix is adding

if len(qargs) == 0:
            qargs = parent.qubits

To ensure the commands remain between the barriers.

@gadial gadial requested review from hhorii and doichanj October 6, 2024 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simulator can run indefinately when running circuits with conditionals
1 participant