Skip to main content

Module state_vector_simd

Module state_vector_simd 

Source
Expand description

SIMD-accelerated single-qubit gate kernels for state vector simulation.

This module provides a high-level public API for applying individual quantum gates directly to Vec<Complex64> state vectors. It owns the gather/scatter logic internally so callers do not need to split amplitudes into separate in_amps0 / in_amps1 buffers themselves.

Internally the implementations delegate to the existing crate::optimized_simd SIMD primitives (backed by scirs2_core::simd_ops::SimdUnifiedOps) for all vector arithmetic, with a scalar fallback for small state vectors (< 256 amplitudes, i.e. < 8 qubits).

§Usage example

use quantrs2_sim::state_vector_simd::{apply_h_simd, apply_x_simd};
use scirs2_core::Complex64;

let n_qubits = 4usize;
let mut state = vec![Complex64::new(0.0, 0.0); 1 << n_qubits];
state[0] = Complex64::new(1.0, 0.0); // |0000⟩

apply_h_simd(&mut state, 0, n_qubits);   // qubit 0 → |+⟩
apply_x_simd(&mut state, 1, n_qubits);   // qubit 1 → |1⟩ (CNOT-like)

These SIMD kernels are provided as a standalone module and can be called directly. Integration into the main StateVectorSimulator dispatch already exists in statevector.rs via apply_single_qubit_gate_simd; this module adds the named, standalone API surface (see also TODO.md).

Functions§

apply_gate_2x2_scalar
Pure-scalar application of a 2×2 unitary matrix to qubit target.
apply_gate_2x2_simd
Apply a generic 2×2 unitary gate to qubit target using SIMD acceleration.
apply_h_simd
Apply the Hadamard gate H to qubit target using SIMD.
apply_rx_simd
Apply the RX(theta) rotation gate to qubit target using SIMD.
apply_ry_simd
Apply the RY(theta) rotation gate to qubit target using SIMD.
apply_rz_simd
Apply the RZ(theta) rotation gate to qubit target using SIMD.
apply_s_simd
Apply the S (phase) gate to qubit target using SIMD.
apply_t_simd
Apply the T gate to qubit target using SIMD.
apply_x_simd
Apply the Pauli-X (NOT) gate to qubit target using SIMD.
apply_y_simd
Apply the Pauli-Y gate to qubit target using SIMD.
apply_z_simd
Apply the Pauli-Z gate to qubit target using SIMD.
simd_available
Returns true when SIMD acceleration is available at runtime on this CPU.