本文整理匯總了Python中PauliClass.ensure_pauli方法的典型用法代碼示例。如果您正苦於以下問題:Python PauliClass.ensure_pauli方法的具體用法?Python PauliClass.ensure_pauli怎麽用?Python PauliClass.ensure_pauli使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PauliClass
的用法示例。
在下文中一共展示了PauliClass.ensure_pauli方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: flip_code
# 需要導入模塊: import PauliClass [as 別名]
# 或者: from PauliClass import ensure_pauli [as 別名]
def flip_code(n_correctable, stab_kind='Z'):
"""
Creates an instance of :class:`qecc.StabilizerCode` representing a
code that protects against weight-``n_correctable`` flip errors of a
single kind.
This method generalizes the bit-flip and phase-flip codes, corresponding
to ``stab_kind=qecc.Z`` and ``stab_kind=qecc.X``, respectively.
:param int n_correctable: Maximum weight of the errors that can be
corrected by this code.
:param qecc.Pauli stab_kind: Single-qubit Pauli operator specifying
which kind of operators to use for the new stabilizer code.
:rtype: qecc.StabilizerCode
"""
nq = 2 * n_correctable + 1
stab_kind = p.ensure_pauli(stab_kind)
if len(stab_kind) != 1:
raise ValueError("stab_kind must be single-qubit.")
return StabilizerCode(
[p.eye_p(j) & stab_kind & stab_kind & p.eye_p(nq-j-2) for j in range(nq-1)],
['X'*nq], ['Z'*nq],
label='{}-flip code (t = {})'.format(stab_kind.op, n_correctable)
)