@@ -165,6 +165,18 @@ impl Engine for StateVecEngine {
165165 self . simulator . szdg ( usize:: from ( * q) ) ;
166166 }
167167 }
168+ GateType :: SX => {
169+ for q in & cmd. qubits {
170+ debug ! ( "Processing SX gate on qubit {q:?}" ) ;
171+ self . simulator . sx ( usize:: from ( * q) ) ;
172+ }
173+ }
174+ GateType :: SXdg => {
175+ for q in & cmd. qubits {
176+ debug ! ( "Processing SXdg gate on qubit {q:?}" ) ;
177+ self . simulator . sxdg ( usize:: from ( * q) ) ;
178+ }
179+ }
168180 GateType :: T => {
169181 for q in & cmd. qubits {
170182 debug ! ( "Processing T gate on qubit {q:?}" ) ;
@@ -276,6 +288,86 @@ impl Engine for StateVecEngine {
276288 . szzdg ( usize:: from ( qubits[ 0 ] ) , usize:: from ( qubits[ 1 ] ) ) ;
277289 }
278290 }
291+ GateType :: SWAP => {
292+ if cmd. qubits . len ( ) % 2 != 0 {
293+ return Err ( quantum_error ( format ! (
294+ "SWAP gate requires even number of qubits, got {}" ,
295+ cmd. qubits. len( )
296+ ) ) ) ;
297+ }
298+ for qubits in cmd. qubits . chunks_exact ( 2 ) {
299+ debug ! (
300+ "Processing SWAP gate on qubits {:?} and {:?}" ,
301+ qubits[ 0 ] , qubits[ 1 ]
302+ ) ;
303+ // SWAP = CX(0,1) CX(1,0) CX(0,1)
304+ let q0 = usize:: from ( qubits[ 0 ] ) ;
305+ let q1 = usize:: from ( qubits[ 1 ] ) ;
306+ self . simulator . cx ( q0, q1) ;
307+ self . simulator . cx ( q1, q0) ;
308+ self . simulator . cx ( q0, q1) ;
309+ }
310+ }
311+ GateType :: CRZ => {
312+ if cmd. qubits . len ( ) % 2 != 0 {
313+ return Err ( quantum_error ( format ! (
314+ "CRZ gate requires even number of qubits, got {}" ,
315+ cmd. qubits. len( )
316+ ) ) ) ;
317+ }
318+ if cmd. angles . is_empty ( ) {
319+ return Err ( quantum_error ( "CRZ gate requires at least one angle" ) ) ;
320+ }
321+ let angle = cmd. angles [ 0 ] . to_radians ( ) ;
322+ let half_angle = angle / 2.0 ;
323+ for qubits in cmd. qubits . chunks_exact ( 2 ) {
324+ debug ! (
325+ "Processing CRZ gate on qubits {:?} and {:?} with angle {:?}" ,
326+ qubits[ 0 ] , qubits[ 1 ] , angle
327+ ) ;
328+ // CRZ(θ) = Rz(θ/2) on target, CX, Rz(-θ/2) on target, CX
329+ let control = usize:: from ( qubits[ 0 ] ) ;
330+ let target = usize:: from ( qubits[ 1 ] ) ;
331+ self . simulator . rz ( half_angle, target) ;
332+ self . simulator . cx ( control, target) ;
333+ self . simulator . rz ( -half_angle, target) ;
334+ self . simulator . cx ( control, target) ;
335+ }
336+ }
337+ GateType :: CCX => {
338+ if cmd. qubits . len ( ) % 3 != 0 {
339+ return Err ( quantum_error ( format ! (
340+ "CCX gate requires a multiple of 3 qubits, got {}" ,
341+ cmd. qubits. len( )
342+ ) ) ) ;
343+ }
344+ for qubits in cmd. qubits . chunks_exact ( 3 ) {
345+ debug ! (
346+ "Processing CCX gate with controls {:?}, {:?} and target {:?}" ,
347+ qubits[ 0 ] , qubits[ 1 ] , qubits[ 2 ]
348+ ) ;
349+ // Toffoli decomposition into Clifford+T gates
350+ let c0 = usize:: from ( qubits[ 0 ] ) ;
351+ let c1 = usize:: from ( qubits[ 1 ] ) ;
352+ let target = usize:: from ( qubits[ 2 ] ) ;
353+ // Standard decomposition (15 gates)
354+ self . simulator . h ( target) ;
355+ self . simulator . cx ( c1, target) ;
356+ self . simulator . tdg ( target) ;
357+ self . simulator . cx ( c0, target) ;
358+ self . simulator . t ( target) ;
359+ self . simulator . cx ( c1, target) ;
360+ self . simulator . tdg ( target) ;
361+ self . simulator . cx ( c0, target) ;
362+ self . simulator . t ( c1) ;
363+ self . simulator . t ( target) ;
364+ self . simulator . cx ( c0, c1) ;
365+ self . simulator . h ( target) ;
366+ self . simulator . t ( c0) ;
367+ self . simulator . tdg ( c1) ;
368+ self . simulator . cx ( c0, c1) ;
369+ }
370+ }
279371 GateType :: RX => {
280372 if !cmd. angles . is_empty ( ) {
281373 let angle = cmd. angles [ 0 ] . to_radians ( ) ;
0 commit comments