Skip to main content

CLiveExecution

Struct CLiveExecution 

Source
#[repr(C)]
pub struct CLiveExecution { pub compute_gate: fn(json: *const c_char) -> i32, pub compute_native_gates: fn(json: *const c_char) -> i32, pub measure: fn(qubits: *const usize, len: usize, result: &mut u64) -> i32, pub dump: fn(qubits: *const usize, len: usize, result_json: &mut *const c_char) -> i32, pub sample: fn(qubits: *const usize, len: usize, shots: usize, result_json: &mut *const c_char) -> i32, pub exp_value: fn(hamiltonian_json: *const c_char, result: &mut f64) -> i32, }
Expand description

FFI-compatible function-pointer table for a live (gate-at-a-time) execution backend.

In live mode each gate is dispatched to the hardware or simulator immediately as it is applied to the process, and measurement results are available without an explicit ket_process_execute call.

Construct a CLiveExecution value on the C side, fill in all function pointers, then call ket_quantum_execution_live to create the corresponding QuantumExecution variant.

All callbacks must return 0 on success or a non-zero libket error code on failure.

Fields§

§compute_gate: fn(json: *const c_char) -> i32

Dispatch a single quantum gate to the backend.

json is a null-terminated JSON string encoding the gate instruction (type, parameters, target qubit, etc.). Returns 0 on success.

§compute_native_gates: fn(json: *const c_char) -> i32

Dispatch a sequence of pre-translated native gate instructions to the backend.

json is a null-terminated JSON string encoding the array of native gate instructions (each a [name, angles, qubits] triple). Returns 0 on success.

§measure: fn(qubits: *const usize, len: usize, result: &mut u64) -> i32

Perform a single-shot measurement of len qubits.

qubits points to an array of len qubit indices. On success the measurement result is written to *result as a bitmask where bit i corresponds to qubits[i]. Returns 0 on success.

§dump: fn(qubits: *const usize, len: usize, result_json: &mut *const c_char) -> i32

Retrieve the full quantum state (probability amplitudes) of len qubits.

qubits points to an array of len qubit indices. On success *result_json is set to a heap-allocated null-terminated JSON string encoding the state; Rust will parse it and then it is the C side’s responsibility to manage the lifetime. Returns 0 on success.

§sample: fn(qubits: *const usize, len: usize, shots: usize, result_json: &mut *const c_char) -> i32

Perform a repeated measurement sample of len qubits over shots shots.

qubits points to an array of len qubit indices. On success *result_json is set to a heap-allocated null-terminated JSON string with the sample counts. Returns 0 on success.

§exp_value: fn(hamiltonian_json: *const c_char, result: &mut f64) -> i32

Compute the expectation value of a Hamiltonian on the current quantum state.

hamiltonian_json is a null-terminated JSON string encoding the Hamiltonian. On success *result is set to the computed expectation value. Returns 0 on success.

Trait Implementations§

Source§

impl Clone for CLiveExecution

Source§

fn clone(&self) -> CLiveExecution

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CLiveExecution

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl LiveExecution for CLiveExecution

Source§

fn compute_gate(&mut self, gate: &GateInstruction) -> Result<(), KetError>

Dispatches a single logical gate instruction to the backend. Read more
Source§

fn compute_native_gates(&mut self, gates: &[NativeGate]) -> Result<(), KetError>

Dispatches a sequence of already-translated native gate instructions to the backend. Read more
Source§

fn measure(&mut self, qubits: &[usize]) -> Result<u64, KetError>

Collapses and reads out the specified qubits, returning the result as a packed integer (bit i corresponds to qubits[i]). Read more
Source§

fn sample( &mut self, qubits: &[usize], shots: usize, ) -> Result<SampleData, KetError>

Samples the measurement distribution of qubits over shots repetitions. Read more
Source§

fn exp_value(&mut self, hamiltonian: Hamiltonian) -> Result<f64, KetError>

Computes the expectation value of hamiltonian with respect to the current quantum state. Read more
Source§

fn dump(&mut self, qubits: &[usize]) -> Result<DumpData, KetError>

Returns a full state-vector snapshot restricted to qubits. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.