Exemplo n.º 1
0
    if parity01: 
        #Reset anc qubit
        X(q[ancIdx])
    
    CX(q[physicalIdx + 1], q[ancIdx])
    CX(q[physicalIdx + 2], q[ancIdx])
    parity12 = Measure(q[ancIdx])
    if parity12:
        #Reset anc qubit
        X(q[ancIdx])
    # Note: only in FTQC runtime that we can examine the measure results in realtime.
    print("Parity01 =", parity01, "Parity12 =", parity12)

@qjit
def testBitflipCode(q : qreg):
    H(q[0])
    encodeLogicalQubit(q)
    measureSyndrome(q, 0, 3)
    # Apply an X error
    for i in range(3):
        print("Apply X error @ ", i)
        X(q[i])
        measureSyndrome(q, 0, 3)
        # Cancel the error for the next test
        X(q[i])


# Allocate 4 qubits: 3 qubits + 1 ancilla
q = qalloc(4)

testBitflipCode(q)
Exemplo n.º 2
0
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, opt=3)
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)
Exemplo n.º 3
0
Arquivo: ghz.py Projeto: aide-qc/qcor
#   for i in range(q.size()):
#     Measure(q[i])

# # Allocate 3 qubits
# q = qalloc(3)

# # Run the bell experiment
# set_shots(1024)
# ghz(q)
# q.print()

# Or, import the IR from a Qiskit's QuantumCircuit
import qiskit

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

# Convert Qiskit circuit to QCOR IR
qcor_kernel = qjit(qiskit_circ)

# Allocate the qreg
q = qalloc(3)

# Examine the QCOR IR:
print('QCOR IR:')
qcor_kernel.print_kernel(q)
Exemplo n.º 4
0
# to indicate it is meant for QCOR just in time compilation

# NOTE Programmers must type annotate their function arguments


@qjit
def measure_all_qubits(q: qreg):
    for i in range(q.size()):
        Measure(q[i])


# Define a Bell kernel
@qjit
def bell_test(q: qreg):
    H(q[0])
    CX(q[0], q[1])
    # Call other kernels
    measure_all_qubits(q)


# Allocate 2 qubits
q = qalloc(2)

# Inspect the IR
comp = bell_test.extract_composite(q)
print(comp)

# Run the bell experiment
bell_test(q)
# Print the results
q.print()
Exemplo n.º 5
0
from qcor import qjit, qalloc
from qiskit.circuit.library import QFT
n_qubits = 3

# Create the IQFT, reverse bits for qcor
iqft = QFT(n_qubits, inverse=True).reverse_bits()

# ---- Use the following qcor boilerplate to generate QIR ----#
# Creates a kernel parameterized on a qreg
qcor_kernel = qjit(iqft)

# Allocate the qreg
q = qalloc(n_qubits)

# Convert to QIR and write to file
qir = qcor_kernel.qir(q,
                      add_entry_point=False,
                      qiskit_compat=True,
                      kernel_name='py_qiskit_iqft')
with open('iqft.ll', 'w') as f:
    f.write(qir)