Quantum Computing Programs Compilation Framework

scaffcc a framework for compilation and analysis l.w
1 / 29
Embed
Share

Explore ScaffCC, a framework for compiling and analyzing quantum computing programs, including quantum advantage, background on quantum computers, compiling quantum codes, goals and contributions, benchmarks, and scaffold programs with quantum circuits.

  • Quantum Computing
  • Compilation Framework
  • Quantum Advantage
  • Quantum Computers
  • Benchmarks

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. ScaffCC: A Framework for Compilation and Analysis of Quantum Computing Programs Ali JavadiAbhari, Shruti Patil, Daniel Kudrow, Jeff Heckey, Alexey Lvov, Frederic T. Chong, Margaret Martonosi Princeton University, UC Santa Barbara, IBM 1

  2. Quantum Computing Advantage A certain class of problems can be solved significantly faster by changing the paradigm of computing: use quantum mechanical systems to store and manipulate information. Example: Factoring a large b-bit number Asymptotic Complexity 232-digit number factoring 2000 years on a single-core AMD Opteron [Kelinjung et al. 2010] Best classical algorithm (GNFS) [Buhler 1994] (technology dependent theoretically large speedup) Shor's quantum algorithm 2 2

  3. Background on Quantum Computers A quantum bit (qubit) can exist in a superposition of states: Quantum operations (gates) transform the state of qubits. Measurement (observation)collapsesit to either or . Quantum computation is reversible. Quantum Assembly qbit a[1], b[5]; H(b[0]); H(b[1]); H(b[2]); H(b[3]); H(b[4]); Z(a[0]); CNOT(a[0],b[1]); 3 3

  4. Compiling Quantum Codes Data types and instructions in quantum computers: Qubits, quantum gates Decoherence requires QECC Logical vs. Physical Levels Efficiency crucial Inefficiencies at logical level are amplified into greater physical level QECC requirements. Logical Physical 4 4

  5. Goals and Contributions 1) Identifying differences in compiling for quantum vs. classical computers 2) Providing good scalability to practical algorithm sizes 3) Automatically synthesizing reversible computation (e.g. for math functions) 4) Developing important program analysis passes 5 5

  6. Benchmarks Classical Time Complexity Quantum Time Complexity Benchmark Grover s Search Binary Welded Tree (BWT) Ground State Estimation (GSE) Triangle Finding Problem (TFP) Boolean Formula (BF) Class Number (CN) 6 6

  7. Scaffold Programs and Quantum Circuits #include <math.h> #define n 5 #define N pow(2,n) // main module module main() { // allocated qubits in main qbit a[n], b[n], t[1]; // classical bits : measurement outcome cbit ma[n]; // iteration bound int nstep = floor((pi/4)*sqrt(N)) . . // Grover iteration: Repeat O(N^0.5) times for (istep=1; istep<=nstep; istep++) { Sqr(a,b); EQxMark(b, t, 0); Sqr(a,b); diffuse(a); } . . // measure a to find outcome for(i=0; i<n; i++) ma[i] = measZ(a[i]); } // module prototypes module Sqr(qbit a[n], qbit b[n]); module EQxMark(qbit b[n], qbit t[1], int tF); // diffusion module module diffuse(qbit q[n]) { // allocate qubits local to module qbit x[n-1]; } // Hadamard applied to q for(j = 0; j < n; j++) H(q[j]); ... 7

  8. From Scaffold to QASM: Deep Optimization through LLVM ScaffCC translates from Scaffold Programming Language to QASM assembly language. Implemented with LLVM, a rich and mature compiler framework. Modified Clang front-end parses and converts ScaffCC to LLVM Intermediate Representation. Generation Classical Control Resolution Clang Front- end QASM Scaffold Program QASM LLVM-IR 8 8

  9. Scalability in Compilation and Analysis (1) Quantum circuits are typically specialized to one problem size, hence they are deeply and statically analyzable. Classical control resolution Static classical control resolution using LLVM passes May cause code explosion during code transformation of larger problems 9 9

  10. Resolving Classical Controls in the Code Classical control surrounding quantum code must be resolved to disambiguate for the hardware the qubits and the exact set of gates module Oracle_0(qbit a[1]) { Rz(a[0],-0.01); } #define s_ 3000 module Oracle(qbit a[1], int j) { double theta=(-1)*pow(2,j)/100; Rz(a[0],theta) } module main() { qbit a[1]; int i,j; for (i=0;i<=s_;i++) for (j=0;j<=3;j++) Oracle(a,j); } . . module Oracle_3(qbit a[1]) { Rz(a[0],-0.08); } 10 10

  11. Classical Control Resolution module EQxMark_0 (qbit b[n], qbit t[1]) { . . Z(x[n-2]); . . } module EQxMark (qbit b[n], qbit t[1], int tF) { . . if(tF==1) CNOT(t[0], x[n-2]); else Z(x[n-2]); . . } clone module EQxMark_1 (qbit b[n], qbit t[1]) { . . CNOT(t[0], x[n-2]); . . } inter-procedural constant propagation module main (qbit b[n], qbit t[1]) { . for (i=0; i<2; i++) EQxMark(b,t,i); . } module main (qbit b[n], qbit t[1]) { . EQxMark(b,t,0); EQxMark(b,t,1); . } unroll EQxMark(b,t,0); EQxMark_0(b,t); EQxMark(b,t,1); EQxMark_1(b,t); 11

  12. Pass-Driven Vs. Instrumentation-Driven Pass-Driven: Loop unrolling Procedure Cloning Inter-procedural Constant Propagation Instrumentation-Driven: Leveraging the dual nature of quantum programs Instrument code such that a fast classical processor executes through the classical portion, collecting information regarding the quantum portion Further speed-up by memoizing same module calls 12 12

  13. The Instrumentation-Driven Approach Scales Better 318 316 314 (Normalized per benchmark) 312 310 Compilation time (s) 308 306 304 Better 302 300 8 Pass-driven 7 6 Instrumentation-driven 5 4 3 2 1 0 M=20 M=30 M=40 n=5 p=6 p=8 n=100, s=1000 n=300, s=3000 n=500, s=5000 x=2, y=2 x=3, y=2 n=20 n=40 n=60 n=10 Grovers BWT GSE TFP BF CN 13 13

  14. Scalability in Compilation and Analysis (2) Traditional QASM: No loops or modules: only sequences of qubits and gates Used for small program representations Programs that we examined contained between 107 to 1012 gates We need a more scalable output format: QASM with Hierarchy (QASM-H) 200,000X smaller code QASM with Hierarchy and Loops (QASM-HL) 14 14

  15. Managing Scalability with QASM Format Scaffold QASM-H #define n 1000 module foo(qbit q[n]) { for(int i = 0; i < n; i++) H(q[i]); CNOT(q[n-1],q[0]); } module main() { qbit b[n]; foo(b); } module foo(qbit* q) { H(q[0]); H(q[1]); .. H(q[999]); CNOT(q[999],q[0]); } module main() { qbit b[1000]; foo(b); } QASM-HL Flat QASM module foo(qbit* q) { H(q[0:999]); CNOT(q[999],q[0]); } module main() { qbit b[1000]; foo(b); } qbit b[1000]; H(b[0]); H(b[1]); . . H(b[999]); CNOT(b[999],b[0]); 15 15

  16. Comparison of QASM-H and QASM-HL A large reduction is already obtained from QASM-H over flat QASM. 1 0.9 0.8 0.7 QASM-HL to QASM-H Code Size Ratio of 0.6 Better 0.5 0.4 0.3 0.2 0.1 0 x=2,y=2 x=3,y=2 n=20 n=30 n=40 M=20 M=30 M=40 n=10 n=5 p=6 p=8 n=100,s=1000 n=300,s=3000 n=500,s=5000 Grovers BWT GSE TFP BF CN 16 16

  17. Synthesizing Reversible Computation Classical-To-Quantum-Gate (CTQG): A ScaffCC feature for efficiently translating classical modules to quantum modules. Translation CTQG Classical Modules CTQG CTQG Compilation Generation Generation Classical Control Resolution Resolution Classical Control Clang Front- end end Clang Front- Scaffold Quantum Modules QASM QASM QASM Linker Scaffold Program Program Scaffold CTQG Separation QASM QASM LLVM-IR LLVM-IR 17 17

  18. CTQG: Classical-To-Quantum-Gate Facilitates the synthesis of quantum circuits from classical mathematical expressions: Basic integer arithmetic (a=a+b, a=a+bc, ...) Fixed-point arithmetic (1/x, sin x, ...) Bit-wise manipulations (shift operators, ...) State-of-the-art in reversible logic synthesis, minimizing the use of extra (ancilla) qubits Produces output gate-by-gate on the fly Not limited by memory 18 18

  19. Program Analysis Analysis passes: Program correctness checks Program estimates Translation CTQG Classical Modules CTQG CTQG Compilation Generation Classical Control Resolution Clang Front- end Scaffold Quantum Modules QASM QASM Linker Scaffold Program CTQG Separation QASM LLVM-IR Correctness Check Program Analysis Analysis Output Timing / Resource Estimates 19 19

  20. Program Analysis ScaffCC supports a range of code analysis techniques: Program correctness checks: No-cloning checks Entanglement and un-computation checks Program estimates: Resource estimation Timing analysis (Parallel scheduling) 20 20

  21. Program Correctness Checks No-Cloning: - Theorem: The state of one qubit cannot be copied into another (no fan-out) - Check that multi-qubit gates do not share qubits Entanglement: - The joint state of two qubits cannot be separated - Data-flow analyses to automate the tracking of entanglement and disentanglement 21 21

  22. Quantum Program Analysis: Resource Analysis Obtaining estimates for the size of the circuit: Qubits are expensive More gates require more overall error correction and hence more cost The same pass-driven and instrumentation-driven approaches apply Dynamic memoization table records number of resources 22 22

  23. Timing Estimate Estimates the critical path length of the program - Assuming unlimited hardware capability for parallelization Scheduling based on qubitdatadependencies between operations Hierarchical scheduling for tractability: Obtain module critical paths separately and then treat them as black boxes. 23 23

  24. Remodularization Analysis makes use of modularity Avoid repetitive analysis Reduce analysis time Results in loss of parallelism at module boundaries Decreased schedule optimality Idea: Inline small modules at call sites larger flattened modules Define threshold for small modules Results in better critical path estimates 24 24

  25. Hierarchical Approach Tradeoff Flattened Analysis Modular Analysis Module Toffoli(a,b,c) c a0 s1 s0 a b PrepZ(s0) PrepZ(s1) X(s1) Toffoli(a0,s1,s0) X(s1) . . . s1 s0 a0 Pz Pz 1 1 H P z P z 1 X H 2 C 2 3 T 2 X 3 C 4 4 C T 5 T Closeness to actual critical path is dependent on the level of modularity Flatter overall program means more opportunity for discovering parallelism 5 C C T 6 6 C 7 3-14 7 T T T T 8 8 C C T 9 9 C T C 10 H T 10 H T 11 C 11 C 12 12 S T 13 S T 14 X X 15 25 25

  26. Effect of Remodularization Based on resource analysis, flatten modules with size less than a threshold Tradeoff between speed of analysis and its accuracy 6.4E+08 Critical Path Length Estimate 6 6.2E+08 5 Analysis Time (s) 6.0E+08 4 5.8E+08 (# gates) 5.6E+08 3 5.4E+08 2 5.2E+08 1 5.0E+08 4.8E+08 0 5k 10k 50k 100k 150k 2M Flattening Threshold for Remodularization Binary Welded Tree n=300, s=1000 26 26

  27. Demo 27 27

  28. Conclusion Extended LLVM s classical framework for quantum compilation at the logical level Managed scalability through: Output format: 200,000X on average + up to 90% for some benchmarks Code generation approach: Up to %70 for large problems CTQG: Automatic generation of efficient quantum programs from classical descriptions Developed a scalable program analysis toolbox ScaffCC can be used as a future research tool 28 28

  29. Thank You 29

Related


More Related Content