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

More efficient QASM3 dumping of global barriers #13485

Open
TsafrirA opened this issue Nov 24, 2024 · 4 comments
Open

More efficient QASM3 dumping of global barriers #13485

TsafrirA opened this issue Nov 24, 2024 · 4 comments
Assignees
Labels
good first issue Good for newcomers mod: qasm3 Related to OpenQASM 3 import or export type: feature request New feature or request
Milestone

Comments

@TsafrirA
Copy link
Collaborator

What should we add?

Qiskit let's the user use global barriers in a circuit, for example:

from qiskit import QuantumCircuit

qc= QuantumCircuit(3)
qc.x(0)
qc.barrier()
qc.x(1)

However, when these barriers get dumped into QASM3, all qubits are explicitly listed:

from qiskit import qasm3

qasm3.dumps(qc)
OPENQASM 3.0;
include "stdgates.inc";
qubit[3] q;
x q[0];
barrier q[0], q[1], q[2];
x q[1];

While this is a valid QASM3 output, it doesn't use the declared support of global barriers in QASM3 via barrier;. For wide circuits this increases the output's size, parsing time, and even compile time down the line (as the global nature of the barrier needs to be checked for, or ignored).

@TsafrirA TsafrirA added the type: feature request New feature or request label Nov 24, 2024
@jakelishman
Copy link
Member

We can change this, no worries - we output this way because it's how it's stored internally, but it's fast for us to check whether it's global during the dump (our data model guarantees that each element of qargs is unique, so it's just a length check), so easy to swap.

We ought to check that the current Python-space parser can handle the global barrier too (I imagine it can), and that other packages depending on us can handle it

@jakelishman jakelishman added the mod: qasm3 Related to OpenQASM 3 import or export label Nov 24, 2024
@jakelishman jakelishman added this to the 2.0.0 milestone Nov 24, 2024
@jakelishman jakelishman added the good first issue Good for newcomers label Nov 24, 2024
@github-project-automation github-project-automation bot moved this to Tagged but unassigned in Contributor Monitoring Nov 24, 2024
@kibrahim757
Copy link

Hi , I would like to work on this one ,please assign me.

@jakelishman
Copy link
Member

I'm sorry, I forgot to come back and update this: I spoke offline with Tsafrir, and we determined that we know of several dependents of Qiskit at the moment that would fail to handle OpenQASM 3 global barrier; statements. In the interests of not breaking downstream users of Qiskit without warning, I think we should feature-gate the global barrier statement making it a non-default option to the exporters. That will mean adding a flag to qasm3.ExperimentalFeatures, and only writing out global barriers if that flag is set, otherwise using the explicit form.

Thanks for the offer - I'll assign you.

@kibrahim757
Copy link

Thanks, I understand the part about adding a flag to ExperimentalFeatures similar toSWITCH_CASE_V1, However I don't understand feature-gate part for the global barrier statement, Do you mean that I need to create another QuantumBarrier? as the existing one requires the operands or I am missing something ?

Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers mod: qasm3 Related to OpenQASM 3 import or export type: feature request New feature or request
Projects
Status: Tagged but unassigned
Development

No branches or pull requests

3 participants