Create a pass which takes IR similar to this:
// NOTE: important is that this has the `entrypoint` attribute (name does not matter).
func.func public @main() -> ... attributes { qcc.entry_point } {
// ...
return %a, %b : i64, i1
}
And replaces it by something like this (details can be carved out in PR):
func.func public @main() -> void attributes { qcc.entry_point } {
// ...
aux.record_integer %a : i64 // this op needs to be added
aux.record_bool %b : i1 // this op already exists
return
}
This follows the recipe of QIR output recording.
Note that QIR enables one to assemble complex data structures to be recorded. For example to record something like (1, 2, [true, false]) (tuple of two ints and an array of bools). This would need "tuple record" and "array record" ops / QIR-funcs in case we want to support it.
Motivation (Qrisp)
Consider the following qrisp (python) example
from qrisp import *
from qrisp.jasp import make_jaspr
import jax.numpy as jnp
def example():
qv = QuantumVariable(2)
h(qv[0])
cx(qv[0], qv[1])
a = measure(qv) + 5 # becomes i64 (more precisely: tensor<i64>)
b = True # becomes i1 (more precisely: tensor<i1>)
# There are also things like this, but we leave them out in the first iteration as
# they get unpacked within the return statement (c, d, e become three times tensor<i64>
# (each) which is impossible to distinguish from three integer variables).
c = [1, 2, 3]
d = (1, 2, 3)
e = (1, [2, 3])
return a, b #, c, d, e
jaspr = make_jaspr(example)()
mlir_stablehlo = jaspr.to_mlir()
print(mlir_stablehlo)
This gets translated into this mlir:
builtin.module @jasp_module {
func.func public @main(%arg13: !jasp.QuantumState) -> (tensor<i64>, tensor<i1>, !jasp.QuantumState) {
// create %10 etc here ...
func.return %12, %13, %10 : tensor<i64>, tensor<i1>, !jasp.QuantumState
}
...
}
After some lowering this will likely look as above. Note that @main is by convention the name of the entrypoint of a qrisp program. There will be a pass which adds the corresponding attribute.
Create a pass which takes IR similar to this:
And replaces it by something like this (details can be carved out in PR):
This follows the recipe of QIR output recording.
Note that QIR enables one to assemble complex data structures to be recorded. For example to record something like
(1, 2, [true, false])(tuple of two ints and an array of bools). This would need "tuple record" and "array record" ops / QIR-funcs in case we want to support it.Motivation (Qrisp)
Consider the following qrisp (python) example
This gets translated into this mlir:
After some lowering this will likely look as above. Note that
@mainis by convention the name of the entrypoint of a qrisp program. There will be a pass which adds the corresponding attribute.