Automatically Translating Quantum Programs from a Subset of
Automatically Translating Quantum Programs from a Subset of Common Gates to an Adiabatic Representation Malcolm Regan, Brody Eastwood, Mahita Nagabhiru, Frank Mueller http: //moss. csc. ncsu. edu/~mueller North Carolina State University 1
Quantum Computing Key concepts l N classical bits go in, N classical bits come out l Can operate on all 2 N possibilities in between l Requirement: Computation must be reversible OK… l Main challenge: You get only one measurement l l probability amplitudes set of possible results verify solution in classical space Gates (IBM Q): Not easy to program: gates universal — 220 states, superposition entaglement D-Wave Adiabatic (D-Wave): Easier not universal — 22000 states, uses quantum tunneling for annealing Both: superconducting circuit w/ Josephson junctions 2
Quantum Architectures 1. Quantum annealer (D-Wave) — Specialized: optimization problems find lowest energy level — Better than classical? maybe significant speedup? — Relation to universal gate model? unknown 2. Approximate quantum [gate] computer (IBM Q…): Noisy (NISQ) — More general: optimization, quantum chemistry, machine learning — Better than classical? likely, sign. Speedup: “advantage” — Fewer qubits than annealers can we transform gate programs into annealing programs? — Potential benefit: solve larger problems / better coherence? 3. Fault-tolerant quantum computer (sorry, not yet today…) — Algorithmic noise mitigation: crypto, search, any of apps above — Need 1000 physical qubits per virtual (“error-free”) qubit — Better than classical? proved theoretically: “supremacy” 3
Gate Paradigm (here: IBM Q) l l Qubit state: vector on Bloch sphere Reversible gates manipulate qubits, e. g. — Pauli: X (NOT), Y, Z — Controlled: CX, CY, CZ — Phase: Z( ), S( /2), T( /4), u 1/2/3, S†, T† — Hadamard: H, Swap, … — Toffoli: CCX, built from other gates on IBM Programming: Compose gates circuits Bit 0 Bit 1 Challenges — Problem transformation qubits, gates — Few qubits (max: 20) — Limited circuit depth (coherence time) — Noise interpret results in imperfect environment 4
Adiabatic Paradigm (here: D-Wave) l Adiabatic quantum optimization — Given 2 -degree (i. e. , 2 -dimensional) 2 -local Ising Hamiltonian find the iz ix {-1, +1} that minimize H — Universal equivalent gate model [Aharonov’ 04+07, Andriyah’ 16] l D-Wave: 1 degree (1 -dimensionsal) — Minimize H 0 only — Traverse controlled by D-Wave — Program Ji, j, hi — Can express subset of gates in this model not universal — Noise (again) 5
Challenge: Gate Adiabatic Translation l IBM Qiskit: Bell State from qiskit import Quantum. Register, Classical. Register, Quantum. Circuit q = Quantum. Register(2) c = Classical. Register(2) qc = Quantum. Circuit(q, c) qc. h(q[0]) # Hadamard on 1 st qubit qc. cx(q[0], q[1]) # CNOT to entangle l D-Wave Ocean — Logic NOT — Objective func: 2 xz-x-z from dimod import Exact. Solver sampler = Exact. Solver() sampler_embedded = Embedding. Composite(sampler) Q = {('x', 'x'): -1, ('y', 'y'): -1, ('x', 'y'): 2} response = sampler_embedded. sample_qubo(Q) for datum in response. data(['sample', 'energy’]): print(datum. sample, "Energy: ", datum. energy) # creates a Bell state qc. measure(q, c) 6
Subset of Gates l l Find subset to cover wide range of circuits — X(NOT) — CX (controlled-NOT) — Toffoli — Swap Notice: not universal, Hadamard is missing! 7
Automatic Translation l Given a circuits (in Qiskit format) 1. Construct equivalent QUBO (quadratic unconstrained binary opt. ) — Each gate QUBO — Compose QUBOs into single Hamiltonian 2. Find embedding in D-Wave’s topology — 16 x 16 bi-partite graphs (K 4, 4) sparsely connected as Chimera — Project per-gate QUBO bi-partite unit graph K 4, 4 — Connect constraints b/w QUBOs of units graphs “wires” 3. In Python: Transform IBM Qiskit program — Replace gates — Run, but instead of IBM Q exec. , make D-Wave Ocean API calls –or generate Ocean source program execute later 8
How to Derive a QUBO: “NOT” Function l l x z Obj ---- ---Consider ground states 0 0 ? penalize s. t. >T: -1 Find common equation (binary): z= x 0 1 True drive to ground -1 1 0 True -1 Find penalty function: 2 xz-x-z+1=0 1 1 ? penalize s. t. >T: xz — Reformat to ������ (�� : �� )= i�� �� + ij�� �� , �� ���� �� �� — Here: Obj(…)=a 1 q 1+a 2 q 2+b 12 q 1 q 2 — Our function is already minimized (o/w, square it now) Create truth table l Rewrite in QUBO format (add -1): 2 xz-x-z l Check if minimization is correct: q 1 q 2 Objective 0 0 1 1 0 1 0 -1 -1 0 a 1 a 2 b 12 -1 -1 2 9
Example: C-NOT Gate XOR Qubo l l l CNOT — same truth table as XOR — just copy in-x out-x — Reversible by applying outputs as new inputs — Need 2 qubits XOR as QUBO — In base iz {0, 1} — Need ancilla qubit a — Let z=x + y — Need 4 qubits — Minimize this: x+y+z+4 x+2 xy-2 xz-4 xa-2 yz-4 ya+4 za Not so fast, how did we get here? 10
Example: XOR Qubo l l XOR as QUBO — In base iz {0, 1} — G: ground state – G = 0 due to row 1 – 4 ground states — Others > G Problem: no solution! — Try for yourself — Need ancilla qubit a 11
Example: C-NOT Gate XOR Qubo l XOR as QUBO — ancilla qubit a, now have 4 qubits scarce resource — Let z=x + y — Minimize this, yields x+y+z+4 x+2 xy-2 xz-4 xa-2 yz-4 ya+4 za — — x=q 0 y=q 1 z=qa Obj=q 2 12
Subset of Gates l l l Find subset to cover wide range of circuits We now have — X(NOT) — CX (controlled-NOT) Repeat exercise for — Toffoli — Swap Combine gates to circuits — Compose into single qubo (Ising Hamiltonian) Map virtual qubits onto hardware qubits (D-Wave) 13
Bipartite Embedding l l We have XOR: x+y+z+4 x+2 xy-2 xz-4 xa-2 yz-4 ya+4 za — Need 4 qubits — Cannot map into K 4, 4 x Complete graph: K 4 transform into bipartite K 4, 4 x z y z a Use qubit chains for x and a x y a — Need 6 qubits –Split original qubit weight a –Connect with coupler –coupler strength high negative bias Planar embedding — Left: inputs — Right: outputs 14
Circuit Creation: Chimera Graph Wiring l From Gate-base Circuit… — Advance gate per “clock cycle “ to embedded Hamiltonian l l Planar embedding — Left: inputs — Right: outputs Connect prior gates chains b/w sub-Qubos (“wires”) 15
IBM Qiskit to D-Wave Ocean l l Idea: Direct translation of Qiskit objects Ocean objects — Instead of running on IBM Q, run on D-Wave 1. Hardware; 2. Simulator; or 3. Generate python Ocean source code for D-wave, run later Gates Qubos Circuits Chains/wires — Quantum circuit annealer graph (Python objects) — Algorithm for layout: planar embedding horizontally+vertically – Bias and strength selection – No layout optimizations yet (just proof-of-concept) Details in paper 16
Implementation l IBM Qiskit: adder from qiskit import Quantum. Register, Classical. Register, Quantum. Circuit q = Quantum. Register(3) c = Classical. Register(3) qc = Quantum. Circuit(q, c) for idx in range(3): circuit. ccx(qi[idx], qi[(idx+1)%3], qo[1]) for idx in range(3): circuit. cx(qi[idx], qo[0]) circuit. measure(qo, co) l D-Wave Ocean — Set initial qubit values 0 from dimod from dwave. system. samplers import DWave. Sampler qubit_biases = {397: 5, 393: 10, …} coupler_strengths = {(393, 397): -10, (394, 398): -10, …} inputs = [397, 398, 137] outputs = [173, 152] sampler = DWave. Sampler(endpoint='https: //cloud. dwavesys. com/sapi', token = token, solver = 'DW_2000 Q_2_1') bqm = dimod. Binary. Quadratic. Model(qubit_bia ses, coupler_strengths, 0, dimod. BINARY) … 17
Results: Full Adder l l l Adder circuit — 5 qubits — Toffoli: 16 gates, 13 deep — gates=3*16+3=51 — depth=3*13+3=42 Adder QUBO embedding — 5*6*8=240 qubits –many unused — Lots of wiring overhead future work Deterministic results low noise 18
More Results l l 4 -bit adder circuit — 10 qubits — Toffoli: 16 gates, 13 deep — gates=8*16+2=130 — depth=8*13+2=106 4 -adder QUBO embedding — 322 qubits, many unused — 430 couplers, 212 used — Routing around dead K 4, 4’s l l 2 -bit multiplier D-wave — 200 qubits — 262 couplers vs. 2 -bit multiply natively (DWave) — ~44 qubits — ~55 couplers l 6 times increase l Native specialization wins 19
Summary: Comparison & Potential l l Given n gates, q qubits (IBM) need ~ 23 n qubits (D-Wave) — Often just 5 -6 n due to complex (Toffoli) gates can improve! Cost/benefit today: 20 vs. 2000 qubits (IBM vs. D-Wave) — 100 X difference — Our translation is < 100 X but shifts dimension to gates! — Map subset of gate-based circuits to D-Wave –Equiv. to ~400 (avg) or ~87 gates (upper bound) –Potentially larger number of qubits Limitation: Hadamard, need different base? lost superposition Noise is tolerable — Easy to identify correct answers ground energy (adiabatic) – more difficult on gate hardware (IMHO) — Check classically (for any quantum paradigm) 20
Other Work at NCSU l NCSU is only academic IBM Q Hub in U. S. l Translating adiabatic gate (D-Wave IBM), in preparation l Algorithmic problem solving l Noise-aware problem solving l l l Application support: Chemistry, Physics, CS, … Program translation Optimization for NISQ: noisy intermediate-scale quantum 21
Acknowledgements l Seed funding by NCSU, support by NSF l Code at https: //github. ncsu. edu/mjregan 2/Gate_Circuit_to_Annealer_Embedding l l See http: //moss. csc. ncsu. edu/~mueller for this+other papers Malcolm Regan, Brody Eastwood, Mahita Nagabhiru and Frank Mueller. Automatically Translating Quantum Programs from a Subset of Common Gates to an Adiabatic Representation, Reversible Computing’ 19 N C U S 22
- Slides: 22