当前位置: 首页>>代码示例>>Python>>正文


Python PauliClass.com方法代码示例

本文整理汇总了Python中PauliClass.com方法的典型用法代码示例。如果您正苦于以下问题:Python PauliClass.com方法的具体用法?Python PauliClass.com怎么用?Python PauliClass.com使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PauliClass的用法示例。


在下文中一共展示了PauliClass.com方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: solve_commutation_constraints

# 需要导入模块: import PauliClass [as 别名]
# 或者: from PauliClass import com [as 别名]
def solve_commutation_constraints(
        commutation_constraints=[],
        anticommutation_constraints=[],
        search_in_gens=None,
        search_in_set=None
    ):
    r"""
    Given commutation constraints on a Pauli operator, yields an iterator onto
    all solutions of those constraints.
    
    :param commutation_constraints: A list of operators :math:`\{A_i\}` such
        that each solution :math:`P` yielded by this function must satisfy
        :math:`[A_i, P] = 0` for all :math:`i`.
    :param anticommutation_constraints: A list of operators :math:`\{B_i\}` such
        that each solution :math:`P` yielded by this function must satisfy
        :math:`\{B_i, P\} = 0` for all :math:`i`.
    :param search_in_gens: A list of operators :math:`\{N_i\}` that generate
        the group in which to search for solutions. If ``None``, defaults to
        the elementary generators of the pc.Pauli group on :math:`n` qubits, where
        :math:`n` is given by the length of the commutation and anticommutation
        constraints.
    :param search_in_set: An iterable of operators to which the search for 
        satisfying assignments is restricted. This differs from ``search_in_gens``
        in that it specifies the entire set, not a generating set. When this
        parameter is specified, a brute-force search is executed. Use only
        when the search set is small, and cannot be expressed using its generating
        set. 
    :returns: An iterator ``it`` such that ``list(it)`` contains all operators
        within the group :math:`G = \langle N_1, \dots, N_k \rangle`
        given by ``search_in_gens``, consistent with the commutation and
        anticommutation constraints.
        
    This function is based on finding the generators of the centralizer groups 
    of each commutation constraint, and is thus faster than a predicate-based
    search over the entire group of interest. The resulting iterator can be
    used in conjunction with other filters, however.
    
    >>> import qecc as q
    >>> list(q.solve_commutation_constraints(q.PauliList('XXI', 'IZZ', 'IYI'), q.PauliList('YIY')))
    [i^0 XII, i^0 IIZ, i^0 YYX, i^0 ZYY]
    >>> from itertools import ifilter
    >>> list(ifilter(lambda P: P.wt <= 2, q.solve_commutation_constraints(q.PauliList('XXI', 'IZZ', 'IYI'), q.PauliList('YIY'))))
    [i^0 XII, i^0 IIZ]
    """
        
    # Normalize our arguments to be PauliLists, so that we can obtain
    # centralizers easily.
    if not isinstance(commutation_constraints, PauliList):
        commutation_constraints = PauliList(commutation_constraints)
    if not isinstance(anticommutation_constraints, PauliList):
        # This is probably not necessary, strictly speaking, but it keeps me
        # slightly more sane to have both constraints represented by the same
        # sequence type.
        anticommutation_constraints = PauliList(anticommutation_constraints)

    # Then check that the arguments make sense.
    if len(commutation_constraints) == 0 and len(anticommutation_constraints) == 0:

        raise ValueError("At least one constraint must be specified.")

    #We default to executing a brute-force search if the search set is
    #explicitly specified:
    if search_in_set is not None:
        commutation_predicate = AllPredicate(*map(
            lambda acc: (lambda P: pc.com(P, acc) == 0),
            commutation_constraints
            ))
        commuters = filter(commutation_predicate, search_in_set)
        anticommutation_predicate = AllPredicate(*map(
            lambda acc: (lambda P: pc.com(P, acc) == 1),
            anticommutation_constraints
            ))
        return filter(anticommutation_predicate, commuters)

    # We finish putting arguments in the right form by defaulting to searching
    # over the pc.Pauli group on $n$ qubits.
    if search_in_gens is None:
        nq = len(commutation_constraints[0] if len(commutation_constraints) > 0 else anticommutation_constraints[0])
        Xs, Zs = pc.elem_gens(nq)
        search_in_gens = Xs + Zs
    
    # Now we update our search by restricting to the centralizer of the
    # commutation constraints.
    search_in_gens = commutation_constraints.centralizer_gens(group_gens=search_in_gens)
    
    # Finally, we return a filter iterator on the elements of the given
    # centralizer that selects elements which anticommute appropriately.
    anticommutation_predicate = AllPredicate(*map(
        lambda acc: (lambda P: pc.com(P, acc) == 1),
        anticommutation_constraints
        ))
    assert len(search_in_gens) > 0
    return ifilter(anticommutation_predicate, pc.from_generators(search_in_gens))
开发者ID:Roger-luo,项目名称:python-quaec,代码行数:95,代码来源:constraint_solvers.py

示例2: pred_fn

# 需要导入模块: import PauliClass [as 别名]
# 或者: from PauliClass import com [as 别名]
 def pred_fn(P):
     # Using imap here instead of map allows all() to short-circuit.
     return all(it.imap(lambda Q: pc.com(P, Q) == 0, paulis))
开发者ID:cgranade,项目名称:python-quaec,代码行数:5,代码来源:pred.py


注:本文中的PauliClass.com方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。