Skip to content

Commit 59fa065

Browse files
committed
Deploying to main from @ openqasm/openqasm@58481e1 🚀
1 parent 3b7c7fc commit 59fa065

File tree

8 files changed

+96
-32
lines changed

8 files changed

+96
-32
lines changed

_sources/language/directives.rst.txt

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,50 @@
11
Directives
22
==========
33

4-
OpenQASM supports directive mechanisms that allows other information to
4+
OpenQASM supports directive mechanisms that allow other information to
55
be included in the program. Directives are either pragmas or annotations.
66
Both are used to supply additional information to the compiler passes and the
77
target system or simulator. Ideally the meaning of the program does not change
88
if some or all of the directives are ignored, so they can be interpreted
99
at the discretion of the consuming process.
1010

11+
Pragma and annotation namespacing
12+
---------------------------------
13+
14+
It is intended that different implementators of the specification might
15+
define their own pragmas and annotations. This creates the possibility that
16+
different implementations might define pragmas or annotations that collide.
17+
18+
To avoid such collisions we recommend that implementations namespace their
19+
pragmas and annotations as follows:
20+
21+
- Pragmas start with `pragma <namespace>.<name>(.<name>)*`.
22+
- Annotations start with `@<namespace>.<name>(.<name>)*`.
23+
24+
Where `namespace` and `name` are valid OpenQASM identifiers.
25+
26+
If the pragma or annotation takes additional arguments the
27+
final `<name>` should be followed by a single space before the
28+
additional text.
29+
30+
The namespace should be a short name that identifies the organization that
31+
defines behaviour of the pragmas and annotations contained within it.
32+
33+
The namespace `openqasm` is reserved for future use by the OpenQASM
34+
specification.
35+
36+
1137
Pragmas
1238
-------
1339

1440
Pragma directives start with ``pragma`` and continue to the end of line. The
1541
text after ``pragma`` is a single string, and parsing is left to the specific
16-
implementation. Implementations may optionally choose to support the older ``#pragma``
17-
keyword as a custom extension.
42+
implementation, although implementors are encourage to use the namespacing
43+
described above.
44+
45+
Implementations may optionally choose to support the older ``#pragma`` keyword
46+
as a custom extension.
47+
1848
Pragmas should be processed as soon as they are encountered; if a
1949
pragma is not supported by a compiler pass it should be ignored and preserved
2050
intact for future passes. Pragmas should avoid stateful or positional
@@ -30,7 +60,7 @@ documentation for supported pragmas.
3060

3161
.. code-block::
3262
33-
pragma simulator noise model "qpu1.noise"
63+
pragma qiskit.simulator noise model "qpu1.noise"
3464
3565
Pragmas can also be used to specify system-level information or assertions for
3666
the entire circuit.
@@ -40,10 +70,10 @@ the entire circuit.
4070
OPENQASM 3.0;
4171
4272
// Attach billing information
43-
pragma user alice account 12345678
73+
pragma ibm.user alice account 12345678
4474
4575
// Assert that the QPU is healthy to run this circuit
46-
pragma max_temp qpu 0.4
76+
pragma ibm.max_temp qpu 0.4
4777
4878
qubit[2] q;
4979
@@ -53,7 +83,8 @@ Annotations
5383

5484
Annotations can be added to supply additional information to the following
5585
OpenQASM ``statement`` as defined in the grammar. Annotations will start with a
56-
``@`` symbol, have an identifying keyword and continue to the end of the line.
86+
``@`` symbol, have a dotted list of identifying keywords and continue to the end
87+
of the line.
5788

5889
Multiple annotations may be added to a single statement. No ordering or
5990
interaction between annotations are prescribed by this specification.
@@ -69,21 +100,21 @@ documentation for supported annotations.
69100
input bit[2] control_flags;
70101
71102
// Instruct compiler to create a reversible version of the function
72-
@reversible
103+
@openqasm.reversible
73104
gate multiply a, b, x {
74105
x = a * b;
75106
}
76107
77108
// Prevent swap insertion
78-
@noswap
109+
@openqasm.noswap
79110
box {
80111
rx(pi) q[0];
81112
cnot q[0], q[3];
82113
}
83114
84115
// Apply multiple annotations
85-
@crosstalk
86-
@noise profile "gate_noise.qnf"
116+
@openqasm.crosstalk
117+
@openqasm.noise profile "gate_noise.qnf"
87118
defcal noisy_gate $0 $1 { ... }
88119
89120

grammar/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ <h1>OpenQASM 3.0 Grammar<a class="headerlink" href="#openqasm-3-0-grammar" title
316316
<span class="linenos"> 38</span><span class="nl">DEFAULT</span><span class="p">:</span><span class="w"> </span><span class="s1">&#39;default&#39;</span><span class="p">;</span>
317317
<span class="linenos"> 39</span>
318318
<span class="linenos"> 40</span><span class="nl">PRAGMA</span><span class="p">:</span><span class="w"> </span><span class="s1">&#39;#&#39;</span><span class="o">?</span><span class="w"> </span><span class="s1">&#39;pragma&#39;</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nv">pushMode</span><span class="o">(</span><span class="no">EAT_TO_LINE_END</span><span class="o">)</span><span class="p">;</span>
319-
<span class="linenos"> 41</span><span class="nl">AnnotationKeyword</span><span class="p">:</span><span class="w"> </span><span class="s1">&#39;@&#39;</span><span class="w"> </span><span class="no">Identifier</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nv">pushMode</span><span class="o">(</span><span class="no">EAT_TO_LINE_END</span><span class="o">)</span><span class="p">;</span>
319+
<span class="linenos"> 41</span><span class="nl">AnnotationKeyword</span><span class="p">:</span><span class="w"> </span><span class="s1">&#39;@&#39;</span><span class="w"> </span><span class="no">Identifier</span><span class="w"> </span><span class="o">(</span><span class="s1">&#39;.&#39;</span><span class="w"> </span><span class="no">Identifier</span><span class="o">)*</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nv">pushMode</span><span class="o">(</span><span class="no">EAT_TO_LINE_END</span><span class="o">)</span><span class="p">;</span>
320320
<span class="linenos"> 42</span>
321321
<span class="linenos"> 43</span>
322322
<span class="linenos"> 44</span><span class="c">/* Types. */</span>

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ <h1>OpenQASM Live Specification<a class="headerlink" href="#openqasm-version-spe
9494
</ul>
9595
</li>
9696
<li class="toctree-l2"><a class="reference internal" href="language/directives.html">Directives</a><ul>
97+
<li class="toctree-l3"><a class="reference internal" href="language/directives.html#pragma-and-annotation-namespacing">Pragma and annotation namespacing</a></li>
9798
<li class="toctree-l3"><a class="reference internal" href="language/directives.html#pragmas">Pragmas</a></li>
9899
<li class="toctree-l3"><a class="reference internal" href="language/directives.html#annotations">Annotations</a></li>
99100
</ul>
@@ -133,7 +134,7 @@ <h1>OpenQASM Live Specification<a class="headerlink" href="#openqasm-version-spe
133134
</li>
134135
<li class="toctree-l1"><a class="reference internal" href="grammar/index.html">OpenQASM 3.0 Grammar</a></li>
135136
<li class="toctree-l1"><a class="reference internal" href="release_notes.html">Release Notes</a><ul>
136-
<li class="toctree-l2"><a class="reference internal" href="release_notes.html#spec-v3-1-0-22">spec/v3.1.0-22</a><ul>
137+
<li class="toctree-l2"><a class="reference internal" href="release_notes.html#spec-v3-1-0-23">spec/v3.1.0-23</a><ul>
137138
<li class="toctree-l3"><a class="reference internal" href="release_notes.html#new-features">New Features</a></li>
138139
<li class="toctree-l3"><a class="reference internal" href="release_notes.html#upgrade-notes">Upgrade Notes</a></li>
139140
<li class="toctree-l3"><a class="reference internal" href="release_notes.html#bug-fixes">Bug Fixes</a></li>

language/directives.html

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,41 @@
3535

3636
<section id="directives">
3737
<h1>Directives<a class="headerlink" href="#directives" title="Link to this heading"></a></h1>
38-
<p>OpenQASM supports directive mechanisms that allows other information to
38+
<p>OpenQASM supports directive mechanisms that allow other information to
3939
be included in the program. Directives are either pragmas or annotations.
4040
Both are used to supply additional information to the compiler passes and the
4141
target system or simulator. Ideally the meaning of the program does not change
4242
if some or all of the directives are ignored, so they can be interpreted
4343
at the discretion of the consuming process.</p>
44+
<section id="pragma-and-annotation-namespacing">
45+
<h2>Pragma and annotation namespacing<a class="headerlink" href="#pragma-and-annotation-namespacing" title="Link to this heading"></a></h2>
46+
<p>It is intended that different implementators of the specification might
47+
define their own pragmas and annotations. This creates the possibility that
48+
different implementations might define pragmas or annotations that collide.</p>
49+
<p>To avoid such collisions we recommend that implementations namespace their
50+
pragmas and annotations as follows:</p>
51+
<ul class="simple">
52+
<li><p>Pragmas start with <cite>pragma &lt;namespace&gt;.&lt;name&gt;(.&lt;name&gt;)*</cite>.</p></li>
53+
<li><p>Annotations start with <cite>&#64;&lt;namespace&gt;.&lt;name&gt;(.&lt;name&gt;)*</cite>.</p></li>
54+
</ul>
55+
<p>Where <cite>namespace</cite> and <cite>name</cite> are valid OpenQASM identifiers.</p>
56+
<p>If the pragma or annotation takes additional arguments the
57+
final <cite>&lt;name&gt;</cite> should be followed by a single space before the
58+
additional text.</p>
59+
<p>The namespace should be a short name that identifies the organization that
60+
defines behaviour of the pragmas and annotations contained within it.</p>
61+
<p>The namespace <cite>openqasm</cite> is reserved for future use by the OpenQASM
62+
specification.</p>
63+
</section>
4464
<section id="pragmas">
4565
<h2>Pragmas<a class="headerlink" href="#pragmas" title="Link to this heading"></a></h2>
4666
<p>Pragma directives start with <code class="docutils literal notranslate"><span class="pre">pragma</span></code> and continue to the end of line. The
4767
text after <code class="docutils literal notranslate"><span class="pre">pragma</span></code> is a single string, and parsing is left to the specific
48-
implementation. Implementations may optionally choose to support the older <code class="docutils literal notranslate"><span class="pre">#pragma</span></code>
49-
keyword as a custom extension.
50-
Pragmas should be processed as soon as they are encountered; if a
68+
implementation, although implementors are encourage to use the namespacing
69+
described above.</p>
70+
<p>Implementations may optionally choose to support the older <code class="docutils literal notranslate"><span class="pre">#pragma</span></code> keyword
71+
as a custom extension.</p>
72+
<p>Pragmas should be processed as soon as they are encountered; if a
5173
pragma is not supported by a compiler pass it should be ignored and preserved
5274
intact for future passes. Pragmas should avoid stateful or positional
5375
interactions to avoid unexpected behaviors between included source files. If the
@@ -57,18 +79,18 @@ <h2>Pragmas<a class="headerlink" href="#pragmas" title="Link to this heading">¶
5779
<p>*Note: The following examples are simply possible implementations, this
5880
specification does not define any pragmas. Please consult your tool’s
5981
documentation for supported pragmas.</p>
60-
<div class="highlight-qasm3 notranslate"><div class="highlight"><pre><span></span><span class="cp">pragma</span> simulator noise model &quot;qpu1.noise&quot;
82+
<div class="highlight-qasm3 notranslate"><div class="highlight"><pre><span></span><span class="cp">pragma</span> qiskit.simulator noise model &quot;qpu1.noise&quot;
6183
</pre></div>
6284
</div>
6385
<p>Pragmas can also be used to specify system-level information or assertions for
6486
the entire circuit.</p>
6587
<div class="highlight-qasm3 notranslate"><div class="highlight"><pre><span></span><span class="cp">OPENQASM</span><span class="w"> </span><span class="l">3.0</span><span class="p">;</span>
6688

6789
<span class="c1">// Attach billing information</span>
68-
<span class="cp">pragma</span> user alice account 12345678
90+
<span class="cp">pragma</span> ibm.user alice account 12345678
6991

7092
<span class="c1">// Assert that the QPU is healthy to run this circuit</span>
71-
<span class="cp">pragma</span> max_temp qpu 0.4
93+
<span class="cp">pragma</span> ibm.max_temp qpu 0.4
7294

7395
<span class="kt">qubit</span><span class="p">[</span><span class="m">2</span><span class="p">]</span><span class="w"> </span><span class="n">q</span><span class="p">;</span>
7496
</pre></div>
@@ -78,7 +100,8 @@ <h2>Pragmas<a class="headerlink" href="#pragmas" title="Link to this heading">¶
78100
<h2>Annotations<a class="headerlink" href="#annotations" title="Link to this heading"></a></h2>
79101
<p>Annotations can be added to supply additional information to the following
80102
OpenQASM <code class="docutils literal notranslate"><span class="pre">statement</span></code> as defined in the grammar. Annotations will start with a
81-
<code class="docutils literal notranslate"><span class="pre">&#64;</span></code> symbol, have an identifying keyword and continue to the end of the line.</p>
103+
<code class="docutils literal notranslate"><span class="pre">&#64;</span></code> symbol, have a dotted list of identifying keywords and continue to the end
104+
of the line.</p>
82105
<p>Multiple annotations may be added to a single statement. No ordering or
83106
interaction between annotations are prescribed by this specification.</p>
84107
<p>*Note: The following examples are simply possible implementations, this
@@ -89,21 +112,21 @@ <h2>Annotations<a class="headerlink" href="#annotations" title="Link to this hea
89112
<span class="kt">input</span><span class="w"> </span><span class="kt">bit</span><span class="p">[</span><span class="m">2</span><span class="p">]</span><span class="w"> </span><span class="n">control_flags</span><span class="p">;</span>
90113

91114
<span class="c1">// Instruct compiler to create a reversible version of the function</span>
92-
<span class="nd">@reversible</span>
115+
<span class="nd">@openqasm</span>.reversible
93116
<span class="kd">gate</span><span class="w"> </span><span class="nf">multiply</span><span class="w"> </span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">{</span>
94117
<span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">b</span><span class="p">;</span>
95118
<span class="p">}</span>
96119

97120
<span class="c1">// Prevent swap insertion</span>
98-
<span class="nd">@noswap</span>
121+
<span class="nd">@openqasm</span>.noswap
99122
<span class="k">box</span><span class="w"> </span><span class="p">{</span>
100123
<span class="w"> </span><span class="nf">rx</span><span class="p">(</span><span class="no">pi</span><span class="p">)</span><span class="w"> </span><span class="n">q</span><span class="p">[</span><span class="m">0</span><span class="p">];</span>
101124
<span class="w"> </span><span class="nf">cnot</span><span class="w"> </span><span class="n">q</span><span class="p">[</span><span class="m">0</span><span class="p">],</span><span class="w"> </span><span class="n">q</span><span class="p">[</span><span class="m">3</span><span class="p">];</span>
102125
<span class="p">}</span>
103126

104127
<span class="c1">// Apply multiple annotations</span>
105-
<span class="nd">@crosstalk</span>
106-
<span class="nd">@noise</span> profile &quot;gate_noise.qnf&quot;
128+
<span class="nd">@openqasm</span>.crosstalk
129+
<span class="nd">@openqasm</span>.noise profile &quot;gate_noise.qnf&quot;
107130
<span class="kd">defcal</span><span class="w"> </span><span class="nf">noisy_gate</span><span class="w"> </span><span class="l">$0</span><span class="w"> </span><span class="l">$1</span><span class="w"> </span><span class="p">{</span><span class="x"> ... </span><span class="p">}</span>
108131
</pre></div>
109132
</div>
@@ -227,6 +250,7 @@ <h3>Navigation</h3>
227250
<li class="toctree-l2"><a class="reference internal" href="subroutines.html">Subroutines</a></li>
228251
<li class="toctree-l2"><a class="reference internal" href="scope.html">Scoping of variables</a></li>
229252
<li class="toctree-l2 current"><a class="current reference internal" href="#">Directives</a><ul>
253+
<li class="toctree-l3"><a class="reference internal" href="#pragma-and-annotation-namespacing">Pragma and annotation namespacing</a></li>
230254
<li class="toctree-l3"><a class="reference internal" href="#pragmas">Pragmas</a></li>
231255
<li class="toctree-l3"><a class="reference internal" href="#annotations">Annotations</a></li>
232256
</ul>

language/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
</ul>
159159
</li>
160160
<li class="toctree-l1"><a class="reference internal" href="directives.html">Directives</a><ul>
161+
<li class="toctree-l2"><a class="reference internal" href="directives.html#pragma-and-annotation-namespacing">Pragma and annotation namespacing</a></li>
161162
<li class="toctree-l2"><a class="reference internal" href="directives.html#pragmas">Pragmas</a></li>
162163
<li class="toctree-l2"><a class="reference internal" href="directives.html#annotations">Annotations</a></li>
163164
</ul>

objects.inv

-2 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)