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

Quantum circuit with conditionals can cause RunTime error #1536

Closed
IlanIwumbwe opened this issue Aug 15, 2024 · 5 comments · Fixed by #1538
Closed

Quantum circuit with conditionals can cause RunTime error #1536

IlanIwumbwe opened this issue Aug 15, 2024 · 5 comments · Fixed by #1538
Assignees
Labels
bug Something isn't working

Comments

@IlanIwumbwe
Copy link

Benny and I found this by running a randomly generated circuit through the compiler.

Recreate with:

main_circ = Circuit(2, 2, "main_circ")
a = Symbol("a")
s_map = {a : -0.5}

# Adding creg resources 
creg_0 = main_circ.add_c_register("creg_0",2)

main_circ.Rz(1,0, condition = reg_eq(creg_0, 3))
main_circ.symbol_substitution(s_map)

main_circ.measure_all()

Results in:

AttributeError: 'pytket._tket.circuit.ClassicalOp' object has no attribute 'lower'

When we remove the symbol substitution, the code runs. After closer inspection, we found that symbol substitution changes Optype.RangePredicate ops into Optype.ClassicalOp even though optype is still stated as Optype.RangePredicate here

@cqc-alec
Copy link
Collaborator

Is the above the full code to reproduce? Running it works for me without error.

@IlanIwumbwe
Copy link
Author

No, here is the updated code snippet:

main_circ = Circuit(2, 2, "main_circ")
a = Symbol("a")
s_map = {a : -0.5}

# Adding creg resources 
creg_0 = main_circ.add_c_register("creg_0",2)

main_circ.Rz(1,0, condition = reg_eq(creg_0, 3))
main_circ.symbol_substitution(s_map)

main_circ.measure_all()

backend = AerBackend()
no_pass_circ = backend.get_compiled_circuit(main_circ, optimisation_level=0)
counts = backend.run_circuit(no_pass_circ).get_counts()

@cqc-alec cqc-alec self-assigned this Aug 15, 2024
@cqc-alec cqc-alec added the bug Something isn't working label Aug 15, 2024
@cqc-alec
Copy link
Collaborator

I think the bug here is that symbol_substitution() is implemented thus for all ClassicalOp types. But there is a whole hierarchy of types inheriting from ClassicalOp, including RangePredicateOp. So when we apply symbol_substitution to those we just get a ClassicalOp.

@IlanIwumbwe
Copy link
Author

Ah, that makes sense. Thank you for the quick response.

@cqc-alec
Copy link
Collaborator

Ah, that makes sense. Thank you for the quick response.

Thank you for raising the issue. Will work on a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants