pub trait BatchExecution {
// Provided methods
fn sample(
&self,
_gates: &[GateInstruction],
_qubits_to_sample: &[usize],
_shots: usize,
) -> Result<SampleData, KetError> { ... }
fn exp_value(
&self,
_gates: &[GateInstruction],
_hamiltonian_list: &[Hamiltonian],
) -> Result<Vec<f64>, KetError> { ... }
fn sample_native(
&self,
_gates: &[NativeGate],
_qubits_to_sample: &[usize],
_shots: usize,
) -> Result<SampleData, KetError> { ... }
fn exp_value_native(
&self,
_gates: &[NativeGate],
_hamiltonian_list: &[Hamiltonian],
) -> Result<Vec<f64>, KetError> { ... }
fn gradient(
&self,
_gates: &[GateInstruction],
_hamiltonian: &Hamiltonian,
) -> Result<(f64, Vec<f64>), KetError> { ... }
}Expand description
A backend that receives a fully-compiled gate sequence and returns aggregate results without mid-circuit feedback.
There are two families of methods: IR-level (sample, exp_value,
gradient) which receive GateInstruction slices directly from the
Libket IR, and native-level (sample_native, exp_value_native) which
receive sequences of NativeGate tuples already translated through a
NativeGateSet.
All methods have a default implementation that returns an error, so implementors only need to override the methods they support.
Provided Methods§
Sourcefn sample(
&self,
_gates: &[GateInstruction],
_qubits_to_sample: &[usize],
_shots: usize,
) -> Result<SampleData, KetError>
fn sample( &self, _gates: &[GateInstruction], _qubits_to_sample: &[usize], _shots: usize, ) -> Result<SampleData, KetError>
Executes gates and samples the state of qubits_to_sample over
shots shots, receiving gates in the Libket IR format.
Implement this method when the backend can accept GateInstruction
slices directly (i.e., no NativeGateSet translation is configured).
§Errors
Returns KetError::GateUnsupported by default. Implementations should
return KetError::ExecutionFailed for backend faults or
KetError::ShotCountInvalid for an out-of-range shot count.
Sourcefn exp_value(
&self,
_gates: &[GateInstruction],
_hamiltonian_list: &[Hamiltonian],
) -> Result<Vec<f64>, KetError>
fn exp_value( &self, _gates: &[GateInstruction], _hamiltonian_list: &[Hamiltonian], ) -> Result<Vec<f64>, KetError>
Executes gates and computes the expectation value of each Hamiltonian
in hamiltonian_list, receiving gates in the Libket IR format.
Implement this method when the backend can accept GateInstruction
slices directly (i.e., no NativeGateSet translation is configured).
§Errors
Returns KetError::GateUnsupported by default. Implementations should
return KetError::ExecutionFailed for backend faults.
Sourcefn sample_native(
&self,
_gates: &[NativeGate],
_qubits_to_sample: &[usize],
_shots: usize,
) -> Result<SampleData, KetError>
fn sample_native( &self, _gates: &[NativeGate], _qubits_to_sample: &[usize], _shots: usize, ) -> Result<SampleData, KetError>
Executes gates and samples the state of qubits_to_sample over
shots shots, receiving pre-translated native gates.
Called when a NativeGateSet translation layer is configured. The
gates slice contains hardware-specific instructions produced by
NativeGateSet::translate or NativeGateSet::cnot.
§Errors
Returns KetError::GateUnsupported by default. Implementations should
return KetError::ExecutionFailed for backend faults or
KetError::ShotCountInvalid for an out-of-range shot count.
Sourcefn exp_value_native(
&self,
_gates: &[NativeGate],
_hamiltonian_list: &[Hamiltonian],
) -> Result<Vec<f64>, KetError>
fn exp_value_native( &self, _gates: &[NativeGate], _hamiltonian_list: &[Hamiltonian], ) -> Result<Vec<f64>, KetError>
Executes gates and computes the expectation value of each Hamiltonian
in hamiltonian_list, receiving pre-translated native gates.
Called when a NativeGateSet translation layer is configured. The
gates slice contains hardware-specific instructions produced by
NativeGateSet::translate or NativeGateSet::cnot.
§Errors
Returns KetError::NativeGateUnsupported by default. Implementations
should return KetError::ExecutionFailed for backend faults.
Sourcefn gradient(
&self,
_gates: &[GateInstruction],
_hamiltonian: &Hamiltonian,
) -> Result<(f64, Vec<f64>), KetError>
fn gradient( &self, _gates: &[GateInstruction], _hamiltonian: &Hamiltonian, ) -> Result<(f64, Vec<f64>), KetError>
Computes the expectation value and its gradient with respect to all circuit parameters in a single backend call.
Returns (expectation_value, gradient_vector) where
gradient_vector[i] is ∂⟨H⟩/∂θᵢ for parameter i.
This method is used when GradientStrategy::Native is selected. If
the backend cannot compute gradients natively, implement
GradientStrategy::ParameterShiftRule instead.
§Errors
Returns KetError::NativeGradientUnsuported by default. Implementations
should return KetError::ExecutionFailed for backend faults.
Trait Implementations§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".