File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 4040
4141- Fix to use ` status ` for ` circuit.sample ` when ` allow_state=True ` .
4242
43+ - Fix sample bug when number of qubit exceeding 32.
44+
4345### Changed
4446
4547- The order of arguments of ` tc.timeevol.ed_evol ` are changed for consistent interface with other evolution methods.
Original file line number Diff line number Diff line change 1919 correlation_from_counts ,
2020 measurement_counts ,
2121 sample_int2bin ,
22- sample_bin2int ,
2322 sample2all ,
2423)
2524from .abstractcircuit import AbstractCircuit
@@ -619,8 +618,8 @@ def perfect_sampling(key: Any) -> Any:
619618 if format is None :
620619 return r
621620 r = backend .stack ([ri [0 ] for ri in r ]) # type: ignore
622- r = backend .cast (r , "int32" )
623- ch = sample_bin2int (r , self ._nqubits )
621+ ch = backend .cast (r , "int32" )
622+ # ch = sample_bin2int(r, self._nqubits)
624623 else : # allow_state
625624 if batch is None :
626625 nbatch = 1
Original file line number Diff line number Diff line change 99import os
1010from functools import partial , reduce
1111from operator import matmul , mul , or_
12+ from collections import Counter
1213from typing import (
1314 Any ,
1415 Callable ,
@@ -2886,6 +2887,17 @@ def sample2all(
28862887 :return: measurement results specified as ``format``
28872888 :rtype: Any
28882889 """
2890+ if n > 32 :
2891+ assert (
2892+ len (backend .shape_tuple (sample )) == 2
2893+ ), "n>32 is only supported for ``sample_bin``"
2894+ if format == "sample_bin" :
2895+ return sample
2896+ if format == "count_dict_bin" :
2897+ binary_strings = ["" .join (map (str , shot )) for shot in sample ]
2898+ return dict (Counter (binary_strings ))
2899+ raise ValueError (f"n={ n } is too large for measurement representaion: { format } " )
2900+
28892901 if len (backend .shape_tuple (sample )) == 1 :
28902902 sample_int = sample
28912903 sample_bin = sample_int2bin (sample , n )
You can’t perform that action at this time.
0 commit comments