Skip to content

Commit

Permalink
Merge pull request #7 from jlapeyre/try-precompile
Browse files Browse the repository at this point in the history
Add a precompile workload
  • Loading branch information
kshyatt-aws authored Oct 31, 2024
2 parents 6724dd5 + eadb3b2 commit 91e6a42
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Quasar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1819,4 +1819,6 @@ function (v::AbstractVisitor)(program_expr::QasmExpression)
return v
end

include("precompile.jl")

end
35 changes: 35 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@setup_workload begin
# Putting some things in `setup` can reduce the size of the
# precompile file and potentially make loading faster.
using Quasar
@compile_workload begin
# all calls in this block will be precompiled, regardless of whether
# they belong to your package or not (on Julia 1.8 and higher)
qasm_src = """OPENQASM 3.0;
gate h a { U(π/2, 0, π) a; gphase(-π/4);};
gate x a { U(π, 0, π) a; gphase(-π/2);};
gate cx a, b { ctrl @ x a, b; };
def bell(qubit q0, qubit q1) {
h q0;
cx q0, q1;
}
qubit[2] q;
bell(q[0], q[1]);
bit[2] b = "00";
b[0] = measure q[0];
b[1] = measure q[1];
bell(q[0], q[1]);
int xx = 1;
xx = 3;
"""
parsed = Quasar.parse_qasm(qasm_src)
Quasar.dt_type[] = Quasar.Nanosecond
Quasar.builtin_gates[] = Quasar.basic_builtin_gates
Quasar.visit_pragma[] = Quasar.basic_visit_pragma
Quasar.parse_pragma[] = Quasar.basic_parse_pragma
visitor = Quasar.QasmProgramVisitor()
visitor(parsed);
end
end

0 comments on commit 91e6a42

Please sign in to comment.