qrisp.jasp.Jaspr.to_qir#

Jaspr.to_qir() str[source]#

Compiles the Jaspr to QIR using the Catalyst framework.

Requires the Catalyst package to be installed (pip install qrisp[catalyst]).

Returns:
str

The QIR string.

Examples

We create a simple script and inspect the QIR string:

from qrisp import *
from qrisp.jasp import make_jaspr

def example_function(i):

    qv = QuantumFloat(i)
    cx(qv[0], qv[1])
    t(qv[1])
    meas_res = measure(qv)
    meas_res += 1
    return meas_res

jaspr = make_jaspr(example_function)(2)
print(jaspr.to_qir())

This yields:

; ModuleID = 'LLVMDialectModule'
source_filename = "LLVMDialectModule"

@... = internal constant [54 x i8] c"{'mcmc': False, 'num_burnin': 0, 'kernel_name': None}\00"
@LightningSimulator = internal constant [19 x i8] c"LightningSimulator\00"
@... = internal constant [...] c"...\00"
@__constant_30xi64 = private constant [30 x i64] [i64 30, i64 29, ..., i64 1], align 64
@__constant_xi64 = private constant i64 0, align 64

declare void @__catalyst__rt__finalize()

declare void @__catalyst__rt__initialize(ptr)

declare ptr @__catalyst__qis__Measure(ptr, i32)

declare void @__catalyst__qis__T(ptr, ptr)

declare void @__catalyst__qis__CNOT(ptr, ptr, ptr)

declare ptr @__catalyst__rt__array_get_element_ptr_1d(ptr, i64)

declare ptr @__catalyst__rt__qubit_allocate_array(i64)

declare void @__catalyst__rt__device_init(ptr, ptr, ptr, i64, i1)

declare void @_mlir_memref_to_llvm_free(ptr)

declare ptr @_mlir_memref_to_llvm_alloc(i64)

define { ptr, ptr, i64 } @jit_jaspr_function(ptr %0, ptr %1, i64 %2) {
  call void @__catalyst__rt__device_init(...)
  %4 = call ptr @__catalyst__rt__qubit_allocate_array(i64 20)
  ... (bookkeeping: allocates and threads a 1024-entry dynamic
       qubit-index stack through a couple of loops, using the
       @_append.detensorized / @_pop.detensorized /
       @make_tracer.detensorized helper functions defined further
       below, to resolve the array offsets %50 and %54 used by
       the gate calls right below) ...
  call void @__catalyst__qis__CNOT(ptr %50, ptr %54, ptr null)
  call void @__catalyst__qis__T(ptr %54, ptr null)
  ... (bookkeeping, resolving the offset for the qubit measured
       below) ...
  %73 = call ptr @__catalyst__qis__Measure(ptr %72, i32 -1)
  ... (post-processing the measurement result into the returned
       value) ...
  ret { ptr, ptr, i64 } %103
}

define void @_catalyst_pyface_jit_jaspr_function(ptr %0, ptr %1) {
  ...
}

define void @_catalyst_ciface_jit_jaspr_function(ptr %0, ptr %1) {
  ...
}

define void @setup() {
  call void @__catalyst__rt__initialize(ptr null)
  ret void
}

define void @teardown() {
  call void @__catalyst__rt__finalize()
  ret void
}

define internal { { ptr, ptr, i64, [1 x i64], [1 x i64] }, i64 } @_append.detensorized(...) {
  ...
}

define internal { i64, i64 } @_pop.detensorized(...) {
  ...
}

define internal i64 @make_tracer.detensorized(i64 %0) {
  ...
}

declare void @llvm.memcpy.p0.p0.i64(...) #0