Skip to content

Commit

Permalink
Added instantiation of wires and buses from inputs. Hopefully fixed now.
Browse files Browse the repository at this point in the history
  • Loading branch information
honzastor committed Mar 27, 2024
1 parent cd3441f commit da733cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
24 changes: 15 additions & 9 deletions ariths_gen/core/arithmetic_circuits/general_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,22 @@ def __init__(self, prefix: str, name: str, out_N: int, inner_component: bool = F
self.inputs = []
input_names = "abcdefghijklmnopqrstuvwxyz" # This should be enough..
assert len(input_names) >= len(inputs)
for i, input_bus in enumerate(inputs):
for i, input in enumerate(inputs):
attr_name = input_names[i]
full_prefix = f"{self.prefix}_{input_bus.prefix}" if self.inner_component else f"{input_bus.prefix}"
bus = Bus(prefix=full_prefix, wires_list=input_bus.bus)
setattr(self, attr_name, bus)
self.inputs.append(bus)

# If the input bus is an output bus, connect it
if input_bus.is_output_bus():
getattr(self, attr_name).connect_bus(connecting_bus=input_bus)
full_prefix = f"{self.prefix}_{input.prefix}" if self.inner_component else f"{input.prefix}"
if isinstance(input, Bus):
bus = Bus(prefix=full_prefix, wires_list=input.bus)
setattr(self, attr_name, bus)
self.inputs.append(bus)

# If the input bus is an output bus, connect it
if input.is_output_bus():
getattr(self, attr_name).connect_bus(connecting_bus=input)
else:
wire = Wire(name=input.name, prefix=full_prefix)
setattr(self, attr_name, wire)
self.inputs.append(wire)

else:
self.inputs = inputs

Expand Down
4 changes: 3 additions & 1 deletion tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def __init__(self, a: Bus, b: Bus, r: Bus, prefix: str = "", name: str = "mac",

def test_direct():
class err_circuit(GeneralCircuit):
def __init__(self, prefix: str = "", name: str = "adder", inner_component: bool = True, a: Bus = Bus(), b: Bus = Bus()):
def __init__(self, a: Bus = Bus(), b: Bus = Bus(), prefix: str = "", name: str = "adder", inner_component: bool = False):
super().__init__(prefix=prefix, name=name, out_N=(a.N + 1), inner_component=inner_component, inputs=[a, b])
self.N = 1
self.prefix = prefix
Expand Down Expand Up @@ -389,4 +389,6 @@ def __init__(self, a: Wire, b: Wire, c: Bus, prefix="test_circuit", **kwargs):
test_unsigned_add()
test_signed_add()
test_mac()
test_direct()
test_wire_as_bus()
print("Python tests were successful!")

0 comments on commit da733cf

Please sign in to comment.