Commit b05493c1 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Merge branch 'master' into tnguyen/wip-ir-workshop-demo

parents 94a19598 891cb352
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
*.lo
*.o
*.obj

*.x
# Precompiled Headers
*.gch
*.pch
+34 −0
Original line number Diff line number Diff line
# MLIR+QIR as an IR for Quantum-Classical Computing
Here we demonstrate the utility of the QIR and MLIR for enabling the development of compilers for available quantum languages. 

Our motivation with this demonstration is to show how MLIR+QIR enable the main feature of a robust IR: mapping multiple languages or programming approaches to multiple backends.

Our examples will be simple GHZ and Bell circuits for NISQ and FTQC execution, respectively. 

## Goals

- Demonstrate the utility of the MLIR and QIR for creating compilers and executable code for available quantum languages.

- Demonstrate MLIR as language-level IR for quantum-classical computing (control flow from Standard/Affine, etc.).

- Demonstrate write-once, run-on-any available quantum backend and multiple languages to multiple backends.

- Demonstrate accessibility of MLIR and QIR for available Pythonic circuit construction frameworks. 

## Outline

1. Show the GHZ QASM3 code. Note control flow, variable declarations, gate modifiers, etc.
2. Compile it to `ghz.x`. 
3. Immediately run it on perfect backend simulator.
4. Note we could just as easily run on physical backends. Kick of runs on IBM, IonQ, and Rigetti, all in separate terminals (set name of vscode terminal with 3 split panes).
5. While these are running, run on a separate new simulator (pick `aer`). Then run on noisy backend from `aer`. 
6. Now show how all this worked: 
    - compile the code again with `-v`, show the command line steps. 
    - Show the progressive lowering. Emit the MLIR code, show it off, its quantum-classical
    - Show the LLVM/QIR code. 
7. Now switch to `bell.qasm` and show how using the same language and IR, we can also run in FTQC mode (multi-modal IR and execution model). 
8. Switch to the Python script to show the audience how all the MLIR/QIR infrastructure just shown can also be generated from Python. Moreover, that Qiskit and Pyquil can also generate MLIR/QIR. Note how `qjit` is the QCOR quantum just-in-time compiler, produces executable functions that enable `mlir()` and `llvm()` methods. 
9. At any point, go back and check on the physical backend executions. 

## Notes:
+8 −1
Original line number Diff line number Diff line
// qcor bell.qasm -o bell.x
// ./bell.x -qrt ftqc

OPENQASM 3;

qubit q[2];

const shots = 1024;
const shots = 100;
int count = 0;

for i in [0:shots] {
    
    // Create Bell state
    h q[0];
    ctrl @ x q[0], q[1];
    
    // Measure and assert both are equal
    bit c[2];
    c = measure q;
    if (c[0] == c[1]) {
+47 −0
Original line number Diff line number Diff line
// NISQ Mode Execution
//
// Compile and run with 
// qcor ghz.qasm -o ghz.x
// 
// Run on QPP (perfect simulator)
// ./ghz.x -qrt nisq -shots 1000
//
// Kick off Hardware Executions (will have to wait, kick off in parallel)
//
// Show on real hardware (IBM)
// ./ghz.x -qpu ibm:ibmq_sydney -qrt nisq -shots 1000
//
// Show on IonQ QPU
// ./ghz.x -qpu ionq:qpu -qrt nisq -shots 1000
//
// (In meantime, show of execution on simulators)
//
// Show on IonQ remote simulator
// ./ghz.x -qpu ionq -qrt nisq -shots 1000
//
// Show on IBM remote simulator
// ./ghz.x -qpu ibm -qrt nisq -shots 1000
// 
// Show on local aer with noisy backend
// ./ghz.x -qpu aer:ibmq_sydney -qrt nisq -shots 100
//
// (Now Show off how this works, MLIR + QIR)
//
// qcor -v ghz.qasm -o ghz.x
// qcor --emit-mlir ghz.qasm
// qcor --emit-llvm ghz.qasm


OPENQASM 3;

const n_qubits = 3;

qubit q[n_qubits];

h q[0];
for i in [0:n_qubits-1] {
    ctrl @ x q[i], q[i+1];
}

bit c[n_qubits];
c = measure q;
 No newline at end of file
Loading