1313
1414from __future__ import annotations
1515
16- from typing import Any
17-
18- import numpy as np
16+ from typing import Any , List
1917
2018from pecos_rslib ._pecos_rslib import RsStateVec as RustStateVec
2119
@@ -33,24 +31,28 @@ def __init__(self, num_qubits: int):
3331 self .bindings = dict (gate_dict )
3432
3533 @property
36- def vector (self ) -> np . ndarray :
34+ def vector (self ) -> List [ complex ] :
3735 raw_vector = self ._sim .vector
3836 print (f"[DEBUG] Raw vector: { raw_vector } " )
3937
38+ # Convert to list of complex numbers
4039 if isinstance (raw_vector [0 ], (list , tuple )):
41- raw_vector = np .array ([complex (r , i ) for r , i in raw_vector ])
40+ vector = [complex (r , i ) for r , i in raw_vector ]
41+ else :
42+ vector = list (raw_vector )
4243
4344 # Convert vector from little-endian to big-endian ordering to match BasicSV
44- raw_vector = np .array (raw_vector ).flatten ()
4545 num_qubits = self .num_qubits
4646
47- # Convert to big-endian by reversing bit order
48- indices = np .arange (len (raw_vector ))
49- binary_indices = [f"{ idx :0{num_qubits }b} " for idx in indices ]
47+ # Create indices mapping using pure Python
48+ indices = list (range (len (vector )))
49+ # Convert indices to binary strings with proper length
50+ binary_indices = [format (idx , f"0{ num_qubits } b" ) for idx in indices ]
51+ # Reverse bits to change endianness
5052 reordered_indices = [int (bits [::- 1 ], 2 ) for bits in binary_indices ]
5153
52- # Reorder the vector to match BasicSV's bit ordering
53- final_vector = raw_vector [ reordered_indices ]
54+ # Reorder the vector using pure Python
55+ final_vector = [ vector [ idx ] for idx in reordered_indices ]
5456
5557 return final_vector
5658
0 commit comments