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
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()
def __init__(self): super(_One, self).__init__('ONE', farray([BDDONE]))
def __init__(self): super(_Xor, self).__init__('XOR', farray([X[0] ^ X[1]]))
def __init__(self): super(_Or, self).__init__('OR', farray([X[0] | X[1]]))
def __init__(self): super(_And, self).__init__('AND', farray([X[0] & X[1]]))
def __init__(self): super(_Nand, self).__init__('NAND', farray([~(X[0] & X[1])]))
def __init__(self): super(_Zero, self).__init__('ZERO', farray([BDDZERO]))
''' 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)
''' 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):