Skip to main content

Module execute

Module execute 

Source
Expand description

C API bindings for quantum execution backends.

This module defines the FFI-compatible structs (CLiveExecution, CBatchExecution, CNativeGateSet) that allow external C/C++ quantum simulators or hardware drivers to plug into the Libket execution pipeline.

§JSON serialization contract

All data exchanged between Rust and the C callbacks is serialized as JSON:

  • Rust → C: gate instructions, Hamiltonians, and gate matrices are serialized with serde_json into null-terminated C strings before being passed to the corresponding callback.
  • C → Rust: JSON strings returned by C callbacks (e.g., sample counts, state dumps, native gate sequences) are parsed back with serde_json on the Rust side. If parsing fails, KetError::SerdeError is returned.

Heap-allocated strings returned by C callbacks are not freed by Rust; the C backend is responsible for their lifetime (typically they are freed via super::ket_string_delete by the caller of the top-level C API).

Structs§

CBatchExecution
FFI-compatible function-pointer table for a batch execution backend.
CLiveExecution
FFI-compatible function-pointer table for a live (gate-at-a-time) execution backend.
CNativeGateSet
FFI-compatible function-pointer table for translating abstract gates into backend-native instructions.

Functions§

ket_quantum_execution_batch
Creates a batch-mode QuantumExecution backed by the provided callback tables.
ket_quantum_execution_live
Creates a live-mode QuantumExecution backed by the provided callback table.