Complete LIFT Framework Guide — All Features
LIFT — Language for Intelligent Frameworks and Technologies Unified intermediate representation for AI and quantum computing.
This document describes every feature of the LIFT framework, numbered and organised by crate. For each feature: what it does, how to use it, and which other features to combine it with.
Table of Contents
- General Architecture
- lift-core — IR Core
- lift-ast — Parsing the .lif Language
- lift-tensor — Tensor Operations (90+ ops)
- lift-quantum — Quantum Gates and Noise (50+ gates)
- lift-hybrid — Classical-Quantum Hybrid Computation
- lift-opt — Optimisation Passes (11 passes)
- lift-sim — Simulation and Cost Analysis
- lift-predict — Performance Prediction
- lift-import — Model Import
- lift-export — Backend Export
- lift-config — Configuration (.lith)
- lift-cli — Command-Line Interface
- Combinations and Complete Pipelines
- Concrete Examples
1. General Architecture
LIFT is a modular compiler composed of 13 crates organised in layers:
┌──────────┐
│ lift-cli │ ← User interface
└────┬─────┘
┌─────────────┼─────────────┐
│ │ │
┌──────┴──────┐ ┌────┴────┐ ┌──────┴──────┐
│ lift-import │ │lift-opt │ │ lift-export │
└──────┬──────┘ └────┬────┘ └──────┬──────┘
│ │ │
┌──────┴──────┐ ┌────┴────┐ ┌──────┴──────┐
│ lift-ast │ │lift-sim │ │lift-predict │
└──────┬──────┘ └────┬────┘ └──────┬──────┘
│ │ │
┌──────┴─────────────┴─────────────┴──────┐
│ lift-core │
├──────────┬──────────┬───────────────────┤
│lift-tensor│lift-quantum│ lift-hybrid │
└──────────┴──────────┴───────────────────┘
1.1 Compilation Pipeline
The standard workflow is:
Source (.lif) → Lexer → Parser → IR (SSA) → Verification → Optimisation → Simulation → Export
1.2 File Formats
| Extension | Description |
|---|---|
.lif |
LIFT IR source code |
.lith |
Compilation configuration |
1.3 Adding LIFT as a Dependency
[]
= "0.2.0"
= "0.2.0"
= "0.2.0"
= "0.2.0"
= "0.2.0"
= "0.2.0"
= "0.2.0"
= "0.2.0"
= "0.2.0"
= "0.2.0"
2. lift-core — IR Core
The heart of the framework. Provides the SSA (Static Single Assignment) intermediate representation.
2.1 Context — The Central Container
use Context;
let mut ctx = new;
The Context stores all IR data: values, operations, blocks, regions, functions, modules, interned strings, and types.
| Field | Description | Usage |
|---|---|---|
ctx.values |
All SSA values | Each operation result is a unique value |
ctx.ops |
All operations | Program instructions |
ctx.blocks |
Basic blocks | Contain sequences of operations |
ctx.regions |
Regions | Contain blocks (function bodies) |
ctx.modules |
Modules | Compilation units |
ctx.strings |
String interning | ctx.strings.intern("name") |
ctx.type_interner |
Type interning | Type deduplication |
Combine with: All other crates. The Context is the entry point for every pipeline.
2.2 Types — Type System
use *;
// Data types
let fp32 = FP32;
let fp16 = FP16;
let bf16 = BF16;
let int8 = INT8;
let fp64 = FP64;
// Dimensions (static or symbolic)
let batch = Constant;
let seq = Symbolic;
// Tensor type info
let tensor_info = TensorTypeInfo ;
// Size in bytes
let bytes = tensor_info.size_bytes; // Some(3136) = 1*784*4
Available data types:
| Type | Size | Usage |
|---|---|---|
FP64 |
8 bytes | High-precision scientific computing |
FP32 |
4 bytes | Standard training |
FP16 |
2 bytes | Fast inference |
BF16 |
2 bytes | Mixed-precision training (Google Brain) |
INT8 |
1 byte | Post-training quantisation |
INT32 |
4 bytes | Indices, counters |
BOOL |
1 byte | Masks |
Memory layouts: Contiguous, Strided.
2.3 Attributes — Operation Metadata
use ;
let mut attrs = new;
// Different attribute types
attrs.set;
attrs.set;
attrs.set;
// Reading
let heads = attrs.get_integer; // Some(8)
let drop = attrs.get_float; // Some(0.1)
let causal = attrs.get_bool; // Some(true)
// Checking
assert!;
assert_eq!;
// Iteration
for in attrs.iter
Combine with: lift-opt (passes read/write attributes), lift-export (exporters read attributes).
2.4 Verifier — Invariant Checking
use verifier;
let ctx = new;
match verify
Checks:
- SSA: every value is defined exactly once
- Qubit linearity: every qubit is used exactly once
- Typing: type consistency between operations
- Structure: blocks, regions, terminators are correct
Combine with: Always use after import and after each optimisation pass.
2.5 Printer — IR Display
use print_ir;
let ctx = new;
let output = print_ir;
println!;
Produces a human-readable textual representation of the IR, useful for debugging.
2.6 Pass Manager
use ;
let mut pm = new;
pm.add_pass;
pm.add_pass;
pm.add_pass;
let results = pm.run_all;
for in &results
Combine with: lift-opt (all 11 passes), lift-config (pass selection via configuration).
2.7 Dialect — Dialect System
use ;
let registry = new;
// The tensor, quantum, hybrid dialects are registered automatically
The three LIFT dialects:
- tensor: tensor operations (
tensor.matmul,tensor.relu, etc.) - quantum: quantum gates (
quantum.h,quantum.cx, etc.) - hybrid: hybrid operations (
hybrid.encode,hybrid.vqc_layer, etc.)
3. lift-ast — Parsing the .lif Language
3.1 Lexer — Tokenisation
use Lexer;
let source = r#"
#dialect tensor
module @mlp {
func @forward(%x: tensor<1x784xf32>) -> tensor<1x10xf32> {
%out = "tensor.relu"(%x) : (tensor<1x784xf32>) -> tensor<1x784xf32>
return %out
}
}
"#;
let mut lexer = new;
let tokens = lexer.tokenize.to_vec;
assert!;
3.2 Parser — Syntactic Analysis
use Parser;
let mut parser = new;
let program = parser.parse.expect;
3.3 IrBuilder — IR Construction
use IrBuilder;
use Context;
let mut ctx = new;
let mut builder = new;
builder.build_program.expect;
3.4 Complete Parsing Pipeline
Combine with: lift-core (Context), then lift-opt (optimisation), lift-sim (analysis), lift-export (compilation).
4. lift-tensor — Tensor Operations (90+ ops)
4.1 Complete Operation List by Category
4.1.1 Basic Arithmetic (5 ops)
| # | Op | IR Name | Inputs | Description |
|---|---|---|---|---|
| 1 | Add |
tensor.add |
2 | Element-wise addition |
| 2 | Sub |
tensor.sub |
2 | Subtraction |
| 3 | Mul |
tensor.mul |
2 | Element-wise multiplication |
| 4 | Div |
tensor.div |
2 | Division |
| 5 | Neg |
tensor.neg |
1 | Negation |
use TensorOp;
let op = MatMul;
println!; // "tensor.matmul"
println!; // (2, 2)
println!; // "2*M*N*K"
4.1.2 Linear Algebra (4 ops)
| # | Op | Inputs | Description |
|---|---|---|---|
| 6 | MatMul |
2 | Matrix multiplication |
| 7 | Linear |
3 | Linear layer (matmul + bias) |
| 8 | Embedding |
2 | Embedding lookup table |
| 9 | SparseMatMul |
2 | Sparse MatMul |
4.1.3 Activations (11 ops)
| # | Op | Description | FLOPs Formula |
|---|---|---|---|
| 10 | ReLU |
max(0, x) | N |
| 11 | GeLU |
Gaussian Error Linear Unit | ~8N |
| 12 | SiLU |
x * sigmoid(x) (Swish) | ~8N |
| 13 | Sigmoid |
1/(1+exp(-x)) | N |
| 14 | Tanh |
Hyperbolic tangent | N |
| 15 | Softmax |
exp(x)/sum(exp(x)) | 5N |
| 16 | LeakyReLU |
max(αx, x) | N |
| 17 | ELU |
Exponential Linear Unit | N |
| 18 | Mish |
x * tanh(softplus(x)) | ~8N |
| 19 | HardSwish |
Swish approximation | ~8N |
| 20 | HardSigmoid |
Sigmoid approximation | N |
assert!;
assert!;
4.1.4 Normalisation (5 ops)
| # | Op | Inputs | Description |
|---|---|---|---|
| 21 | LayerNorm |
2-3 | Layer normalisation |
| 22 | RMSNorm |
2-3 | Root Mean Square Norm (LLaMA) |
| 23 | BatchNorm |
3-5 | Batch normalisation |
| 24 | GroupNorm |
2-3 | Group normalisation |
| 25 | InstanceNorm |
2-3 | Instance normalisation |
assert!;
4.1.5 Attention (8 ops)
| # | Op | Inputs | Description |
|---|---|---|---|
| 26 | Attention |
3-4 | Standard attention (Q, K, V, [mask]) |
| 27 | MultiHeadAttention |
3-4 | Multi-head |
| 28 | MultiQueryAttention |
3-4 | Multi-query (Llama) |
| 29 | GroupedQueryAttention |
3-4 | Grouped query (GQA) |
| 30 | FlashAttention |
3-4 | FlashAttention V2 (O(N) memory) |
| 31 | SlidingWindowAttention |
3-4 | Sliding window (Mistral) |
| 32 | CrossAttention |
3-4 | Cross-attention (encoder-decoder) |
| 33 | PagedAttention |
3-5 | Paged attention (vLLM) |
assert!;
4.1.6 Convolutions (6 ops)
| # | Op | Description |
|---|---|---|
| 34 | Conv2D |
Convolution 2D standard |
| 35 | Conv1D |
1D convolution (audio, sequences) |
| 36 | Conv3D |
3D convolution (video, volumetric) |
| 37 | ConvTranspose2D |
Transposed convolution (upsampling) |
| 38 | DepthwiseConv2D |
Depthwise convolution (MobileNet) |
| 39 | DilatedConv2D |
Dilated convolution (large receptive field) |
4.1.7 Pooling (4 ops)
| # | Op | Description |
|---|---|---|
| 40 | MaxPool2D |
Max pooling 2D |
| 41 | AvgPool2D |
Average pooling 2D |
| 42 | AdaptiveAvgPool2D |
Adaptive average pooling |
| 43 | GlobalAvgPool |
Global average pooling |
4.1.8 Shape Operations (13 ops)
| # | Op | Description | FLOPs |
|---|---|---|---|
| 44 | Reshape |
Change shape | 0 |
| 45 | Transpose |
Transpose | 0 |
| 46 | Concat |
Concatenate | 0 |
| 47 | Split |
Split | 0 |
| 48 | Gather |
Advanced indexing | 0 |
| 49 | Scatter |
Indexed write | 0 |
| 50 | Squeeze |
Remove dim=1 | 0 |
| 51 | Unsqueeze |
Add dim=1 | 0 |
| 52 | Permute |
Permute dimensions | 0 |
| 53 | Expand |
Broadcast expansion | 0 |
| 54 | Slice |
Slice | 0 |
| 55 | Pad |
Padding | 0 |
| 56 | Tile |
Repeat | 0 |
assert!;
4.1.9 Constants (5 ops)
| # | Op | Description |
|---|---|---|
| 57 | Constant |
Constant tensor |
| 58 | Zeros |
Zero tensor |
| 59 | Ones |
Ones tensor |
| 60 | Arange |
Sequence [0, 1, ..., n-1] |
| 61 | Full |
Tensor filled with a value |
4.1.10 Recurrent (3 ops)
| # | Op | Description |
|---|---|---|
| 62 | LSTMCell |
LSTM cell |
| 63 | GRUCell |
GRU cell |
| 64 | RNNCell |
Simple RNN cell |
4.1.11 Advanced Mathematics (9 ops)
| # | Op | Description |
|---|---|---|
| 65 | Einsum |
Einstein notation |
| 66 | FFT |
Fast Fourier Transform |
| 67 | IFFT |
Inverse FFT |
| 68 | SVD |
Singular Value Decomposition |
| 69 | Eig |
Eigendecomposition |
| 70 | Solve |
Linear system solver |
| 71 | TopK |
Top-K values |
| 72 | Sort |
Sort |
| 73 | Cumsum |
Cumulative sum |
4.1.12 Quantisation (6 ops)
| # | Op | Description |
|---|---|---|
| 74 | Quantize |
FP → INT8 |
| 75 | Dequantize |
INT8 → FP |
| 76 | QuantizeInt4 |
FP → INT4 |
| 77 | DequantizeInt4 |
INT4 → FP |
| 78 | QuantizeFp8 |
FP → FP8 |
| 79 | DequantizeFp8 |
FP8 → FP |
4.1.13 Diffusion / Generative (3 ops)
| # | Op | Description |
|---|---|---|
| 80 | UNetDownBlock |
U-Net down block |
| 81 | UNetUpBlock |
U-Net up block |
| 82 | TimestepEmbedding |
Timestep embedding (Stable Diffusion) |
4.1.14 GNN — Graph Neural Networks (2 ops)
| # | Op | Description |
|---|---|---|
| 83 | GNNMessagePassing |
GNN message passing |
| 84 | GNNGlobalPooling |
GNN global pooling |
4.1.15 MoE — Mixture of Experts (2 ops)
| # | Op | Description |
|---|---|---|
| 85 | MoEDispatch |
Route to experts |
| 86 | MoECombine |
Combine expert outputs |
4.1.16 Memory and Gradient (11 ops)
| # | Op | Description |
|---|---|---|
| 87 | Checkpoint |
Gradient checkpointing (memory saving) |
| 88 | Offload |
CPU offload (for large models) |
| 89 | GradAccumulate |
Gradient accumulation |
| 90 | GradMatMul |
MatMul gradient |
| 91 | GradReLU |
ReLU gradient |
| 92 | GradSoftmax |
Softmax gradient |
| 93 | GradLayerNorm |
LayerNorm gradient |
| 94 | GradAttention |
Attention gradient |
| 95 | GradConv2D |
Conv2D gradient |
| 96 | GradLinear |
Linear gradient |
| 97 | GradGeLU |
GeLU gradient |
4.1.17 Parallelism (4 ops)
| # | Op | Description |
|---|---|---|
| 98 | ParallelSplit |
Data parallel split |
| 99 | ParallelAllReduce |
All-reduce across GPUs |
| 100 | PipelineSend |
Pipeline parallel send |
| 101 | PipelineReceive |
Pipeline parallel receive |
4.1.18 Fused Operations (6 ops)
| # | Op | Description | Gain |
|---|---|---|---|
| 102 | FusedMatMulBiasReLU |
MatMul + Bias + ReLU | 1 kernel instead of 3 |
| 103 | FusedMatMulBias |
MatMul + Bias | 1 kernel instead of 2 |
| 104 | FusedLinearGeLU |
Linear + GeLU | Bandwidth gain |
| 105 | FusedAttentionLayerNorm |
Attention + LayerNorm | Memory reduction |
| 106 | FusedLinearSiLU |
Linear + SiLU | Bandwidth gain |
| 107 | FusedConvBatchNormReLU |
Conv + BN + ReLU | Fast inference |
4.2 Shape Inference
use *;
use TensorOp;
use ShapeInference;
// Shape inference
let a = mk;
let b = mk;
let result = infer_output_shape.unwrap;
// result[0].shape = [2, 3, 128]
// FLOP computation
let flops = compute_flops;
println!; // Some(49152)
// Memory computation
let mem = compute_memory_bytes;
println!;
Combine with: lift-sim (cost model uses FLOPs), lift-predict (roofline prediction).
4.3 Useful Predicates
let op = FlashAttention;
op.is_attention; // true — attention variant?
op.is_convolution; // false — convolution?
op.is_normalisation; // false — normalisation?
op.is_activation; // false — activation?
op.is_fused; // false — fused operation?
op.is_gradient; // false — gradient operation?
op.is_zero_flop; // false — zero FLOPs (reshape, etc.)?
op.num_inputs; // (3, 4) — min/max number of inputs
op.flops_formula; // "2*B*H*(S^2*D + S*D^2)"
5. lift-quantum — Quantum Gates and Noise (50+ gates)
5.1 Quantum Gates
5.1.1 Standard 1-Qubit Gates (9 gates)
| # | Gate | IR Name | Type | Description |
|---|---|---|---|---|
| 1 | H |
quantum.h |
Clifford | Hadamard |
| 2 | X |
quantum.x |
Pauli | Quantum NOT (bit-flip) |
| 3 | Y |
quantum.y |
Pauli | Y rotation by π |
| 4 | Z |
quantum.z |
Pauli | Phase-flip |
| 5 | S |
quantum.s |
Clifford | Phase π/2 |
| 6 | Sdg |
quantum.sdg |
Clifford | S inverse |
| 7 | T |
quantum.t |
Non-Clifford | Phase π/4 (expensive for QEC) |
| 8 | Tdg |
quantum.tdg |
Non-Clifford | T inverse |
| 9 | SX |
quantum.sx |
Clifford | Square root of X |
5.1.2 Parametric 1-Qubit Gates (9 gates)
| # | Gate | Parameters | Description |
|---|---|---|---|
| 10 | RX |
θ | Rotation around X |
| 11 | RY |
θ | Rotation around Y |
| 12 | RZ |
θ | Rotation around Z |
| 13 | P |
φ | Phase gate |
| 14 | U1 |
λ | U1 unitary gate |
| 15 | U2 |
φ, λ | U2 unitary gate |
| 16 | U3 |
θ, φ, λ | General unitary gate |
| 17 | Rx90 |
— | Fixed RX(π/2) |
| 18 | Rx180 |
— | Fixed RX(π) |
5.1.3 Portes 2-qubits (14 portes)
| # | Porte | Description | Natif pour |
|---|---|---|---|
| 19 | CX |
CNOT | IBM |
| 20 | CZ |
Controlled-Z | IBM, Rigetti |
| 21 | CY |
Controlled-Y | — |
| 22 | SWAP |
Échange de qubits | — |
| 23 | ISWAP |
iSWAP | Rigetti |
| 24 | ECR |
Echoed Cross-Resonance | IBM Eagle |
| 25 | RZX |
ZX rotation | IBM |
| 26 | XX |
Ising XX | IonQ |
| 27 | YY |
Ising YY | IonQ |
| 28 | ZZ |
Ising ZZ | IonQ |
| 29 | CPhase |
Controlled Phase | Rigetti |
| 30 | XY |
XY interaction | Rigetti |
| 31 | CP |
Controlled Phase | — |
| 32 | MS |
Mølmer–Sørensen | IonQ |
5.1.4 3-Qubit and Multi-Control Gates (4 gates)
| # | Gate | Description |
|---|---|---|
| 33 | CCX |
Toffoli (CCNOT) |
| 34 | CSWAP |
Fredkin |
| 35 | MCX |
Multi-controlled X |
| 36 | MCZ |
Multi-controlled Z |
5.1.5 Special and Control Gates (10 gates)
| # | Gate | Description |
|---|---|---|
| 37 | GlobalPhase |
Global phase |
| 38 | Delay |
Delay (decoherence) |
| 39 | VirtualRZ |
Virtual RZ (no physical cost) |
| 40 | IfElse |
Classical conditional control |
| 41 | Measure |
Measure 1 qubit |
| 42 | MeasureAll |
Measure all qubits |
| 43 | Reset |
Reset |
| 44 | Barrier |
Barrier (prevents optimisation) |
| 45 | Init |
Initialisation |
| 46 | ParamGate |
Generic parametric gate |
use QuantumGate;
let gate = H;
println!; // "quantum.h"
println!; // 1
println!; // true
println!; // false
println!; // true
// Look up a gate by its IR name
let gate = from_name; // Some(CX)
5.2 Hardware Providers — Native Gate Sets
use ;
// Native gates per provider
let ibm_basis = native_basis;
let rigetti_basis = native_basis;
let ionq_basis = native_basis;
let quant_basis = native_basis;
| Provider | Native Gates |
|---|---|
IbmEagle |
CX, RZ, SX, X |
IbmKyoto |
ECR, RZ, SX, X |
Rigetti |
CZ, RX, RZ |
IonQ |
GPI, GPI2, MS |
Quantinuum |
RZ, RX, ZZ |
Simulator |
All gates |
Combine with: lift-opt::LayoutMapping (transpilation to target hardware).
5.3 Device Topology — Hardware Topology
use DeviceTopology;
// Predefined topologies
let linear = linear; // Linear chain
let grid = grid; // 3x3 grid
let hex = heavy_hex; // Heavy-hex IBM
let ion = all_to_all; // All-to-all (trapped ions)
let tree = tree; // Binary tree
// Custom topology
let custom = custom;
// Querying
linear.are_connected; // true
linear.shortest_path; // Some([0, 1, 2, 3, 4])
linear.swap_distance; // Some(3)
linear.avg_connectivity; // average connectivity
linear.diameter; // graph diameter
grid.neighbors; // neighbours of qubit 4
Combine with: lift-opt::LayoutMapping, lift-opt::NoiseAwareSchedule.
5.4 Noise Models
use ;
// Noise models
let ideal = Ideal;
let depol = Depolarizing ;
let bitflip = BitFlip ;
let phaseflip = PhaseFlip ;
// Model fidelity
let fidelity = depol.fidelity; // 0.99
// Per-gate noise
let gate_noise = with_depolarizing;
// Full circuit analysis
let mut cn = new;
// ... noise accumulation
println!;
println!;
5.5 Kraus Channels — Quantum Noise Channels
use ;
// Predefined noise channels
let depol = depolarizing; // 1-qubit depolarising
let amp = amplitude_damping; // Amplitude damping
let phase = phase_damping; // Phase damping
// Channel fidelity
let fidelity = depol.average_gate_fidelity;
println!;
// Complex matrices
let mut m = identity;
let dagger = m.dagger; // Conjugate transpose
let product = m.mul.unwrap;
let trace = m.trace.unwrap;
Combine with: lift-sim::QuantumCostModel (circuit fidelity estimation), lift-opt::NoiseAwareSchedule.
5.6 QEC — Quantum Error Correction
use ;
// Available QEC codes
let surface = SurfaceCode ; // 25 physical qubits/logical
let steane = SteaneCode; // 7 physical qubits/logical
let shor = ShorCode; // 9 physical qubits/logical
let rep = RepetitionCode ; // 7 physical qubits
let ldpc = LdpcCode ; // LDPC code
// Code properties
println!; // 25
println!; // 5
println!; // 5
// Full QEC analysis
let analysis = analyse;
println!;
println!;
println!;
Combine with: lift-sim::QuantumCostModel, lift-predict (fidelity budget).
6. lift-hybrid — Classical-Quantum Hybrid Computation
6.1 Hybrid Operations (21 ops)
6.1.1 Encoding/Decoding (2 ops)
| # | Op | IR Name | Description |
|---|---|---|---|
| 1 | Encode |
hybrid.encode |
Encode classical data → qubits |
| 2 | Decode |
hybrid.decode |
Decode quantum measurements → classical |
6.1.2 Gradient Methods (6 ops)
| # | Op | IR Name | Evaluations | Exact? |
|---|---|---|---|---|
| 3 | ParameterShift |
hybrid.parameter_shift |
2N | Yes |
| 4 | FiniteDifference |
hybrid.finite_difference |
N+1 | No |
| 5 | SPSA |
hybrid.spsa |
2 | No |
| 6 | AdjointDifferentiation |
hybrid.adjoint_diff |
1 | Yes |
| 7 | StochasticParameterShift |
hybrid.stochastic_param_shift |
2 | No |
| 8 | JointGradient |
hybrid.joint_gradient |
Combined | — |
use GradientMethod;
let method = ParameterShift;
let evals = method.circuit_evaluations; // 200 evaluations for 100 params
assert!; // true
6.1.3 Processing (4 ops)
| # | Op | Description |
|---|---|---|
| 9 | ClassicalPreprocess |
Classical preprocessing |
| 10 | QuantumPostprocess |
Quantum postprocessing |
| 11 | HybridForward |
Hybrid forward pass |
| 12 | HybridBackward |
Hybrid backward pass |
6.1.4 Variational Algorithms (4 ops)
| # | Op | Description | Usage |
|---|---|---|---|
| 13 | VqcLayer |
Variational circuit layer | Quantum classification |
| 14 | VqeAnsatz |
VQE ansatz | Quantum chemistry |
| 15 | QaoaLayer |
QAOA layer | Combinatorial optimisation |
| 16 | QuantumKernel |
Quantum kernel | Quantum machine learning |
6.1.5 Data Transfer (2 ops)
| # | Op | Description |
|---|---|---|
| 17 | GpuToQpu |
GPU → QPU transfer |
| 18 | QpuToGpu |
QPU → GPU transfer |
6.1.6 Co-Execution and Measurement (3 ops)
| # | Op | Description |
|---|---|---|
| 19 | CoExecute |
Simultaneous classical+quantum execution |
| 20 | MeasureExpectation |
Observable expectation value |
| 21 | MeasureSamples |
Measurement sampling |
use HybridOp;
let op = VqcLayer;
assert!;
assert!;
6.2 Encoding Strategies
use ;
let strategies = ;
// Encoding configuration
let config = new;
println!; // 8 = log2(256)
println!; // 256
| Strategy | Qubits | Depth | Best for |
|---|---|---|---|
| Angle | n | 1 | Few features |
| Amplitude | log₂(n) | n | Many features |
| Basis | n | 1 | Binary data |
| IQP | n | 2n | Quantum advantage |
| Hamiltonian | n | n | Physical simulation |
| Kernel | n | 3n | Quantum ML |
6.3 Gradient Configuration — Joint Gradient Setup
use ;
let config = JointGradientConfig ;
println!;
// 1 (backprop) + 100 (2*50 parameter shift) = 101
6.4 Auxiliary Types
use ;
// Ansatz types for VQC
let ansatz = HardwareEfficient; // HardwareEfficient, StronglyEntangling, TwoLocal, UCCSD, Custom
// Synchronisation policy
let sync = Blocking; // Blocking, Asynchronous, Pipeline
// Feature maps for quantum kernels
let fm = ZZFeatureMap; // ZZFeatureMap, PauliFeatureMap, AngleEncoding, AmplitudeEncoding
7. lift-opt — Optimisation Passes (11 passes)
7.1 Classical Passes (5 passes)
7.1.1 Canonicalize — Canonical Form
use Canonicalize;
use Pass;
let pass = Canonicalize;
// Reorders operations into canonical form
// Normalises IR patterns to facilitate subsequent optimisations
Usage: Always run first in the pipeline.
7.1.2 ConstantFolding — Constant Folding
use ConstantFolding;
let pass = ConstantFolding;
// Evaluates operations whose operands are all compile-time constants
// Example: add(const(2), const(3)) → const(5)
7.1.3 DeadCodeElimination — Dead Code Elimination
use DeadCodeElimination;
let pass = DeadCodeElimination;
// Removes operations whose results are never used
// Respects operations with side effects (measurements, etc.)
7.1.4 TensorFusion — Tensor Fusion
use TensorFusion;
let pass = TensorFusion;
// Fuses consecutive operations into fused operations
// Example: MatMul + Bias + ReLU → FusedMatMulBiasReLU
// Reduces memory accesses and kernel launches
Combine with: Run after Canonicalize and ConstantFolding.
7.1.5 CommonSubexprElimination — Common Subexpression Elimination
use CommonSubexprElimination;
let pass = CommonSubexprElimination;
// Detects identical operations (same op, same operands)
// Replaces duplicates with references to the first occurrence
// Excludes operations with side effects
7.2 Quantum Passes (3 passes)
7.2.1 GateCancellation — Gate Cancellation
use GateCancellation;
let pass = GateCancellation;
// Removes gate pairs that cancel out
// Example: H H → identity, X X → identity
// Respects qubit linearity invariants
7.2.2 RotationMerge — Rotation Merging
use RotationMerge;
let pass = RotationMerge;
// Merges consecutive rotations on the same axis
// Example: RZ(0.3) RZ(0.5) → RZ(0.8)
// Removes identity rotations (angle ≈ 0)
7.2.3 NoiseAwareSchedule — Noise-Aware Scheduling
use NoiseAwareSchedule;
let pass = NoiseAwareSchedule;
// Reorders quantum gates to minimise decoherence
// Prioritises fast gates (1-qubit) before slow ones (2-qubit)
// Respects SSA dependencies
Combine with: lift-quantum::topology::DeviceTopology for the target topology.
7.3 Advanced AI Passes (3 passes)
7.3.1 FlashAttentionPass — FlashAttention Replacement
use FlashAttentionPass;
let pass = default; // threshold = 512
let pass_custom = FlashAttentionPass ;
// Replaces tensor.attention with tensor.flash_attention
// when sequence length exceeds the threshold
// Reduces memory complexity from O(N²) to O(N)
7.3.2 QuantisationPass — Quantisation Annotation
use QuantisationPass;
use ;
let pass = default; // INT8, Dynamic
let pass_custom = QuantisationPass ;
// Annotates heavy operations (MatMul, Conv, Linear, Attention)
// with quantisation metadata
// Inserts Quantize/Dequantize pairs around annotated ops
| Target | Size | Usage |
|---|---|---|
Int8 |
1 byte | Standard inference |
Int4 |
0.5 byte | Compressed LLMs (GPTQ, AWQ) |
Fp8E4M3 |
1 byte | H100 training |
Fp8E5M2 |
1 byte | H100 inference |
7.3.3 LayoutMapping — Qubit Mapping
use LayoutMapping;
let pass = LayoutMapping;
// Inserts SWAP gates to map logical qubits to physical qubits
// Based on the target device topology
// Marks operations requiring swaps via attributes
Combine with: lift-quantum::topology::DeviceTopology.
7.4 Recommended Optimisation Pipeline
use PassManager;
let mut pm = new;
// Phase 1: Cleanup
pm.add_pass;
pm.add_pass;
pm.add_pass;
pm.add_pass;
// Phase 2: Fusion (AI)
pm.add_pass;
pm.add_pass;
pm.add_pass;
// Phase 3: Quantum
pm.add_pass;
pm.add_pass;
pm.add_pass;
pm.add_pass;
// Phase 4: Final cleanup
pm.add_pass;
let results = pm.run_all;
8. lift-sim — Simulation and Cost Analysis
8.1 CostModel — Classical Cost Model
use CostModel;
// Predefined GPU profiles
let a100 = a100; // 312 TFLOPS, 2039 GB/s
let h100 = h100; // 989 TFLOPS, 3350 GB/s
// Time estimation
let flops = 2 * 1024 * 1024 * 1024_u64;
let bytes = 4 * 1024 * 1024_u64;
let compute_ms = a100.compute_time_ms; // Compute time
let memory_ms = a100.memory_time_ms; // Memory time
let roofline_ms = a100.roofline_time_ms; // Roofline model
// Analysis
let ai = a100.arithmetic_intensity; // FLOPs/byte
let bound = a100.is_compute_bound; // true = compute-bound
let fits = a100.fits_in_memory; // Fits in memory?
let gpus = a100.num_gpus_needed; // GPUs needed
8.2 QuantumCostModel — Quantum Cost Model
use QuantumCostModel;
// Quantum processor profiles
let sc = superconducting_default; // IBM-like: 127 qubits
let ion = trapped_ion_default; // IonQ-like: 32 qubits
let atom = neutral_atom_default; // Atom-like: 256 qubits
// Circuit fidelity estimation
let fidelity = sc.circuit_fidelity; // 50 1Q gates, 20 2Q gates
println!;
// Circuit time
let time_us = sc.circuit_time_us; // 50 1Q, 20 2Q, 5 measurements, 10 depth
println!;
// Decoherence fidelity
let decoherence = sc.decoherence_fidelity;
println!;
| Parameter | Superconducting | Trapped Ions | Neutral Atoms |
|---|---|---|---|
| 1Q time | 0.02 µs | 10 µs | 0.5 µs |
| 2Q time | 0.3 µs | 200 µs | 1.0 µs |
| 1Q fidelity | 99.9% | 99.99% | 99.9% |
| 2Q fidelity | 99% | 99.9% | 99.5% |
| T1 | 100 µs | 1 s | 5 ms |
| Qubits | 127 | 32 | 256 |
8.3 Budget — Resource Constraints
use Budget;
let budget = Budget ;
budget.check_flops.unwrap; // OK
budget.check_memory.unwrap; // OK
budget.check_fidelity.unwrap; // OK
8.4 EnergyModel — Energy and Carbon Estimation
use EnergyModel;
let model = a100;
// Energy for 1 second of computation on 4 GPUs
let joules = model.energy_joules; // Joules
let kwh = model.energy_kwh; // kWh
let carbon = model.carbon_grams; // grams CO₂
println!;
println!;
// Quantum energy (cryogenic refrigeration)
let q_joules = model.quantum_energy_joules; // 100 µs, 127 qubits
8.5 ReactiveBudget — Dynamic Budget
use ;
let budget = Budget ;
let mut rb = new;
// Consume resources incrementally
rb.consume; // flops, mem, time, fidelity
rb.consume;
// Check remaining budget
rb.check_remaining.unwrap; // OK if within limits
// Utilisation report
let util = rb.utilisation;
println!;
println!;
// Remaining budget
println!;
println!;
Combine with: lift-opt (stop optimisation if budget exhausted), lift-predict (verify prediction respects budget).
8.6 Module Analysis
use ;
let ctx = load_and_parse.unwrap;
// Classical analysis
let report = analyze_module;
println!;
println!;
println!;
println!;
println!;
println!;
println!;
// Quantum analysis
let quantum = analyze_quantum_ops;
println!;
println!;
println!;
println!;
println!;
println!;
9. lift-predict — Performance Prediction
use predict_performance;
use ;
let report = analyze_module;
let cost_model = h100;
let prediction = predict_performance;
println!;
println!;
println!;
println!;
println!; // "compute" or "memory"
Combine with: lift-sim (provides the analysis report and cost model).
10. lift-import — Model Import
10.1 ONNX Import
use OnnxImporter;
let importer = new;
let ctx = importer.import.expect;
10.2 PyTorch FX Import
use PyTorchFxImporter;
let importer = new;
let ctx = importer.import.expect;
10.3 OpenQASM 3.0 Import
use OpenQasm3Importer;
let importer = new;
let ctx = importer.import.expect;
Combine with: lift-core::verifier (verify imported IR), then lift-opt (optimise).
11. lift-export — Backend Export
11.1 Export LLVM IR
use LlvmExporter;
let exporter = new;
let llvm_ir = exporter.export.expect;
write.unwrap;
Produces LLVM IR compilable with clang or llc.
11.2 Export OpenQASM 3.0
use QasmExporter;
let exporter = new;
let qasm = exporter.export.expect;
write.unwrap;
Produces OpenQASM 3.0 executable on IBM Quantum, Rigetti, etc.
Combine with: lift-opt (optimise before export), lift-quantum::Provider (transpile to native gate set).
12. lift-config — Configuration (.lith)
12.1 .lith File Format
[target]
backend = "cuda"
device = "A100"
precision = "fp16"
[budget]
max_flops = 1000000000000
max_memory_bytes = 80000000000
max_time_ms = 100.0
min_fidelity = 0.99
[optimisation]
level = O2
max_iterations = 10
[simulation]
shape_propagation = true
flop_counting = true
memory_analysis = true
noise_simulation = true
[quantum]
topology = "heavy_hex"
num_qubits = 127
shots = 4096
12.2 Programmatic Loading
use ;
// From a file
let source = read_to_string.unwrap;
let config = new.parse.unwrap;
// Default configuration
let default = default;
// Backend: llvm, Level: O2, Passes: canonicalize, constant-folding, dce, tensor-fusion
// With quantum
let hybrid = default.with_quantum;
12.3 Optimisation Levels
| Level | Passes | Usage |
|---|---|---|
O0 |
None | Debug, verification |
O1 |
Canonicalize, DCE | Fast compilation |
O2 |
+ ConstantFolding, TensorFusion | Default — good trade-off |
O3 |
+ FlashAttention, Quantisation, CSE | Maximum performance |
13. lift-cli — Command-Line Interface
13.1 Available Commands
13.1.1 lift verify — Verify a .lif file
Checks SSA invariants, qubit linearity, and typing.
13.1.2 lift analyse — Analyse a program
Produces a report: op count, FLOPs, memory, quantum analysis.
13.1.3 lift print — Display the IR
Affiche l'IR en format lisible.
13.1.4 lift optimise — Optimiser
Applique les passes d'optimisation configurées.
13.1.5 lift predict — Prédire la performance
Prédit le temps d'exécution avec le modèle roofline.
13.1.6 lift export — Exporter
Exporte vers LLVM IR ou OpenQASM 3.0.
14. Combinaisons et pipelines complets
14.1 Pipeline IA complet (Transformer)
// 1. Importer un modèle ONNX
let ctx = new.import?;
// 2. Vérifier
verify?;
// 3. Analyser
let report = analyze_module;
// 4. Optimiser
let mut pm = new;
pm.add_pass;
pm.add_pass;
pm.add_pass;
pm.add_pass;
pm.add_pass;
pm.add_pass;
pm.add_pass;
pm.add_pass;
pm.run_all;
// 5. Prédire la performance
let h100 = h100;
let pred = predict_performance;
// 6. Exporter vers LLVM
let llvm = new.export?;
write?;
14.2 Pipeline quantique complet (Bell State)
// 1. Parser le circuit
let ctx = load_lif_file?;
// 2. Analyser le bruit
let quantum = analyze_quantum_ops;
let sc = superconducting_default;
let fidelity = sc.circuit_fidelity;
// 3. QEC si nécessaire
if fidelity < 0.99
// 4. Optimiser
let mut pm = new;
pm.add_pass;
pm.add_pass;
pm.add_pass;
pm.add_pass;
pm.run_all;
// 5. Exporter vers QASM
let qasm = new.export?;
write?;
14.3 Pipeline hybride complet (VQE)
// 1. Configurer l'encodage
let encoding = new;
// 2. Configurer le gradient
let grad_config = JointGradientConfig ;
// 3. Budget réactif pour contrôler les ressources
let budget = Budget ;
let mut rb = new;
// 4. Boucle d'optimisation VQE
for iteration in 0..100
// 5. Estimer l'empreinte carbone
let energy = a100;
let carbon = energy.carbon_grams;
println!;
14.4 Pipeline CLI complet
# Vérifier, analyser, optimiser, prédire et exporter en une séquence
15. Exemples concrets
15.1 MLP (Perceptron multi-couches)
Fichier tensor_mlp.lif :
#dialect tensor
module @mlp {
func @forward(%x: tensor<1x784xf32>, %w1: tensor<784x256xf32>,
%b1: tensor<256xf32>, %w2: tensor<256x10xf32>,
%b2: tensor<10xf32>) -> tensor<1x10xf32> {
%h1 = "tensor.matmul"(%x, %w1) : (tensor<1x784xf32>, tensor<784x256xf32>) -> tensor<1x256xf32>
%h2 = "tensor.add"(%h1, %b1) : (tensor<1x256xf32>, tensor<256xf32>) -> tensor<1x256xf32>
%h3 = "tensor.relu"(%h2) : (tensor<1x256xf32>) -> tensor<1x256xf32>
%h4 = "tensor.matmul"(%h3, %w2) : (tensor<1x256xf32>, tensor<256x10xf32>) -> tensor<1x10xf32>
%h5 = "tensor.add"(%h4, %b2) : (tensor<1x10xf32>, tensor<10xf32>) -> tensor<1x10xf32>
%out = "tensor.softmax"(%h5) : (tensor<1x10xf32>) -> tensor<1x10xf32>
return %out
}
}
15.2 Self-Attention (Transformer)
Fichier attention.lif :
#dialect tensor
module @transformer {
func @self_attention(%q: tensor<1x128x64xf32>, %k: tensor<1x128x64xf32>,
%v: tensor<1x128x64xf32>, %norm_w: tensor<64xf32>)
-> tensor<1x128x64xf32> {
%attn = "tensor.attention"(%q, %k, %v) : (...) -> tensor<1x128x64xf32>
%normed = "tensor.layernorm"(%attn, %norm_w) : (...) -> tensor<1x128x64xf32>
return %normed
}
}
15.3 État de Bell (Quantique)
Fichier quantum_bell.lif :
#dialect quantum
module @bell_state {
func @bell(%q0: qubit, %q1: qubit) -> (qubit, qubit) {
%q2 = "quantum.h"(%q0) : (qubit) -> qubit
%q3, %q4 = "quantum.cx"(%q2, %q1) : (qubit, qubit) -> (qubit, qubit)
return %q3, %q4
}
}
15.4 Configuration de production
Fichier production.lith :
[target]
backend = "cuda"
device = "H100"
precision = "fp16"
[budget]
max_flops = 1000000000000
max_memory_bytes = 80000000000
max_time_ms = 100.0
[optimisation]
level = O3
max_iterations = 20
[simulation]
shape_propagation = true
flop_counting = true
memory_analysis = true
noise_simulation = true
[quantum]
topology = "heavy_hex"
num_qubits = 127
shots = 4096
Résumé des combinaisons par tâche
| Tâche | Crates à combiner |
|---|---|
| Entraîner un LLM | lift-tensor + lift-opt (TensorFusion, FlashAttention) + lift-sim (CostModel) + lift-export (LLVM) |
| Inférence quantisée | lift-tensor + lift-opt (QuantisationPass) + lift-predict + lift-export (LLVM) |
| Circuit quantique | lift-quantum + lift-opt (GateCancellation, RotationMerge, LayoutMapping) + lift-export (QASM) |
| VQE / QAOA | lift-hybrid + lift-quantum + lift-opt (NoiseAwareSchedule) + lift-sim (QuantumCostModel) |
| Quantum ML | lift-hybrid (QuantumKernel, encoding) + lift-tensor + lift-quantum |
| Analyse de coût | lift-sim (CostModel, EnergyModel) + lift-predict |
| QEC planning | lift-quantum (qec, topology) + lift-sim (QuantumCostModel) |
| Import/Optimise/Export | lift-import + lift-opt + lift-export |
| Stable Diffusion | lift-tensor (UNet ops) + lift-opt (TensorFusion) + lift-export |
| GNN | lift-tensor (GNNMessagePassing, GNNGlobalPooling) + lift-opt + lift-export |