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

Qasm3 exporter failing when if branch does not contain all clbits #8903

Closed
gabrieleagl opened this issue Oct 14, 2022 · 3 comments · Fixed by #8906
Closed

Qasm3 exporter failing when if branch does not contain all clbits #8903

gabrieleagl opened this issue Oct 14, 2022 · 3 comments · Fixed by #8906
Labels
bug Something isn't working

Comments

@gabrieleagl
Copy link
Contributor

gabrieleagl commented Oct 14, 2022

Environment

  • Qiskit Terra version: 0.39.0
  • Python version: 3.10.6
  • Operating system: MacOs 12.6 (21G115)

What is happening?

In some cases, the qasm3 exporter gives an error if the circuit has more clbits than needed in the if_else statement.

How can we reproduce the issue?

Run the following:

backend_wellington = provider.get_backend('ibm_wellington')

cr = ClassicalRegister(1) # if >1 breaks
cr2 = ClassicalRegister(1) # if this reg exists, breaks
qr = QuantumRegister(5)
qc = QuantumCircuit(qr, cr, cr2)

with qc.if_test((cr[0], 1)) as _:
    qc.cnot(0,1)
    qc.cnot(0,2)
    qc.cnot(0,3)
    qc.cnot(0,4)

qc_trans = transpile(qc, backend=backend_wellington, basis_gates=backend_wellington.configuration().basis_gates+['if_else'], optimization_level=1)
print(qasm3.Exporter().dumps(qc))
print(qasm3.Exporter().dumps(qc_trans))

Now, qc gets correctly exported, while qc_trans provides the following error:

QASM3ExporterError: 'Tried to push a scope whose circuit needs 2 clbits, but only provided 1 clbits to create the mapping.'

What should happen?

The QASM3 string should be output for both cases.

Any suggestions?

No response

@gabrieleagl gabrieleagl added the bug Something isn't working label Oct 14, 2022
@gabrieleagl
Copy link
Contributor Author

@jakelishman FYI

@jakelishman
Copy link
Member

Thanks for the report, though please don't tag me in everything - I'll see the issues anyway and tagging me messes with notification priorities.

@jakelishman
Copy link
Member

Ha, I know exactly what we've done here, and funnily enough I looked at the line of code responsible, thought about changing it and thought "nah, that's right". I can fix this no worries.

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