Пример #1
0
def make_random_one_inp_and_const_inp_gate(L, ultimate_level, penultimate_level,
                                           gate_name, circuit, gate_factory):
    """creates a random gate with one input and a constant that is an input
    batch."""
    # This gate requires one input; at least one input should be available.
    assert(len(ultimate_level) + len(penultimate_level) > 0)
    input1_index = sr.randint(0, len(ultimate_level) - 1)
    input1 = ultimate_level[input1_index]
    const = ci.Input([ib.IBMBatch([int(sr.getrandbits(1))
                                   for inp_ind in xrange(L)])])
    return gate_factory(gate_name, input1, const, circuit)
 def test_get_depth(self):
     """
     Tests that the get_depth method returns the correct depth, as defined
     by IBM.
     """
     circuit = ic.IBMCircuit(10)
     w1 = iw.IBMInputWire("w1", circuit)
     w2 = iw.IBMInputWire("w2", circuit)
     const = ci.Input([ib.IBMBatch([1, 0, 1])])
     g1 = igs.IBMSelectGate("g1", w1, w2, const, circuit)
     self.assertEqual(.6, g1.get_depth())
 def test_get_full_display_string(self):
     """
     Tests that the method get_full_display_string returns the correct
     string.
     """
     #Initialize the circuit:
     circuit = ic.IBMCircuit(10)
     #Initialize the input wires:
     w1 = iw.IBMInputWire("w1", circuit)
     #Initialize the constant:
     const = ci.Input([ib.IBMBatch([True, False])])
     #Initialize the gate:
     g = igac.IBMAddConstGate("g", w1, const, circuit)
     self.assertEquals("g:LADDconst(w1,[10])", g.get_full_display_string())
 def test_get_full_display_string(self):
     """
     Tests that the method get_full_display_string returns the correct
     string.
     """
     #Initialize the circuit:
     circuit = ic.IBMCircuit(10)
     #Initialize the input wires:
     w1 = iw.IBMInputWire("w1", circuit)
     w2 = iw.IBMInputWire("w2", circuit)
     #Initialize the constant:
     const = ci.Input([ib.IBMBatch([1, 0])])
     #Initialize the gate:
     g = igs.IBMSelectGate("g", w1, w2, const, circuit)
     self.assertEquals(g.get_full_display_string(), "g:LSELECT(w1,w2,[10])")
Пример #5
0
def make_random_two_inp_and_const_inp_gate(L, ultimate_level, penultimate_level,
                                           gate_name, circuit, gate_factory):
    """creats a random gate with two inputs and a constant that is an input
    batch."""
    # This gate requires two inputs; at least two inputs should be available.
    assert(len(ultimate_level) + len(penultimate_level) > 1)
    input1_index = sr.randint(0, len(ultimate_level) - 1)
    input1 = ultimate_level[input1_index]
    input2_index = sr.randint(0, len(ultimate_level) +
                              len(penultimate_level) - 1)
    while input2_index == input1_index:
        input2_index = sr.randint(0, len(ultimate_level) +
                                  len(penultimate_level) - 1)
    if input2_index < len(ultimate_level):
        input2 = ultimate_level[input2_index]
    else:
        input2 = penultimate_level[input2_index - len(ultimate_level)]
    const = ci.Input([ib.IBMBatch([int(sr.getrandbits(1))
                                   for inp_ind in xrange(L)])])
    return gate_factory(gate_name, input1, input2, const, circuit)
Пример #6
0
def make_random_input(L, W, B):
    """Creates a random input with W batches, each with L bits."""
    return ci.Input([
        ib.IBMBatch([int(sr.randint(0, B)) for inp_num in xrange(L)])
        for batch_num in xrange(W)
    ])
def make_random_input(W):
    """Returns an array of W random bits."""
    # TODO: this can probably be made to run faster by generating all W random
    # bits at once.
    return si.Input([int(sr.getrandbits(1)) for inp_num in xrange(W)])