Skip to content

Commit 1a2347a

Browse files
Added support for OpenQasm (#2797)
1 parent f9b6952 commit 1a2347a

16 files changed

+296
-3
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+5
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,11 @@
850850
],
851851
"owner": "Milania1"
852852
},
853+
"openqasm": {
854+
"title": "OpenQasm",
855+
"alias": "qasm",
856+
"owner": "RunDevelopment"
857+
},
853858
"oz": {
854859
"title": "Oz",
855860
"owner": "Golmote"

components/prism-openqasm.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// https://qiskit.github.io/openqasm/grammar/index.html
2+
3+
Prism.languages.openqasm = {
4+
'comment': /\/\*[\s\S]*?\*\/|\/\/.*/,
5+
'string': {
6+
pattern: /"[^"\r\n\t]*"|'[^'\r\n\t]*'/,
7+
greedy: true
8+
},
9+
10+
'keyword': /\b(?:barrier|boxas|boxto|break|const|continue|ctrl|def|defcal|defcalgrammar|delay|else|end|for|gate|gphase|if|in|include|inv|kernel|lengthof|let|measure|pow|reset|return|rotary|stretchinf|while|CX|OPENQASM|U)\b|#pragma\b/,
11+
'class-name': /\b(?:angle|bit|bool|creg|fixed|float|int|length|qreg|qubit|stretch|uint)\b/,
12+
'function': /\b(?:sin|cos|tan|exp|ln|sqrt|rotl|rotr|popcount)\b(?=\s*\()/,
13+
14+
'constant': /\b(?:pi|tau|euler)\b|[π𝜏]/,
15+
'number': {
16+
pattern: /(^|[^.\w$])(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?(?:dt|ns|us|µs|ms|s)?/i,
17+
lookbehind: true
18+
},
19+
'operator': /->|>>=?|<<=?|&&|\|\||\+\+|--|[!=<>&|~^+\-*/%]=?|@/,
20+
'punctuation': /[(){}\[\];,:.]/
21+
};
22+
23+
Prism.languages.qasm = Prism.languages.openqasm;

components/prism-openqasm.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-openqasm.html

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<h2>Full example</h2>
2+
<pre class="language-cpp"><code>// https://github.com/Qiskit/openqasm
3+
/*
4+
* Repeat-until-success circuit for Rz(theta),
5+
* cos(theta-pi)=3/5, from Nielsen and Chuang, Chapter 4.
6+
*/
7+
OPENQASM 3;
8+
include "stdgates.inc";
9+
10+
/*
11+
* Applies identity if out is 01, 10, or 11 and a Z-rotation by
12+
* theta + pi where cos(theta)=3/5 if out is 00.
13+
* The 00 outcome occurs with probability 5/8.
14+
*/
15+
def segment qubit[2]:anc, qubit:psi -> bit[2] {
16+
bit[2] b;
17+
reset anc;
18+
h anc;
19+
ccx anc[0], anc[1], psi;
20+
s psi;
21+
ccx anc[0], anc[1], psi;
22+
z psi;
23+
h anc;
24+
measure anc -> b;
25+
return b;
26+
}
27+
28+
qubit input;
29+
qubit ancilla[2];
30+
bit flags[2] = "11";
31+
bit output;
32+
33+
reset input;
34+
h input;
35+
36+
// braces are optional in this case
37+
while(int(flags) != 0) {
38+
flags = segment ancilla, input;
39+
}
40+
rz(pi - arccos(3 / 5)) input;
41+
h input;
42+
output = measure input; // should get zero
43+
</code></pre>

plugins/autoloader/prism-autoloader.js

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
"n4jsd": "n4js",
206206
"nani": "naniscript",
207207
"objc": "objectivec",
208+
"qasm": "openqasm",
208209
"objectpascal": "pascal",
209210
"px": "pcaxis",
210211
"pcode": "peoplecode",

plugins/autoloader/prism-autoloader.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/show-language/prism-show-language.js

+2
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@
147147
"objc": "Objective-C",
148148
"ocaml": "OCaml",
149149
"opencl": "OpenCL",
150+
"openqasm": "OpenQasm",
151+
"qasm": "OpenQasm",
150152
"parigp": "PARI/GP",
151153
"objectpascal": "Object Pascal",
152154
"psl": "PATROL Scripting Language",

0 commit comments

Comments
 (0)