-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix empty-barrier handling in OpenQASM 2 (#10469)
The new parser would allow a `barrier;` statement, implicitly broadcasting it across all qubits in scope. This is technically not supported by the OpenQASM 2 specification, but is a useful quality-of-life extension to the specification (in the same way that Qiskit interprets barriers, and the OpenQASM 3 specification defines the `barrier;` statement). The precise rule is added to the new parser's `strict` mode. The OpenQASM 2 _exporter_ similarly should not have been putting out `barrier;` statements. These could only occur in Qiskit when a barrier was explicitly constructed with zero elements (as opposed to the call `QuantumCircuit.barrier()`, which has the all-in-scope behaviour), and consequently have no actual meaning or effect. The exporter is modified to simply skip such instructions, for as long as Qiskit permits the qubitless barrier statement.
- Loading branch information
1 parent
845746d
commit e75893d
Showing
5 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
releasenotes/notes/qasm2-fix-zero-op-barrier-4af211b119d5b24d.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
fixes: | ||
- | | ||
The OpenQASM 2 parser (:func:`.qasm2.load` and :func:`~.qasm2.loads`) running in ``strict`` mode | ||
will now correctly emit an error if a ``barrier`` statement has no arguments. When running in | ||
the (default) more permissive mode, an argument-less ``barrier`` statement will continue to | ||
cause a barrier on all qubits currently in scope (the qubits a gate definition affects, or all | ||
the qubits defined by a program, if the statement is in a gate body or in the global scope, | ||
respectively). | ||
- | | ||
The OpenQASM 2 exporter (:meth:`.QuantumCircuit.qasm`) will now no longer attempt | ||
to output ``barrier`` statements that act on no qubits. Such a barrier statement has no effect | ||
in Qiskit either, but is invalid OpenQASM 2. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters