本文整理匯總了Python中PauliClass.elem_gen方法的典型用法代碼示例。如果您正苦於以下問題:Python PauliClass.elem_gen方法的具體用法?Python PauliClass.elem_gen怎麽用?Python PauliClass.elem_gen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PauliClass
的用法示例。
在下文中一共展示了PauliClass.elem_gen方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: star_decoder
# 需要導入模塊: import PauliClass [as 別名]
# 或者: from PauliClass import elem_gen [as 別名]
def star_decoder(self, for_enc=None, as_dict=False):
r"""
Returns a tuple of a decoding Clifford and a :class:`qecc.PauliList`
specifying the recovery operation to perform as a function of the result
of a :math:`Z^{\otimes{n - k}}` measurement on the ancilla register.
For syndromes corresponding to errors of weight greater than the distance,
the relevant element of the recovery list will be set to
:obj:`qecc.Unspecified`.
:param for_enc: If not ``None``, specifies to use a given Clifford
operator as the encoder, instead of the first element yielded by
:meth:`encoding_cliffords`.
:param bool as_dict: If ``True``, returns a dictionary from recovery
operators to syndromes that indicate that recovery.
"""
def error_to_pauli(error):
if error == p.I.as_clifford():
return "I"
if error == p.X.as_clifford():
return "X"
if error == p.Y.as_clifford():
return "Y"
if error == p.Z.as_clifford():
return "Z"
if for_enc is None:
encoder = self.encoding_cliffords().next()
else:
encoder = for_enc
decoder = encoder.inv()
errors = pc.PauliList(p.eye_p(self.nq)) + pc.PauliList(p.paulis_by_weight(self.nq, self.n_correctable))
syndrome_dict = defaultdict(lambda: Unspecified)
syndrome_meas = [p.elem_gen(self.nq, idx, 'Z') for idx in range(self.nq_logical, self.nq)]
for error in errors:
effective_gate = decoder * error.as_clifford() * encoder
# FIXME: the following line emulates measurement until we have a real
# measurement simulation method.
syndrome = tuple([effective_gate(meas).ph / 2 for meas in syndrome_meas])
recovery = "".join([
# FIXME: the following is a broken hack to get the phases on the logical qubit register.
error_to_pauli(c.Clifford([effective_gate.xout[idx][idx]], [effective_gate.zout[idx][idx]]))
for idx in range(self.nq_logical)
])
# For degenerate codes, the syndromes can collide, so long as we
# correct the same way for each.
if syndrome in syndrome_dict and syndrome_dict[syndrome] != recovery:
raise RuntimeError('Syndrome {} has collided.'.format(syndrome))
syndrome_dict[syndrome] = recovery
if as_dict:
outdict = dict()
keyfn = lambda (syndrome, recovery): recovery
data = sorted(syndrome_dict.items(), key=keyfn)
for recovery, syndrome_group in it.groupby(data, keyfn):
outdict[recovery] = [syn[0] for syn in syndrome_group]
return decoder, outdict
else:
recovery_list = pc.PauliList(syndrome_dict[syndrome] for syndrome in it.product(range(2), repeat=self.n_constraints))
return decoder, recovery_list