当前位置: 首页>>代码示例>>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;未经允许,请勿转载。