Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(18)  |  Call(16)  |  Derive(0)  |  Import(2)
Constructs a set of gate identities from the list of possible gates.

Performs a breadth first search over the space of gate identities.
This allows the finding of the shortest gate identities first.

Parameters
==========

gate_list : list, Gate
    A list of Gates from which to search for gate identities.(more...)

        def bfs_identity_search(gate_list, nqubits, max_depth=None,
       identity_only=False):
    """Constructs a set of gate identities from the list of possible gates.

    Performs a breadth first search over the space of gate identities.
    This allows the finding of the shortest gate identities first.

    Parameters
    ==========

    gate_list : list, Gate
        A list of Gates from which to search for gate identities.
    nqubits : int
        The number of qubits the quantum circuit operates on.
    max_depth : int
        The longest quantum circuit to construct from gate_list.
    identity_only : bool
        True to search for gate identities that reduce to identity;
        False to search for gate identities that reduce to a scalar.

    Examples
    ========

    Find a list of gate identities:

    >>> from sympy.physics.quantum.identitysearch import bfs_identity_search
    >>> from sympy.physics.quantum.gate import X, Y, Z, H
    >>> x = X(0); y = Y(0); z = Z(0)
    >>> bfs_identity_search([x], 1, max_depth=2)
    set([GateIdentity(X(0), X(0))])

    >>> bfs_identity_search([x, y, z], 1)
    set([GateIdentity(X(0), X(0)), GateIdentity(Y(0), Y(0)),
         GateIdentity(Z(0), Z(0)), GateIdentity(X(0), Y(0), Z(0))])

    Find a list of identities that only equal to 1:

    >>> bfs_identity_search([x, y, z], 1, identity_only=True)
    set([GateIdentity(X(0), X(0)), GateIdentity(Y(0), Y(0)),
         GateIdentity(Z(0), Z(0))])
    """

    if max_depth is None or max_depth <= 0:
        max_depth = len(gate_list)

    id_only = identity_only

    # Start with an empty sequence (implicitly contains an IdentityGate)
    queue = deque([()])

    # Create an empty set of gate identities
    ids = set()

    # Begin searching for gate identities in given space.
    while (len(queue) > 0):
        current_circuit = queue.popleft()

        for next_gate in gate_list:
            new_circuit = current_circuit + (next_gate,)

            # Determines if a (strict) subcircuit is a scalar matrix
            circuit_reducible = is_reducible(new_circuit, nqubits,
                                             1, len(new_circuit))

            # In many cases when the matrix is a scalar value,
            # the evaluated matrix will actually be an integer
            if (is_scalar_matrix(new_circuit, nqubits, id_only) and
                not is_degenerate(ids, new_circuit) and
                    not circuit_reducible):
                ids.add(GateIdentity(*new_circuit))

            elif (len(new_circuit) < max_depth and
                  not circuit_reducible):
                queue.append(new_circuit)

    return ids
        


src/s/y/sympy-HEAD/sympy/physics/quantum/tests/test_identitysearch.py   sympy(Download)
from sympy.physics.quantum.gate import (X, Y, Z, H, S, T, CNOT,
        IdentityGate, CGate, PhaseGate, TGate, gate_simp)
from sympy.physics.quantum.identitysearch import (generate_gate_rules,
        generate_equivalent_ids, GateIdentity, bfs_identity_search,
        random_identity_search, is_scalar_sparse_matrix,
def test_bfs_identity_search():
    assert bfs_identity_search([], 1) == set()
 
    (x, y, z, h) = create_gate_sequence()
 
    gate_list = [x]
    id_set = set([GateIdentity(x, x)])
    assert bfs_identity_search(gate_list, 1, max_depth=2) == id_set
                  GateIdentity(z, z),
                  GateIdentity(x, y, z)])
    assert bfs_identity_search(gate_list, 1) == id_set
 
    id_set = set([GateIdentity(x, x),
                  GateIdentity(x, z, x, z),
                  GateIdentity(y, z, y, z)])
    assert bfs_identity_search(gate_list, 1, max_depth=4) == id_set
    assert bfs_identity_search(gate_list, 1, max_depth=5) == id_set
 

src/s/y/sympy-HEAD/sympy/physics/quantum/tests/test_circuitutils.py   sympy(Download)
from sympy import Symbol, Integer, Mul
from sympy.utilities import numbered_symbols
from sympy.physics.quantum.gate import (X, Y, Z, H, S, T, CNOT,
        CGate)
from sympy.physics.quantum.identitysearch import bfs_identity_search
 
    gate_list = [x, y, z]
    ids = list(bfs_identity_search(gate_list, 1, max_depth=4))
 
    circuit = (x, y, h, z, cnot)
 
    gate_list = [x, y, z, h, cnot, cgate_z]
    ids = list(bfs_identity_search(gate_list, 2, max_depth=4))
 
    seq = [25]
 
    gate_list = [x, y, z, h, cnot, cgate_z]
    ids = list(bfs_identity_search(gate_list, 2, max_depth=4))
 
    eq_ids = flatten_ids(ids)