@@ -641,19 +641,23 @@ def aggregate_shots(self, shots):
641
641
return self .cast (shots , dtype = shots [0 ].dtype )
642
642
643
643
def samples_to_binary (self , samples , nqubits ):
644
- qrange = self . np . arange ( nqubits - 1 , - 1 , - 1 , dtype = self . np . int32 )
645
- return self . np .mod (
646
- self .np . right_shift ( self . cast ( samples [:, None ], dtype = "int32" ), qrange ), 2
647
- )
644
+ ### This is faster just staying @ NumPy.
645
+ qrange = np .arange ( nqubits - 1 , - 1 , - 1 , dtype = np . int32 )
646
+ samples = self .to_numpy ( samples )
647
+ return np . mod ( np . right_shift ( samples [:, None ], qrange ), 2 )
648
648
649
649
def samples_to_decimal (self , samples , nqubits ):
650
- qrange = self .np .arange (nqubits - 1 , - 1 , - 1 , dtype = self .np .int32 )
650
+ ### This is faster just staying @ NumPy.
651
+ qrange = np .arange (nqubits - 1 , - 1 , - 1 , dtype = np .int32 )
651
652
qrange = (2 ** qrange )[:, None ]
652
- return self .np .matmul (samples , qrange )[:, 0 ]
653
+ samples = np .asarray (samples .tolist ())
654
+ return np .matmul (samples , qrange )[:, 0 ]
653
655
654
656
def calculate_frequencies (self , samples ):
655
657
# Samples are a list of strings so there is no advantage in using other backends
656
658
res , counts = np .unique (samples , return_counts = True )
659
+ res = self .to_numpy (res ).tolist ()
660
+ counts = self .to_numpy (counts ).tolist ()
657
661
return collections .Counter (dict (zip (res , counts )))
658
662
659
663
def update_frequencies (self , frequencies , probabilities , nsamples ):
@@ -677,6 +681,7 @@ def sample_frequencies(self, probabilities, nshots):
677
681
)
678
682
679
683
def apply_bitflips (self , noiseless_samples , bitflip_probabilities ):
684
+ noiseless_samples = self .cast (noiseless_samples , dtype = noiseless_samples .dtype )
680
685
fprobs = self .cast (bitflip_probabilities , dtype = "float64" )
681
686
sprobs = self .cast (np .random .random (noiseless_samples .shape ), dtype = "float64" )
682
687
flip_0 = self .cast (sprobs < fprobs [0 ], dtype = noiseless_samples .dtype )
0 commit comments