Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a precompile workload #7

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading