pub trait NativeGateSet {
// Required methods
fn translate(
&self,
matrix: &[[Complex<f64>; 2]; 2],
target: usize,
) -> Result<Vec<NativeGate>, KetError>;
fn cnot(
&self,
control: usize,
target: usize,
) -> Result<Vec<NativeGate>, KetError>;
}Expand description
Translates Libket IR gates into hardware-specific native gate sequences.
Implement this trait to map the compiler’s intermediate representation into
the physical instruction set of a specific QPU or simulator. The default implementation
(RzRyCX) uses a ZYZ Euler decomposition and emits rz, ry, and cnot instructions.
Required Methods§
Sourcefn translate(
&self,
matrix: &[[Complex<f64>; 2]; 2],
target: usize,
) -> Result<Vec<NativeGate>, KetError>
fn translate( &self, matrix: &[[Complex<f64>; 2]; 2], target: usize, ) -> Result<Vec<NativeGate>, KetError>
Translates the 2×2 complex unitary matrix acting on target into
zero or more native single-qubit gate instructions.
The matrix is represented as [[Cf64; 2]; 2] (row-major). Backends
may recognise special patterns (H, Rz, etc.) and emit optimised
instructions accordingly.
§Errors
Returns KetError::NativeGateUnsupported if the matrix cannot be
translated into the backend’s instruction set.
Sourcefn cnot(
&self,
control: usize,
target: usize,
) -> Result<Vec<NativeGate>, KetError>
fn cnot( &self, control: usize, target: usize, ) -> Result<Vec<NativeGate>, KetError>
Translates a CNOT gate into native gate instructions.
§Errors
Returns KetError::NativeGateUnsupported if CNOT is not supported.
Trait Implementations§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".