compile_from_mlir

compile_from_mlir(ir, compiler=None, compile_options=None)[source]

Compile a Catalyst function to binary code from the provided MLIR.

Parameters
  • ir (str) – the MLIR to compile in string form

  • compile_options – options to use during compilation

Returns

A callable that manages the compiled shared library and its invocation.

Return type

CompiledFunction

Example

The main entry point of the program is required to start with catalyst.entry_point, and the program is required to contain setup and teardown functions.

ir = r"""
    module @workflow {
        func.func public @catalyst.entry_point(%arg0: tensor<f64>) -> tensor<f64> attributes {llvm.emit_c_interface} {
            return %arg0 : tensor<f64>
        }
        func.func @setup() {
            quantum.init
            return
        }
        func.func @teardown() {
            quantum.finalize
            return
        }
    }
"""

compiled_function = debug.compile_from_mlir(ir)
>>> compiled_function(0.1)
[0.1]