Exemplo n.º 1
0
    def combined_with(self, other):
        '''
        Combine with another `Technology` instance and return the resulting,
        new tech. Note that this operation is NOT commutative. In other words,
        `a.combined_with(b)` does NOT do the same thing as
        `b.combined_with(a)`, even if you set the PRNG seed.

        :param other: another technology with which to combine
        '''
        other_exprs = list(other.circuit)
        for other_input in other.inputs():
            if random() < INPUT_PROBABILITY:
                continue
            self_output = choice(self.circuit)
            other_exprs = [
                expr.compose({other_input: self_output})
                for expr in other_exprs
            ]
        self_exprs = list(self.circuit)

        new_name = '({} + {})'.format(
            self.name, other.name)  # TODO Come up with name algorithm
        new_circuit = farray(self_exprs + other_exprs)
        new_cost = self.cost + other.cost  # FIXME Compute cost according to A&P

        return Technology(new_name, new_circuit, new_cost)
 def do_original_net(self, file_org):
     self.netlist.clear()
     self.outputs = []  #output list
     self.inputs = []  #input list
     with open(dirConst + '/' + file_org) as f:
         for line in f:
             self.parser(line)
     #map all gates to output line
     tmp_lst = []
     for i, item in enumerate(self.outputs):
         if (self.netlist.get(item, None) is not None):
             #if the wire is coming from other gate
             tmp_lst.append(self.netlist.get(item, None))
     self.yd = pyedaitr.farray([x for x in tmp_lst])
     self.nosips = len(self.inputs)
     # print("-------------------------netlist-------------------------")
     # print(self.netlist)
     # print("-------------------------inputs -------------------------")
     # print(self.inputs)
     # print("-------------------------output -------------------------")
     self.IpO = self.Ip
Exemplo n.º 3
0
    def combined_with(self, other):
        '''
        Combine with another `Technology` instance and return the resulting,
        new tech. Note that this operation is NOT commutative. In other words,
        `a.combined_with(b)` does NOT do the same thing as
        `b.combined_with(a)`, even if you set the PRNG seed.

        :param other: another technology with which to combine
        '''
        other_exprs = list(other.circuit)
        for other_input in other.inputs():
            if random() < INPUT_PROBABILITY:
                continue
            self_output = choice(self.circuit)
            other_exprs = [expr.compose({other_input: self_output}) for expr in other_exprs]
        self_exprs = list(self.circuit)

        new_name = '({} + {})'.format(self.name, other.name) # TODO Come up with name algorithm
        new_circuit = farray(self_exprs + other_exprs)
        new_cost = self.cost + other.cost # FIXME Compute cost according to A&P

        return Technology(new_name, new_circuit, new_cost)
 def do_mitter_net(self, file_enc):
     self.netlist.clear()
     self.outputs = []  #output list
     self.inputs = []  #input list
     with open(dirConst + '/' + file_enc) as f:
         for line in f:
             self.parser(line)
     #map all gates to output line
     tmp_lst = []
     for i, item in enumerate(self.outputs):
         if (self.netlist.get(item, None) is not None):
             #if the wire is coming from other gate
             tmp_lst.append(self.netlist.get(item, None))
     self.y1 = pyedaitr.farray([x for x in tmp_lst])
     # print("-------------------------netlist-------------------------")
     # print(self.netlist)
     # print("-------------------------inputs -------------------------")
     # print(self.inputs)
     # print("-------------------------output -------------------------")
     self.y2 = self.y1
     self.IpE = self.Ip
     self.KeyIpE = self.KeyIp
     self.noskeys = self.get_nokeys()
Exemplo n.º 5
0
 def __init__(self):
     super(_One, self).__init__('ONE', farray([BDDONE]))
Exemplo n.º 6
0
 def __init__(self):
     super(_Xor, self).__init__('XOR', farray([X[0] ^ X[1]]))
Exemplo n.º 7
0
 def __init__(self):
     super(_Or, self).__init__('OR', farray([X[0] | X[1]]))
Exemplo n.º 8
0
 def __init__(self):
     super(_And, self).__init__('AND', farray([X[0] & X[1]]))
Exemplo n.º 9
0
 def __init__(self):
     super(_Nand, self).__init__('NAND', farray([~(X[0] & X[1])]))
Exemplo n.º 10
0
 def __init__(self):
     super(_Zero, self).__init__('ZERO', farray([BDDZERO]))
Exemplo n.º 11
0
 def __init__(self):
     super(_Xor, self).__init__('XOR', farray([X[0] ^ X[1]]))
Exemplo n.º 12
0
 def __init__(self):
     super(_Or, self).__init__('OR', farray([X[0] | X[1]]))
Exemplo n.º 13
0
 def __init__(self):
     super(_And, self).__init__('AND', farray([X[0] & X[1]]))
Exemplo n.º 14
0
 def __init__(self):
     super(_Nand, self).__init__('NAND', farray([~(X[0] & X[1])]))
Exemplo n.º 15
0
 def __init__(self):
     super(_Zero, self).__init__('ZERO', farray([BDDZERO]))
Exemplo n.º 16
0
 def __init__(self):
     super(_One, self).__init__('ONE', farray([BDDONE]))
Exemplo n.º 17
0
'''
Tests for the `Technology` class.
'''
import unittest
from pyeda.inter import farray
from circuits.technology import Technology
from circuits.variables import *
from circuits.primitives import *


TECH1_NAME = 'FIRST'
TECH1_CIRCUIT = farray([X[0] & X[1] & X[2]])
TECH1_COST = 0
TECH1_VARS = {X[0], X[1], X[2]}
TECH2_NAME = 'SECOND'
TECH2_CIRCUIT = farray([X[0] | X[1] | X[2]])
TECH2_COST = 1
TECH2_VARS = {X[0], X[1], X[2]}


class TestTechnology(unittest.TestCase):
    def setUp(self):
        self.t1 = Technology(TECH1_NAME, TECH1_CIRCUIT, TECH1_COST)
        self.t2 = Technology(TECH2_NAME, TECH2_CIRCUIT, TECH2_COST)

    def test_creation(self):
        self.assertEqual(self.t1.name, TECH1_NAME)
        self.assertEqual(self.t1.cost, TECH1_COST)
        self.assertEqual(self.t2.name, TECH2_NAME)
        self.assertEqual(self.t2.cost, TECH2_COST)
Exemplo n.º 18
0
'''
Tests for the `Technology` class.
'''
import unittest
from pyeda.inter import farray
from circuits.technology import Technology
from circuits.variables import *
from circuits.primitives import *

TECH1_NAME = 'FIRST'
TECH1_CIRCUIT = farray([X[0] & X[1] & X[2]])
TECH1_COST = 0
TECH1_VARS = {X[0], X[1], X[2]}
TECH2_NAME = 'SECOND'
TECH2_CIRCUIT = farray([X[0] | X[1] | X[2]])
TECH2_COST = 1
TECH2_VARS = {X[0], X[1], X[2]}


class TestTechnology(unittest.TestCase):
    def setUp(self):
        self.t1 = Technology(TECH1_NAME, TECH1_CIRCUIT, TECH1_COST)
        self.t2 = Technology(TECH2_NAME, TECH2_CIRCUIT, TECH2_COST)

    def test_creation(self):
        self.assertEqual(self.t1.name, TECH1_NAME)
        self.assertEqual(self.t1.cost, TECH1_COST)
        self.assertEqual(self.t2.name, TECH2_NAME)
        self.assertEqual(self.t2.cost, TECH2_COST)

    def test_satisfies(self):