wai/quantum-conformance/formats/ holds a module for each construct, each with the program it must read to (a reference held by the equivalence ladder), the outcomes it gives, a round trip back to its format, the formats it writes to, and every refusal with its code and its place: the QIR specification's two example programs, every intrinsic, a QIR 1 module with typed pointers, the profiles' refusals; jeff modules built field by field from the schema; the jeff project's own structured benchmarks and examples, unchanged; and OpenQASM sources written to each format, the QIR written pinned by its BLAKE3. CI runs it in wai-quantum-formats.yml, with the readers' and writers' unit tests. The jeff reader now converts integers to floats and floats to integers, and a QIR conversion is checked against the type it gives. Co-Authored-By: Claude Opus 5.5 <[email protected]>
121 lines
5.8 KiB
LLVM
121 lines
5.8 KiB
LLVM
; The adaptive profile's own example program (the QIR specification, MIT): a
|
|
; Bell pair whose second half is teleported twice, each step measuring in
|
|
; the middle and correcting on the result. The pair ends between qubits 0 and
|
|
; 5, so results 4 and 5 are equal on every shot.
|
|
|
|
@0 = internal constant [5 x i8] c"0_t0\00"
|
|
@1 = internal constant [5 x i8] c"0_t1\00"
|
|
|
|
define i64 @TeleportChain() local_unnamed_addr #0 {
|
|
entry:
|
|
call void @__quantum__rt__initialize(ptr null)
|
|
br label %body
|
|
|
|
body: ; preds = %entry
|
|
tail call void @__quantum__qis__h__body(ptr null)
|
|
tail call void @__quantum__qis__cnot__body(ptr null, ptr nonnull inttoptr (i64 1 to ptr))
|
|
tail call void @__quantum__qis__h__body(ptr nonnull inttoptr (i64 2 to ptr))
|
|
tail call void @__quantum__qis__cnot__body(ptr nonnull inttoptr (i64 2 to ptr), ptr nonnull inttoptr (i64 4 to ptr))
|
|
tail call void @__quantum__qis__h__body(ptr nonnull inttoptr (i64 3 to ptr))
|
|
tail call void @__quantum__qis__cnot__body(ptr nonnull inttoptr (i64 3 to ptr), ptr nonnull inttoptr (i64 5 to ptr))
|
|
tail call void @__quantum__qis__cnot__body(ptr nonnull inttoptr (i64 1 to ptr), ptr nonnull inttoptr (i64 2 to ptr))
|
|
tail call void @__quantum__qis__h__body(ptr nonnull inttoptr (i64 1 to ptr))
|
|
tail call void @__quantum__qis__mz__body(ptr nonnull inttoptr (i64 1 to ptr), ptr writeonly null)
|
|
tail call void @__quantum__qis__reset__body(ptr nonnull inttoptr (i64 1 to ptr))
|
|
%0 = tail call i1 @__quantum__rt__read_result(ptr readonly null)
|
|
br i1 %0, label %then__1, label %continue__1
|
|
|
|
; conditional quantum gate (only one in this block, but many can appear and the full quantum instruction set should be usable)
|
|
then__1: ; preds = %body
|
|
tail call void @__quantum__qis__z__body(ptr nonnull inttoptr (i64 4 to ptr))
|
|
br label %continue__1
|
|
|
|
continue__1: ; preds = %then__1, %body
|
|
tail call void @__quantum__qis__mz__body(ptr nonnull inttoptr (i64 2 to ptr), ptr writeonly nonnull inttoptr (i64 1 to ptr))
|
|
tail call void @__quantum__qis__reset__body(ptr nonnull inttoptr (i64 2 to ptr))
|
|
%1 = tail call i1 @__quantum__rt__read_result(ptr readonly nonnull inttoptr (i64 1 to ptr))
|
|
br i1 %1, label %then__2, label %continue__2
|
|
|
|
then__2: ; preds = %continue__1
|
|
tail call void @__quantum__qis__x__body(ptr nonnull inttoptr (i64 4 to ptr))
|
|
br label %continue__2
|
|
|
|
continue__2: ; preds = %then__2, %continue__1
|
|
tail call void @__quantum__qis__cnot__body(ptr nonnull inttoptr (i64 4 to ptr), ptr nonnull inttoptr (i64 3 to ptr))
|
|
tail call void @__quantum__qis__h__body(ptr nonnull inttoptr (i64 4 to ptr))
|
|
tail call void @__quantum__qis__mz__body(ptr nonnull inttoptr (i64 4 to ptr), ptr writeonly nonnull inttoptr (i64 2 to ptr))
|
|
tail call void @__quantum__qis__reset__body(ptr nonnull inttoptr (i64 4 to ptr))
|
|
%2 = tail call i1 @__quantum__rt__read_result(ptr readonly nonnull inttoptr (i64 2 to ptr))
|
|
br i1 %2, label %then__3, label %continue__3
|
|
|
|
then__3: ; preds = %continue__2
|
|
tail call void @__quantum__qis__z__body(ptr nonnull inttoptr (i64 5 to ptr))
|
|
br label %continue__3
|
|
|
|
continue__3: ; preds = %then__3, %continue__2
|
|
tail call void @__quantum__qis__mz__body(ptr nonnull inttoptr (i64 3 to ptr), ptr writeonly nonnull inttoptr (i64 3 to ptr))
|
|
tail call void @__quantum__qis__reset__body(ptr nonnull inttoptr (i64 3 to ptr))
|
|
%3 = tail call i1 @__quantum__rt__read_result(ptr readonly nonnull inttoptr (i64 3 to ptr))
|
|
br i1 %3, label %then__4, label %continue__4
|
|
|
|
then__4: ; preds = %continue__3
|
|
tail call void @__quantum__qis__x__body(ptr nonnull inttoptr (i64 5 to ptr))
|
|
br label %continue__4
|
|
|
|
continue__4: ; preds = %continue__3, %then__4
|
|
tail call void @__quantum__qis__mz__body(ptr null, ptr writeonly nonnull inttoptr (i64 4 to ptr))
|
|
tail call void @__quantum__qis__reset__body(ptr null)
|
|
tail call void @__quantum__qis__mz__body(ptr nonnull inttoptr (i64 5 to ptr), ptr writeonly nonnull inttoptr (i64 5 to ptr))
|
|
tail call void @__quantum__qis__reset__body(ptr nonnull inttoptr (i64 5 to ptr))
|
|
br label %exit
|
|
|
|
exit:
|
|
call void @__quantum__rt__result_record_output(ptr nonnull inttoptr (i64 4 to ptr), ptr @0)
|
|
call void @__quantum__rt__result_record_output(ptr nonnull inttoptr (i64 5 to ptr), ptr @1)
|
|
ret i64 0
|
|
}
|
|
|
|
; declarations of QIS functions
|
|
|
|
declare void @__quantum__qis__cnot__body(ptr, ptr) local_unnamed_addr
|
|
|
|
declare void @__quantum__qis__h__body(ptr) local_unnamed_addr
|
|
|
|
declare void @__quantum__qis__x__body(ptr) local_unnamed_addr
|
|
|
|
declare void @__quantum__qis__z__body(ptr) local_unnamed_addr
|
|
|
|
declare void @__quantum__qis__reset__body(ptr) local_unnamed_addr
|
|
|
|
declare void @__quantum__qis__mz__body(ptr, ptr writeonly) #1
|
|
|
|
; declarations of runtime functions
|
|
|
|
declare void @__quantum__rt__initialize(ptr)
|
|
|
|
declare i1 @__quantum__rt__read_result(ptr readonly)
|
|
|
|
declare void @__quantum__rt__result_record_output(ptr, ptr)
|
|
|
|
; attributes
|
|
|
|
attributes #0 = { "entry_point" "qir_profiles"="adaptive_profile" "output_labeling_schema"="schema_id" "required_num_qubits"="6" "required_num_results"="6" }
|
|
|
|
attributes #1 = { "irreversible" }
|
|
|
|
; module flags
|
|
|
|
!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}
|
|
|
|
!0 = !{i32 1, !"qir_major_version", i32 2}
|
|
!1 = !{i32 7, !"qir_minor_version", i32 0}
|
|
!2 = !{i32 1, !"dynamic_qubit_management", i1 false}
|
|
!3 = !{i32 1, !"dynamic_result_management", i1 false}
|
|
!4 = !{i32 5, !"int_computations", !10}
|
|
!5 = !{i32 5, !"float_computations", !11}
|
|
!6 = !{i32 1, !"ir_functions", i1 false}
|
|
!7 = !{i32 1, !"backwards_branching", i2 0}
|
|
!8 = !{i32 1, !"multiple_target_branching", i1 false}
|
|
!9 = !{i32 1, !"multiple_return_points", i1 false}
|
|
!10 = !{!"i32", !"i64"}
|
|
!11 = !{!"float", !"double"}
|