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

All Samples(5)  |  Call(4)  |  Derive(0)  |  Import(1)
Insert a circuit into another quantum circuit.

random_insert randomly chooses a location in the circuit to insert
a randomly selected circuit from amongst the given choices.

Parameters
==========

circuit : Gate tuple or Mul
    A tuple or Mul of Gates representing a quantum circuit(more...)

        def random_insert(circuit, choices, seed=None):
    """Insert a circuit into another quantum circuit.

    random_insert randomly chooses a location in the circuit to insert
    a randomly selected circuit from amongst the given choices.

    Parameters
    ==========

    circuit : Gate tuple or Mul
        A tuple or Mul of Gates representing a quantum circuit
    choices : list
        Set of circuit choices
    seed : int or list
        seed used for _randrange; to override the random selections, give
        a list two integers, [i, j] where i is the circuit location where
        choice[j] will be inserted.

    Notes
    =====

    Indices for insertion should be [0, n] if n is the length of the
    circuit.
    """
    from sympy.utilities.randtest import _randrange

    if not choices:
        return circuit

    if isinstance(circuit, Mul):
        circuit = circuit.args

    # get the location in the circuit and the element to insert from choices
    randrange = _randrange(seed)
    loc = randrange(len(circuit) + 1)
    choice = choices[randrange(len(choices))]

    circuit = list(circuit)
    circuit[loc: loc] = choice
    return tuple(circuit)
        


src/s/y/sympy-HEAD/sympy/physics/quantum/tests/test_circuitutils.py   sympy(Download)
        CGate)
from sympy.physics.quantum.identitysearch import bfs_identity_search
from sympy.physics.quantum.circuitutils import (kmp_table, find_subcircuit,
        replace_subcircuit, convert_to_symbolic_indices,
        convert_to_real_indices, random_reduce, random_insert,
    circuit = (y, y)
    loc, choice = 0, 0
    actual = random_insert(circuit, choices, seed=[loc, choice])
    assert actual == (x, x, y, y)
 
    circuit = (x, y, z, h)
    choices = [(h, h), (x, y, z)]
    expected = (x, x, y, z, y, z, h)
    loc, choice = 1, 1
    actual = random_insert(circuit, choices, seed=[loc, choice])
    expected = (x, z, x, z, x, y, h, cnot, cgate_z)
    loc, choice = 1, 30
    actual = random_insert(circuit, eq_ids, seed=[loc, choice])
    assert actual == expected
    circuit = Mul(*circuit)
    actual = random_insert(circuit, eq_ids, seed=[loc, choice])