本文整理汇总了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)
)