Commit e860bb78 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

fix a few mlir qasm3 bugs, attempt to fix apt-get install bug where pch needs to be regenerated

parent 536c58cc
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ add_subdirectory(handlers)
add_subdirectory(runtime)
add_subdirectory(tools)
add_subdirectory(lib)
add_subdirectory(scripts/debian)

if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  if (NOT MLIR_DIR) 
@@ -105,7 +106,7 @@ set(CPACK_PACKAGE_VERSION_MINOR "${MINOR_VERSION}")
set(CPACK_PACKAGE_VERSION_PATCH "${PATCH_VERSION}")
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}")
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/scripts/debian/postinst")
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/scripts/debian/postinst")

#dependencies for this service menu
if (${QCOR_CPACK_DEB_PLATFORM} STREQUAL "bionic")
+29 −0
Original line number Diff line number Diff line
# QASM3 MLIR and QIR Simple
Here we demonstrate the utility of the QIR and MLIR for enabling the development of compilers for available quantum languages. 
We show 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 write-once, run-on-any available quantum backend. 

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

## Outline

GHZ (nisq) and Bell (ftqc) QASM3 codes, compile and run on simulator, IBM, Rigetti (in JupyterLab), IonQ. Walk through generated MLIR and QIR.

- Show pre-written GHZ and Bell QASM3 codes, note how GHZ is written for NISQ execution, while Bell is written for FTQC. 

- Lower GHZ to MLIR, show off the result. Lower GHZ to QIR, show off the result. 

- Lower Bell to MLIR, show off the result. Lower Bell to QIR, show off the result. 

- Compile and run the Bell code on QPP, note qcor -verbose and show the commands being run

- Compile the GHZ code for the IBM backend and execute. Note automated placement. 



## Notes:
 No newline at end of file
+21 −0
Original line number Diff line number Diff line
OPENQASM 3;

qubit q[2];

const shots = 1024;
int count = 0;

for i in [0:shots] {
    h q[0];
    ctrl @ x q[0], q[1];
    bit c[2];
    c = measure q;
    if (c[0] == c[1]) {
        count += 1;
    }

    reset q;
}

print("count is ", count);
+17 −0
Original line number Diff line number Diff line
// Compile and run with 
// qcor ghz.qasm -o ghz.x
// ./ghz.x -qrt nisq -shots 1000

OPENQASM 3;

const n_qubits = 8;

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
+45 −0
Original line number Diff line number Diff line
from qcor import qjit, qalloc
import qiskit

# Generate 3-qubit GHZ state with Qiskit
circ = qiskit.QuantumCircuit(3)
circ.h(0)
circ.cx(0, 1)
circ.cx(1, 2)
circ.measure_all()

# Creates a kernel parameterized on a qreg
qcor_kernel = qjit(circ)

# Allocate the qreg
q = qalloc(3)

# Convert to MLIR and print
mlir = qcor_kernel.mlir(q)
print(mlir)

# Convert to QIR and print
qir = qcor_kernel.qir(q)
print(qir)

from pyquil import Program
from pyquil.gates import CNOT, H, MEASURE
  
p = Program()
p += H(0)
p += CNOT(0, 1)
ro = p.declare('ro', 'BIT', 2)
p += MEASURE(0, ro[0])
p += MEASURE(1, ro[1])

# This requires rigetti/quilc docker image
qcor_kernel_pyquil = qjit(p)
r = qalloc(2)

# Convert to MLIR and print
mlir = qcor_kernel_pyquil.mlir(r)
print(mlir)

# Convert to QIR and print
qir = qcor_kernel_pyquil.qir(r)
print(qir)
 No newline at end of file
Loading