當前位置: 首頁>>代碼示例>>Python>>正文


Python PauliClass.powerset方法代碼示例

本文整理匯總了Python中PauliClass.powerset方法的典型用法代碼示例。如果您正苦於以下問題:Python PauliClass.powerset方法的具體用法?Python PauliClass.powerset怎麽用?Python PauliClass.powerset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PauliClass的用法示例。


在下文中一共展示了PauliClass.powerset方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: minimize_distance_from

# 需要導入模塊: import PauliClass [as 別名]
# 或者: from PauliClass import powerset [as 別名]
 def minimize_distance_from(self, other, quiet=True):
     """
     Reorders the stabilizer group generators of this code to minimize
     the Hamming distance with the group generators of another code,
     using a greedy heuristic algorithm.
     """
     
     self_gens = self.group_generators
     other_gens = other.group_generators
     
     for idx_generator in range(len(self_gens)):
         min_hdist    = self.nq + 1 # Effectively infinite.
         min_wt       = self.nq + 1
         best_gen = None
         best_gen_decomp = ()
         
         for stab_elems in p.powerset(self_gens[idx_generator:]):
             if len(stab_elems) > 0:
                 stab_elem = reduce(op.mul, stab_elems)
                 hd = stab_elem.hamming_dist(other_gens[idx_generator])
                 
                 if hd <= min_hdist and stab_elem.wt <= min_wt and (hd < min_hdist or stab_elem.wt < min_wt):
                     min_hdist = hd
                     min_wt    = stab_elem.wt
                     best_gen  = stab_elem
                     best_gen_decomp = stab_elems
                 
         assert best_gen is not None, "Powerset iteration failed."
                 
         if best_gen in self_gens:
             # Swap so that it lies at the front.
             idx = self_gens.index(best_gen)
             if not quiet and idx != idx_generator:
                 print 'Swap move: {} <-> {}'.format(idx_generator, idx)
             self_gens[idx_generator], self_gens[idx] = self_gens[idx], self_gens[idx_generator]
             
         else:
             # Set the head element to best_gen, correcting the rest
             # as needed.
             if self_gens[idx_generator] in best_gen_decomp:
                 if not quiet:
                     print 'Set move: {}  =  {}'.format(idx_generator, best_gen)
                 self_gens[idx_generator] = best_gen
             else:
                 if not quiet:
                     print 'Mul move: {} *=  {}'.format(idx_generator, best_gen)
                 self_gens[idx_generator] *= best_gen
                 
     return self
開發者ID:Roger-luo,項目名稱:python-quaec,代碼行數:51,代碼來源:stab.py


注:本文中的PauliClass.powerset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。