A quantum computing simulator for OpenQASM.
go install github.com/itsubaki/qasm@latest% qasm -help
Usage of qasm:
-f string
filepath
-lex
Lex the input into a sequence of tokens
-max-qubits int
Maximum number of qubits (0 or less for unlimited)
-parse
Parse the input and convert it into an AST (abstract syntax tree)
-repl
REPL(read-eval-print loop) mode
-svg
Render the circuit as an SVG
-theme string
SVG theme (paper/cyber) (default "paper")
-top int
top results (default -1)
-validate
Validate the input without executing it
-verbose
Enable verbose output% qasm < testdata/bell.qasm
[00] ( 0.7071 0.0000i): 0.5000
[11] ( 0.7071 0.0000i): 0.5000% qasm -repl
qasm> OPENQASM 3.0;
qasm>
qasm> qubit[2]
6669
q;
qasm> U(pi/2, 0, pi) q[0];
qasm> gphase(-pi/4);
qasm>
qasm> ctrl @ U(pi, 0, pi) q[0], q[1];
qasm> ctrl @ gphase(-pi/2) q[0];
qasm>
qasm> :print
--- STATE ---
[00] ( 0.7071 0.0000i): 0.5000
[11] ( 0.7071 0.0000i): 0.5000
--- ENVIRONMENT ---
const : map[]
variable : map[]
bit : map[]
bit[] : map[]
qubit : map[]
qubit[] : map[q:[0 1]]
gate : []
subroutine: []% qasm -repl
qasm> OPENQASM 3.0;
qasm>
qasm> const float ratio = pi;
qasm> int n = 2;
qasm> if (n > 0) { n = n*ratio; }
qasm>
qasm> :print
--- STATE ---
--- ENVIRONMENT ---
const : map[ratio:3.141592653589793]
variable : map[n:6.283185307179586]
bit : map[]
bit[] : map[]
qubit : map[]
qubit[] : map[]
gate : []
subroutine: []% qasm -svg --theme cyber < testdata/svg/shor15.qasm > testdata/svg/shor15.svg