qrisp.jasp.Jaspr.to_mlir#
- Jaspr.to_mlir()[source]#
Compiles the Jaspr to an xDSL module using the Jasp Dialect. Requires the xDSL package to be installed (
pip install xdsl).Note
An xDSL module can be visualized via:
print(xdsl_module)
and serialized to a string using:
from xdsl.printer import Printer Printer().print_op(xdsl_module)
- Returns:
- xdsl.dialects.builtin.ModuleOp
An xDSL module representing the quantum computation.
Examples
We create a simple script and inspect the MLIR string:
from qrisp import * from qrisp.jasp import make_jaspr def example_function(i): qv = QuantumVariable(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_mlir())
builtin.module @jasp_module { func.func public @main(%arg0 : tensor<i64>, %arg1 : !jasp.QuantumState) -> (tensor<i64>, !jasp.QuantumState) { %0, %1 = "jasp.create_qubits"(%arg0, %arg1) : (tensor<i64>, !jasp.QuantumState) -> (!jasp.QubitArray, !jasp.QuantumState) %2 = "stablehlo.constant"() <{value = dense<0> : tensor<i64>}> : () -> tensor<i64> %3 = "jasp.get_qubit"(%0, %2) : (!jasp.QubitArray, tensor<i64>) -> !jasp.Qubit %4 = "stablehlo.constant"() <{value = dense<1> : tensor<i64>}> : () -> tensor<i64> %5 = "jasp.get_qubit"(%0, %4) : (!jasp.QubitArray, tensor<i64>) -> !jasp.Qubit %6 = "jasp.quantum_gate"(%3, %5, %1) {gate_type = "cx"} : (!jasp.Qubit, !jasp.Qubit, !jasp.QuantumState) -> !jasp.QuantumState %7 = "jasp.quantum_gate"(%5, %6) {gate_type = "t"} : (!jasp.Qubit, !jasp.QuantumState) -> !jasp.QuantumState %8, %9 = "jasp.measure"(%0, %7) : (!jasp.QubitArray, !jasp.QuantumState) -> (tensor<i64>, !jasp.QuantumState) %10 = "stablehlo.add"(%8, %4) : (tensor<i64>, tensor<i64>) -> tensor<i64> %11 = "jasp.reset"(%0, %9) : (!jasp.QubitArray, !jasp.QuantumState) -> !jasp.QuantumState %12 = "jasp.delete_qubits"(%0, %11) : (!jasp.QubitArray, !jasp.QuantumState) -> !jasp.QuantumState func.return %10, %12 : tensor<i64>, !jasp.QuantumState } }