diff --git a/src/faebryk/core/util.py b/src/faebryk/core/util.py index 946512d9..93eac605 100644 --- a/src/faebryk/core/util.py +++ b/src/faebryk/core/util.py @@ -224,12 +224,10 @@ def get_direct_connected_nodes[T: Node]( def get_net(mif: F.Electrical): - from faebryk.library.Net import Net - nets = { net for mif in get_connected_mifs(mif.connected) - if (net := get_parent_of_type(mif, Net)) is not None + if (net := get_parent_of_type(mif, F.Net)) is not None } if not nets: @@ -323,12 +321,10 @@ def get_param_tree(param: Parameter) -> list[tuple[Parameter, list]]: def connect_interfaces_via_chain( start: ModuleInterface, bridges: Iterable[Node], end: ModuleInterface, linkcls=None ): - from faebryk.library.can_bridge import can_bridge - last = start for bridge in bridges: - last.connect(bridge.get_trait(can_bridge).get_in(), linkcls=linkcls) - last = bridge.get_trait(can_bridge).get_out() + last.connect(bridge.get_trait(F.can_bridge).get_in(), linkcls=linkcls) + last = bridge.get_trait(F.can_bridge).get_out() last.connect(end, linkcls=linkcls) @@ -375,13 +371,11 @@ def connect_module_mifs_by_name( def reversed_bridge(bridge: Node): - from faebryk.library.can_bridge import can_bridge - class _reversed_bridge(Node): def __init__(self) -> None: super().__init__() - bridge_trait = bridge.get_trait(can_bridge) + bridge_trait = bridge.get_trait(F.can_bridge) if_in = bridge_trait.get_in() if_out = bridge_trait.get_out() @@ -565,8 +559,6 @@ def pretty_param_tree_top(param: Parameter) -> str: def use_interface_names_as_net_names(node: Node, name: str | None = None): - from faebryk.library.Net import Net - if not name: p = node.get_parent() assert p @@ -597,7 +589,7 @@ def use_interface_names_as_net_names(node: Node, name: str | None = None): n for c in connections if (p := c.get_parent()) - and isinstance(n := p[0], Net) + and isinstance(n := p[0], F.Net) and n.part_of in connections }: # logger.warning(f"Skipped, attached to Net: {el_if}: {matched_nets!r}") @@ -617,7 +609,7 @@ def use_interface_names_as_net_names(node: Node, name: str | None = None): # performance resolved.update(group) - nets: dict[str, tuple[Net, F.Electrical]] = {} + nets: dict[str, tuple[F.Net, F.Electrical]] = {} for el_if in to_use: net_name = f"{name}{el_if.get_full_name().removeprefix(name_prefix)}" @@ -635,7 +627,7 @@ def use_interface_names_as_net_names(node: Node, name: str | None = None): + "\n\t".join(map(str, net.part_of.get_direct_connections())) ) - net = Net() + net = F.Net() net.add_trait(F.has_overriden_name_defined(net_name)) net.part_of.connect(el_if) logger.debug(f"Created {net_name} for {el_if}") diff --git a/src/faebryk/exporters/netlist/netlist.py b/src/faebryk/exporters/netlist/netlist.py index 0e7d77cd..1e39a40c 100644 --- a/src/faebryk/exporters/netlist/netlist.py +++ b/src/faebryk/exporters/netlist/netlist.py @@ -38,9 +38,8 @@ class Vertex: def make_t2_netlist_from_graph(G: Graph) -> T2Netlist: from faebryk.core.util import get_all_nodes_of_type, get_all_nodes_with_trait from faebryk.exporters.netlist.graph import can_represent_kicad_footprint - from faebryk.library.Net import Net as FNet - nets = get_all_nodes_of_type(G, FNet) + nets = get_all_nodes_of_type(G, F.Net) t2_nets = [ T2Netlist.Net( diff --git a/src/faebryk/exporters/pcb/layout/heuristic_pulls.py b/src/faebryk/exporters/pcb/layout/heuristic_pulls.py index 17df93ac..1fb57885 100644 --- a/src/faebryk/exporters/pcb/layout/heuristic_pulls.py +++ b/src/faebryk/exporters/pcb/layout/heuristic_pulls.py @@ -21,8 +21,6 @@ def __init__(self, params: Params | None = None): def apply(self, *node: Node): from faebryk.core.util import get_parent_of_type - from faebryk.library.ElectricLogic import ElectricLogic - from faebryk.library.Resistor import Resistor # Remove nodes that have a position defined node = tuple( @@ -32,8 +30,8 @@ def apply(self, *node: Node): ) for n in node: - assert isinstance(n, Resistor) - logic = NotNone(get_parent_of_type(n, ElectricLogic)) + assert isinstance(n, F.Resistor) + logic = NotNone(get_parent_of_type(n, F.ElectricLogic)) place_next_to(logic.signal, n, route=True, params=self._params) diff --git a/src/faebryk/libs/app/erc.py b/src/faebryk/libs/app/erc.py index c182e9d1..85b68f69 100644 --- a/src/faebryk/libs/app/erc.py +++ b/src/faebryk/libs/app/erc.py @@ -56,29 +56,23 @@ def simple_erc(G: Graph): Returns: """ - from faebryk.library.Capacitor import Capacitor - from faebryk.library.ElectricPower import ElectricPower - from faebryk.library.Fuse import Fuse - from faebryk.library.Net import Net - from faebryk.library.Resistor import Resistor - logger.info("Checking graph for ERC violations") # power short - electricpower = get_all_nodes_of_type(G, ElectricPower) + electricpower = get_all_nodes_of_type(G, F.ElectricPower) logger.info(f"Checking {len(electricpower)} Power") for ep in electricpower: if ep.lv.is_connected_to(ep.hv): raise ERCFaultShort([ep], "shorted power") # shorted nets - nets = get_all_nodes_of_type(G, Net) + nets = get_all_nodes_of_type(G, F.Net) logger.info(f"Checking {len(nets)} nets") for net in nets: collisions = { p[0] for mif in net.part_of.get_direct_connections() - if (p := mif.get_parent()) and isinstance(p[0], Net) + if (p := mif.get_parent()) and isinstance(p[0], F.Net) } if collisions: @@ -113,9 +107,9 @@ def simple_erc(G: Graph): # checked.add(mif) # if any(mif.is_connected_to(other) for other in (mifs - checked)): # raise ERCFault([mif], "shorted symmetric footprint") - comps = get_all_nodes_of_types(G, (Resistor, Capacitor, Fuse)) + comps = get_all_nodes_of_types(G, (F.Resistor, F.Capacitor, F.Fuse)) for comp in comps: - assert isinstance(comp, (Resistor, Capacitor, Fuse)) + assert isinstance(comp, (F.Resistor, F.Capacitor, F.Fuse)) # TODO make prettier if ( comp.has_trait(has_part_picked) diff --git a/src/faebryk/libs/examples/pickers.py b/src/faebryk/libs/examples/pickers.py index f30b10d1..6cfa705e 100644 --- a/src/faebryk/libs/examples/pickers.py +++ b/src/faebryk/libs/examples/pickers.py @@ -11,7 +11,6 @@ import faebryk.library._F as F from faebryk.core.module import Module from faebryk.core.util import specialize_module -from faebryk.library._F import Constant, Range from faebryk.libs.app.parameters import replace_tbd_with_any from faebryk.libs.picker.lcsc import LCSC_Part from faebryk.libs.picker.picker import PickerOption, pick_module_by_params @@ -30,17 +29,17 @@ def pick_fuse(module: F.Fuse): PickerOption( part=LCSC_Part(partno="C914087"), params={ - "fuse_type": Constant(F.Fuse.FuseType.RESETTABLE), - "response_type": Constant(F.Fuse.ResponseType.SLOW), - "trip_current": Constant(1 * P.A), + "fuse_type": F.Constant(F.Fuse.FuseType.RESETTABLE), + "response_type": F.Constant(F.Fuse.ResponseType.SLOW), + "trip_current": F.Constant(1 * P.A), }, ), PickerOption( part=LCSC_Part(partno="C914085"), params={ - "fuse_type": Constant(F.Fuse.FuseType.RESETTABLE), - "response_type": Constant(F.Fuse.ResponseType.SLOW), - "trip_current": Constant(0.5 * P.A), + "fuse_type": F.Constant(F.Fuse.FuseType.RESETTABLE), + "response_type": F.Constant(F.Fuse.ResponseType.SLOW), + "trip_current": F.Constant(0.5 * P.A), }, ), ], @@ -59,14 +58,14 @@ def pick_mosfet(module: F.MOSFET): PickerOption( part=LCSC_Part(partno="C20917"), params={ - "channel_type": Constant(F.MOSFET.ChannelType.N_CHANNEL), + "channel_type": F.Constant(F.MOSFET.ChannelType.N_CHANNEL), }, pinmap=standard_pinmap, ), PickerOption( part=LCSC_Part(partno="C15127"), params={ - "channel_type": Constant(F.MOSFET.ChannelType.P_CHANNEL), + "channel_type": F.Constant(F.MOSFET.ChannelType.P_CHANNEL), }, pinmap=standard_pinmap, ), @@ -87,23 +86,23 @@ def pick_capacitor(module: F.Capacitor): PickerOption( part=LCSC_Part(partno="C1525"), params={ - "temperature_coefficient": Range( + "temperature_coefficient": F.Range( F.Capacitor.TemperatureCoefficient.Y5V, F.Capacitor.TemperatureCoefficient.X7R, ), - "capacitance": Constant(100 * P.nF), - "rated_voltage": Range(0 * P.V, 16 * P.V), + "capacitance": F.Constant(100 * P.nF), + "rated_voltage": F.Range(0 * P.V, 16 * P.V), }, ), PickerOption( part=LCSC_Part(partno="C19702"), params={ - "temperature_coefficient": Range( + "temperature_coefficient": F.Range( F.Capacitor.TemperatureCoefficient.Y5V, F.Capacitor.TemperatureCoefficient.X7R, ), - "capacitance": Constant(10 * P.uF), - "rated_voltage": Range(0 * P.V, 10 * P.V), + "capacitance": F.Constant(10 * P.uF), + "rated_voltage": F.Range(0 * P.V, 10 * P.V), }, ), ], @@ -122,59 +121,59 @@ def pick_resistor(resistor: F.Resistor): [ PickerOption( part=LCSC_Part(partno="C25111"), - params={"resistance": Constant(40.2 * P.kohm)}, + params={"resistance": F.Constant(40.2 * P.kohm)}, ), PickerOption( part=LCSC_Part(partno="C25076"), - params={"resistance": Constant(100 * P.kohm)}, + params={"resistance": F.Constant(100 * P.kohm)}, ), PickerOption( part=LCSC_Part(partno="C25087"), - params={"resistance": Constant(200 * P.kohm)}, + params={"resistance": F.Constant(200 * P.kohm)}, ), PickerOption( part=LCSC_Part(partno="C11702"), - params={"resistance": Constant(1 * P.kohm)}, + params={"resistance": F.Constant(1 * P.kohm)}, ), PickerOption( part=LCSC_Part(partno="C25879"), - params={"resistance": Constant(2.2 * P.kohm)}, + params={"resistance": F.Constant(2.2 * P.kohm)}, ), PickerOption( part=LCSC_Part(partno="C25900"), - params={"resistance": Constant(4.7 * P.kohm)}, + params={"resistance": F.Constant(4.7 * P.kohm)}, ), PickerOption( part=LCSC_Part(partno="C25905"), - params={"resistance": Constant(5.1 * P.kohm)}, + params={"resistance": F.Constant(5.1 * P.kohm)}, ), PickerOption( part=LCSC_Part(partno="C25917"), - params={"resistance": Constant(6.8 * P.kohm)}, + params={"resistance": F.Constant(6.8 * P.kohm)}, ), PickerOption( part=LCSC_Part(partno="C25744"), - params={"resistance": Constant(10 * P.kohm)}, + params={"resistance": F.Constant(10 * P.kohm)}, ), PickerOption( part=LCSC_Part(partno="C25752"), - params={"resistance": Constant(12 * P.kohm)}, + params={"resistance": F.Constant(12 * P.kohm)}, ), PickerOption( part=LCSC_Part(partno="C25771"), - params={"resistance": Constant(27 * P.kohm)}, + params={"resistance": F.Constant(27 * P.kohm)}, ), PickerOption( part=LCSC_Part(partno="C25741"), - params={"resistance": Constant(100 * P.kohm)}, + params={"resistance": F.Constant(100 * P.kohm)}, ), PickerOption( part=LCSC_Part(partno="C25782"), - params={"resistance": Constant(390 * P.kohm)}, + params={"resistance": F.Constant(390 * P.kohm)}, ), PickerOption( part=LCSC_Part(partno="C25790"), - params={"resistance": Constant(470 * P.kohm)}, + params={"resistance": F.Constant(470 * P.kohm)}, ), ], ) @@ -187,30 +186,30 @@ def pick_led(module: F.LED): PickerOption( part=LCSC_Part(partno="C72043"), params={ - "color": Constant(F.LED.Color.EMERALD), - "max_brightness": Constant(285 * P.mcandela), - "forward_voltage": Constant(3.7 * P.volt), - "max_current": Constant(100 * P.mA), + "color": F.Constant(F.LED.Color.EMERALD), + "max_brightness": F.Constant(285 * P.mcandela), + "forward_voltage": F.Constant(3.7 * P.volt), + "max_current": F.Constant(100 * P.mA), }, pinmap={"1": module.cathode, "2": module.anode}, ), PickerOption( part=LCSC_Part(partno="C72041"), params={ - "color": Constant(F.LED.Color.BLUE), - "max_brightness": Constant(28.5 * P.mcandela), - "forward_voltage": Constant(3.1 * P.volt), - "max_current": Constant(100 * P.mA), + "color": F.Constant(F.LED.Color.BLUE), + "max_brightness": F.Constant(28.5 * P.mcandela), + "forward_voltage": F.Constant(3.1 * P.volt), + "max_current": F.Constant(100 * P.mA), }, pinmap={"1": module.cathode, "2": module.anode}, ), PickerOption( part=LCSC_Part(partno="C72038"), params={ - "color": Constant(F.LED.Color.YELLOW), - "max_brightness": Constant(180 * P.mcandela), - "forward_voltage": Constant(2.3 * P.volt), - "max_current": Constant(60 * P.mA), + "color": F.Constant(F.LED.Color.YELLOW), + "max_brightness": F.Constant(180 * P.mcandela), + "forward_voltage": F.Constant(2.3 * P.volt), + "max_current": F.Constant(60 * P.mA), }, pinmap={"1": module.cathode, "2": module.anode}, ), @@ -225,7 +224,7 @@ def pick_tvs(module: F.TVS): PickerOption( part=LCSC_Part(partno="C85402"), params={ - "reverse_working_voltage": Constant(5 * P.V), + "reverse_working_voltage": F.Constant(5 * P.V), }, pinmap={ "1": module.cathode, @@ -252,11 +251,11 @@ def pick_battery(module: F.Battery): PickerOption( part=LCSC_Part(partno="C5239862"), params={ - "voltage": Constant(3 * P.V), - "capacity": Range.from_center(225 * P.mAh, 50 * P.mAh), - "material": Constant(F.ButtonCell.Material.Lithium), - "size": Constant(F.ButtonCell.Size.N_2032), - "shape": Constant(F.ButtonCell.Shape.Round), + "voltage": F.Constant(3 * P.V), + "capacity": F.Range.from_center(225 * P.mAh, 50 * P.mAh), + "material": F.Constant(F.ButtonCell.Material.Lithium), + "size": F.Constant(F.ButtonCell.Size.N_2032), + "shape": F.Constant(F.ButtonCell.Shape.Round), }, pinmap={ "1": module.power.lv, diff --git a/test/core/test_parameters.py b/test/core/test_parameters.py index 428d0f5b..fd8fbd9c 100644 --- a/test/core/test_parameters.py +++ b/test/core/test_parameters.py @@ -5,18 +5,11 @@ import unittest from operator import add +import faebryk.library._F as F from faebryk.core.core import logger as core_logger from faebryk.core.module import Module from faebryk.core.parameter import Parameter from faebryk.core.util import specialize_module -from faebryk.library.ANY import ANY -from faebryk.library.Constant import Constant -from faebryk.library.Operation import Operation -from faebryk.library.Range import Range -from faebryk.library.Resistor import Resistor -from faebryk.library.Set import Set -from faebryk.library.TBD import TBD -from faebryk.library.UART_Base import UART_Base from faebryk.libs.units import P logger = logging.getLogger(__name__) @@ -32,106 +25,112 @@ def assertIsInstance[T: Parameter](obj: Parameter, cls: type[T]) -> T: return obj # Constant - ONE = Constant(1) + ONE = F.Constant(1) self.assertEqual(ONE.value, 1) - TWO = Constant(2) - self.assertEqual(assertIsInstance(ONE + TWO, Constant).value, 3) - self.assertEqual(assertIsInstance(ONE - TWO, Constant).value, -1) + TWO = F.Constant(2) + self.assertEqual(assertIsInstance(ONE + TWO, F.Constant).value, 3) + self.assertEqual(assertIsInstance(ONE - TWO, F.Constant).value, -1) - self.assertEqual(assertIsInstance((ONE / TWO) / TWO, Constant).value, 1 / 4) + self.assertEqual(assertIsInstance((ONE / TWO) / TWO, F.Constant).value, 1 / 4) # Range - R_ONE_TEN = Range(1, 10) - self.assertEqual(assertIsInstance(R_ONE_TEN + TWO, Range), Range(3, 12)) + R_ONE_TEN = F.Range(1, 10) + self.assertEqual(assertIsInstance(R_ONE_TEN + TWO, F.Range), F.Range(3, 12)) - R_TWO_THREE = Range(2, 3) - self.assertEqual(assertIsInstance(R_ONE_TEN + R_TWO_THREE, Range), Range(3, 13)) - self.assertEqual(assertIsInstance(R_ONE_TEN * R_TWO_THREE, Range), Range(2, 30)) - self.assertEqual(assertIsInstance(R_ONE_TEN - R_TWO_THREE, Range), Range(-2, 8)) + R_TWO_THREE = F.Range(2, 3) self.assertEqual( - assertIsInstance(R_ONE_TEN / R_TWO_THREE, Range), Range(1 / 3, 10 / 2) + assertIsInstance(R_ONE_TEN + R_TWO_THREE, F.Range), F.Range(3, 13) + ) + self.assertEqual( + assertIsInstance(R_ONE_TEN * R_TWO_THREE, F.Range), F.Range(2, 30) + ) + self.assertEqual( + assertIsInstance(R_ONE_TEN - R_TWO_THREE, F.Range), F.Range(-2, 8) + ) + self.assertEqual( + assertIsInstance(R_ONE_TEN / R_TWO_THREE, F.Range), F.Range(1 / 3, 10 / 2) ) # TBD Range - a = TBD[int]() - b = TBD[int]() - R_TBD = Range(a, b) + a = F.TBD[int]() + b = F.TBD[int]() + R_TBD = F.Range(a, b) add = R_ONE_TEN + R_TBD mul = R_ONE_TEN * R_TBD sub = R_ONE_TEN - R_TBD div = R_ONE_TEN / R_TBD - a.merge(Constant(2)) - b.merge(Constant(3)) - self.assertEqual(assertIsInstance(add, Range), Range(3, 13)) - self.assertEqual(assertIsInstance(mul, Range), Range(2, 30)) - self.assertEqual(assertIsInstance(sub, Range), Range(-2, 8)) - self.assertEqual(assertIsInstance(div, Range), Range(1 / 3, 10 / 2)) + a.merge(F.Constant(2)) + b.merge(F.Constant(3)) + self.assertEqual(assertIsInstance(add, F.Range), F.Range(3, 13)) + self.assertEqual(assertIsInstance(mul, F.Range), F.Range(2, 30)) + self.assertEqual(assertIsInstance(sub, F.Range), F.Range(-2, 8)) + self.assertEqual(assertIsInstance(div, F.Range), F.Range(1 / 3, 10 / 2)) # Set - S_FIVE_NINE = Set(set(Constant(x) for x in range(5, 10))) + S_FIVE_NINE = F.Set(set(F.Constant(x) for x in range(5, 10))) self.assertEqual( - assertIsInstance(S_FIVE_NINE + ONE, Set).params, - set(Constant(x) for x in range(6, 11)), + assertIsInstance(S_FIVE_NINE + ONE, F.Set).params, + set(F.Constant(x) for x in range(6, 11)), ) - S_TEN_TWENTY_THIRTY = Set(set(Constant(x) for x in [10, 20, 30])) + S_TEN_TWENTY_THIRTY = F.Set(set(F.Constant(x) for x in [10, 20, 30])) self.assertEqual( - assertIsInstance(S_FIVE_NINE + S_TEN_TWENTY_THIRTY, Set), - Set(Constant(x + y) for x in range(5, 10) for y in [10, 20, 30]), + assertIsInstance(S_FIVE_NINE + S_TEN_TWENTY_THIRTY, F.Set), + F.Set(F.Constant(x + y) for x in range(5, 10) for y in [10, 20, 30]), ) # conjunctions # with static values - R_ONE_TEN = Range(1, 10) - R_TWO_THREE = Range(2, 3) - self.assertEqual(R_ONE_TEN & R_TWO_THREE, Range(2, 3)) - self.assertEqual(R_ONE_TEN & Range(5, 20), Range(5, 10)) - self.assertEqual(R_ONE_TEN & 5, Constant(5)) - self.assertEqual(R_ONE_TEN & Constant(5), Constant(5)) - self.assertEqual(R_ONE_TEN & Set([1, 5, 8, 12]), Set([1, 5, 8])) - self.assertEqual(Set([1, 2, 3]) & Set([2, 3, 4]), Set([2, 3])) - self.assertEqual(Set([1, 2, 3]) & 3, Constant(3)) - self.assertEqual(Constant(3) & 3, Constant(3)) - self.assertEqual(Constant(2) & 3, Set([])) - self.assertEqual(R_ONE_TEN & {1, 2, 11}, Set([1, 2])) - self.assertEqual(R_ONE_TEN & Range(12, 13), Set([])) + R_ONE_TEN = F.Range(1, 10) + R_TWO_THREE = F.Range(2, 3) + self.assertEqual(R_ONE_TEN & R_TWO_THREE, F.Range(2, 3)) + self.assertEqual(R_ONE_TEN & F.Range(5, 20), F.Range(5, 10)) + self.assertEqual(R_ONE_TEN & 5, F.Constant(5)) + self.assertEqual(R_ONE_TEN & F.Constant(5), F.Constant(5)) + self.assertEqual(R_ONE_TEN & F.Set([1, 5, 8, 12]), F.Set([1, 5, 8])) + self.assertEqual(F.Set([1, 2, 3]) & F.Set([2, 3, 4]), F.Set([2, 3])) + self.assertEqual(F.Set([1, 2, 3]) & 3, F.Constant(3)) + self.assertEqual(F.Constant(3) & 3, F.Constant(3)) + self.assertEqual(F.Constant(2) & 3, F.Set([])) + self.assertEqual(R_ONE_TEN & {1, 2, 11}, F.Set([1, 2])) + self.assertEqual(R_ONE_TEN & F.Range(12, 13), F.Set([])) # with tbd - a = TBD[int]() - b = TBD[int]() - R_TBD = Range(a, b) - r_one_ten_con_tbd = R_ONE_TEN & R_TBD - assertIsInstance(r_one_ten_con_tbd, Operation) + a = F.TBD[int]() + b = F.TBD[int]() + RTBD = F.Range(a, b) + r_one_ten_con_tbd = R_ONE_TEN & RTBD + assertIsInstance(r_one_ten_con_tbd, F.Operation) a.merge(2) b.merge(20) - self.assertEqual(assertIsInstance(r_one_ten_con_tbd, Range), Range(2, 10)) + self.assertEqual(assertIsInstance(r_one_ten_con_tbd, F.Range), F.Range(2, 10)) # TODO disjunctions - # Operation - token = TBD() - op = assertIsInstance(ONE + token, Operation) - op2 = assertIsInstance(op + 10, Operation) + # F.Operation + token = F.TBD() + op = assertIsInstance(ONE + token, F.Operation) + op2 = assertIsInstance(op + 10, F.Operation) - self.assertEqual(op.operands, (ONE, TBD())) + self.assertEqual(op.operands, (ONE, F.TBD())) self.assertEqual(op.operation(1, 2), 3) - token.merge(Constant(2)) - self.assertEqual(op.get_most_narrow(), Constant(3)) + token.merge(F.Constant(2)) + self.assertEqual(op.get_most_narrow(), F.Constant(3)) - self.assertEqual(op + 5, Constant(8)) - self.assertEqual(op2.get_most_narrow(), Constant(13)) + self.assertEqual(op + 5, F.Constant(8)) + self.assertEqual(op2.get_most_narrow(), F.Constant(13)) # Any - assertIsInstance(ONE + ANY(), Operation) - assertIsInstance(TBD() + ANY(), Operation) - assertIsInstance((TBD() + TBD()) + ANY(), Operation) + assertIsInstance(ONE + F.ANY(), F.Operation) + assertIsInstance(F.TBD() + F.ANY(), F.Operation) + assertIsInstance((F.TBD() + F.TBD()) + F.ANY(), F.Operation) # Test quantities - self.assertEqual(Constant(1 * P.baud), 1 * P.baud) - self.assertEqual(Constant(1) * P.baud, 1 * P.baud) - self.assertEqual(Range(1, 10) * P.baud, Range(1 * P.baud, 10 * P.baud)) - self.assertEqual(Set([1, 2]) * P.baud, Set([1 * P.baud, 2 * P.baud])) + self.assertEqual(F.Constant(1 * P.baud), 1 * P.baud) + self.assertEqual(F.Constant(1) * P.baud, 1 * P.baud) + self.assertEqual(F.Range(1, 10) * P.baud, F.Range(1 * P.baud, 10 * P.baud)) + self.assertEqual(F.Set([1, 2]) * P.baud, F.Set([1 * P.baud, 2 * P.baud])) def test_resolution(self): def assertIsInstance[T](obj, cls: type[T]) -> T: @@ -139,21 +138,21 @@ def assertIsInstance[T](obj, cls: type[T]) -> T: assert isinstance(obj, cls) return obj - ONE = Constant(1) + ONE = F.Constant(1) self.assertEqual( - assertIsInstance(Parameter.resolve_all([ONE, ONE]), Constant).value, 1 + assertIsInstance(Parameter.resolve_all([ONE, ONE]), F.Constant).value, 1 ) - TWO = Constant(2) + TWO = F.Constant(2) self.assertEqual( assertIsInstance( - Parameter.resolve_all([Operation([ONE, ONE], add), TWO]), Constant + Parameter.resolve_all([F.Operation([ONE, ONE], add), TWO]), F.Constant ).value, 2, ) - self.assertEqual(TBD(), TBD()) - self.assertEqual(ANY(), ANY()) + self.assertEqual(F.TBD(), F.TBD()) + self.assertEqual(F.ANY(), F.ANY()) def test_merge( a: Parameter[int] | set[int] | int | tuple[int, int], @@ -168,9 +167,9 @@ def fail_merge(a, b): a = Parameter[int].from_literal(a) self.assertRaises(Parameter.MergeException, lambda: a.merge(b)) - # Sets ---- + # F.Sets ---- - # Ranges + # F.Ranges test_merge((0, 10), (5, 15), (5, 10)) test_merge((0, 10), (5, 8), (5, 8)) fail_merge((0, 10), (11, 15)) @@ -183,18 +182,18 @@ def fail_merge(a, b): fail_merge((1, 5), set()) fail_merge(5, set()) test_merge(set(), set(), set()) - test_merge(TBD(), set(), set()) - test_merge(ANY(), set(), set()) + test_merge(F.TBD(), set(), set()) + test_merge(F.ANY(), set(), set()) test_merge({1, 2}, {2, 3}, {2}) fail_merge({1, 2}, {3, 4}) test_merge({1, 2}, 2, 2) - # TBD/ANY -- + # F.TBD/F.ANY -- - test_merge(TBD(), TBD(), TBD()) - test_merge(ANY(), ANY(), ANY()) - test_merge(TBD(), ANY(), ANY()) + test_merge(F.TBD(), F.TBD(), F.TBD()) + test_merge(F.ANY(), F.ANY(), F.ANY()) + test_merge(F.TBD(), F.ANY(), F.ANY()) def test_specific(self): def test_spec( @@ -222,14 +221,14 @@ def test_spec( test_spec((1, 2), (1, 3), False) test_spec((1, 10), (1, 3)) - test_spec(1, ANY(), False) - test_spec(ANY(), 1) - test_spec(TBD(), 1, False) - test_spec(ANY(), Operation((1, 2), add)) - test_spec(ANY(), Operation((1, TBD()), add)) + test_spec(1, F.ANY(), False) + test_spec(F.ANY(), 1) + test_spec(F.TBD(), 1, False) + test_spec(F.ANY(), F.Operation((1, 2), add)) + test_spec(F.ANY(), F.Operation((1, F.TBD()), add)) - test_spec(Operation((1, 2), add), 3) - test_spec(Operation((1, TBD()), add), TBD(), False) + test_spec(F.Operation((1, 2), add), 3) + test_spec(F.Operation((1, F.TBD()), add), F.TBD(), False) def test_compress(self): def test_comp( @@ -241,12 +240,12 @@ def test_comp( self.assertEqual(a.get_most_narrow(), expected) test_comp(1, 1) - test_comp(Constant(Constant(1)), 1) - test_comp(Constant(Constant(Constant(1))), 1) + test_comp(F.Constant(F.Constant(1)), 1) + test_comp(F.Constant(F.Constant(F.Constant(1))), 1) test_comp({1}, 1) - test_comp(Range(1), 1) - test_comp(Range(Range(1)), 1) - test_comp(Constant(Set([Range(Range(1))])), 1) + test_comp(F.Range(1), 1) + test_comp(F.Range(F.Range(1)), 1) + test_comp(F.Constant(F.Set([F.Range(F.Range(1))])), 1) def test_modules(self): def assertIsInstance[T](obj, cls: type[T]) -> T: @@ -255,9 +254,9 @@ def assertIsInstance[T](obj, cls: type[T]) -> T: return obj class Modules(Module): - UART_A: UART_Base - UART_B: UART_Base - UART_C: UART_Base + UART_A: F.UART_Base + UART_B: F.UART_Base + UART_C: F.UART_Base m = Modules() @@ -267,54 +266,59 @@ class Modules(Module): UART_A.connect(UART_B) - UART_A.baud.merge(Constant(9600 * P.baud)) + UART_A.baud.merge(F.Constant(9600 * P.baud)) for uart in [UART_A, UART_B]: self.assertEqual( - assertIsInstance(uart.baud.get_most_narrow(), Constant).value, + assertIsInstance(uart.baud.get_most_narrow(), F.Constant).value, 9600 * P.baud, ) - UART_C.baud.merge(Range(1200 * P.baud, 115200 * P.baud)) + UART_C.baud.merge(F.Range(1200 * P.baud, 115200 * P.baud)) UART_A.connect(UART_C) for uart in [UART_A, UART_B, UART_C]: self.assertEqual( - assertIsInstance(uart.baud.get_most_narrow(), Constant).value, + assertIsInstance(uart.baud.get_most_narrow(), F.Constant).value, 9600 * P.baud, ) - resistor = Resistor() + resistor = F.Resistor() assertIsInstance( - resistor.get_current_flow_by_voltage_resistance(Constant(0.5)), Operation + resistor.get_current_flow_by_voltage_resistance(F.Constant(0.5)), + F.Operation, ) def test_comparisons(self): # same type - self.assertGreater(Constant(2), Constant(1)) - self.assertLess(Constant(1), Constant(2)) - self.assertLessEqual(Constant(2), Constant(2)) - self.assertGreaterEqual(Constant(2), Constant(2)) - self.assertLess(Range(1, 2), Range(3, 4)) - self.assertEqual(min(Range(1, 2), Range(3, 4), Range(5, 6)), Range(1, 2)) + self.assertGreater(F.Constant(2), F.Constant(1)) + self.assertLess(F.Constant(1), F.Constant(2)) + self.assertLessEqual(F.Constant(2), F.Constant(2)) + self.assertGreaterEqual(F.Constant(2), F.Constant(2)) + self.assertLess(F.Range(1, 2), F.Range(3, 4)) + self.assertEqual( + min(F.Range(1, 2), F.Range(3, 4), F.Range(5, 6)), F.Range(1, 2) + ) # mixed - self.assertLess(Constant(1), Range(2, 3)) - self.assertGreater(Constant(4), Range(2, 3)) - self.assertFalse(Constant(3) < Range(2, 4)) - self.assertFalse(Constant(3) > Range(2, 4)) - self.assertFalse(Constant(3) == Range(2, 4)) - self.assertEqual(min(Constant(3), Range(5, 6), Constant(4)), Constant(3)) + self.assertLess(F.Constant(1), F.Range(2, 3)) + self.assertGreater(F.Constant(4), F.Range(2, 3)) + self.assertFalse(F.Constant(3) < F.Range(2, 4)) + self.assertFalse(F.Constant(3) > F.Range(2, 4)) + self.assertFalse(F.Constant(3) == F.Range(2, 4)) + self.assertEqual( + min(F.Constant(3), F.Range(5, 6), F.Constant(4)), F.Constant(3) + ) # nested - self.assertLess(Constant(1), Set([Constant(2), Constant(3)])) - self.assertLess(Range(1, 2), Range(Constant(3), Constant(4))) - self.assertLess(Range(1, 2), Set([Constant(4), Constant(3)])) - self.assertLess(Constant(Constant(Constant(1))), 2) + self.assertLess(F.Constant(1), F.Set([F.Constant(2), F.Constant(3)])) + self.assertLess(F.Range(1, 2), F.Range(F.Constant(3), F.Constant(4))) + self.assertLess(F.Range(1, 2), F.Set([F.Constant(4), F.Constant(3)])) + self.assertLess(F.Constant(F.Constant(F.Constant(1))), 2) self.assertEqual( - min(Constant(Constant(Constant(1))), Constant(Constant(2))), - Constant(Constant(Constant(1))), + min(F.Constant(F.Constant(F.Constant(1))), F.Constant(F.Constant(2))), + F.Constant(F.Constant(F.Constant(1))), ) def test_specialize(self): @@ -340,7 +344,7 @@ def __preinit__(self) -> None: bcell = specialize_module(app.battery, F.ButtonCell()) bcell.voltage.merge(3 * P.V) - bcell.capacity.merge(Range.from_center(225 * P.mAh, 50 * P.mAh)) + bcell.capacity.merge(F.Range.from_center(225 * P.mAh, 50 * P.mAh)) bcell.material.merge(F.ButtonCell.Material.Lithium) bcell.size.merge(F.ButtonCell.Size.N_2032) bcell.shape.merge(F.ButtonCell.Shape.Round) @@ -357,10 +361,10 @@ def __preinit__(self) -> None: self.assertEqual(v.get_most_narrow(), 3 * P.V) r = app.led.current_limiting_resistor.resistance r = r.get_most_narrow() - self.assertIsInstance(r, Range, f"{type(r)}") + self.assertIsInstance(r, F.Range, f"{type(r)}") def test_units(self): - self.assertEqual(Constant(1e-9 * P.F), 1 * P.nF) + self.assertEqual(F.Constant(1e-9 * P.F), 1 * P.nF) if __name__ == "__main__": diff --git a/test/library/test_footprints.py b/test/library/test_footprints.py index f08a9378..297d2f7f 100644 --- a/test/library/test_footprints.py +++ b/test/library/test_footprints.py @@ -3,15 +3,14 @@ import unittest -from faebryk.library.has_kicad_footprint import has_kicad_footprint -from faebryk.library.QFN import QFN +import faebryk.library._F as F from faebryk.libs.units import P class TestFootprints(unittest.TestCase): def test_qfn_kicad(self): test_cases = { - "Package_DFN_QFN:QFN-16-1EP_4x4mm_P0.5mm_EP2.45x2.45mm_ThermalVias": QFN( # noqa: E501 + "Package_DFN_QFN:QFN-16-1EP_4x4mm_P0.5mm_EP2.45x2.45mm_ThermalVias": F.QFN( # noqa: E501 pin_cnt=16, exposed_thermal_pad_cnt=1, size_xy=(4 * P.mm, 4 * P.mm), @@ -19,7 +18,7 @@ def test_qfn_kicad(self): exposed_thermal_pad_dimensions=(2.45 * P.mm, 2.45 * P.mm), has_thermal_vias=True, ), - "Package_DFN_QFN:QFN-12-1EP_3x3mm_P0.5mm_EP1.6x1.6mm": QFN( + "Package_DFN_QFN:QFN-12-1EP_3x3mm_P0.5mm_EP1.6x1.6mm": F.QFN( pin_cnt=12, exposed_thermal_pad_cnt=1, size_xy=(3 * P.mm, 3 * P.mm), @@ -27,7 +26,7 @@ def test_qfn_kicad(self): exposed_thermal_pad_dimensions=(1.6 * P.mm, 1.6 * P.mm), has_thermal_vias=False, ), - "Package_DFN_QFN:QFN-20-1EP_3.5x3.5mm_P0.5mm_EP2x2mm": QFN( + "Package_DFN_QFN:QFN-20-1EP_3.5x3.5mm_P0.5mm_EP2x2mm": F.QFN( pin_cnt=20, exposed_thermal_pad_cnt=1, size_xy=(3.5 * P.mm, 3.5 * P.mm), @@ -39,7 +38,8 @@ def test_qfn_kicad(self): for solution, footprint in test_cases.items(): self.assertEqual( - solution, footprint.get_trait(has_kicad_footprint).get_kicad_footprint() + solution, + footprint.get_trait(F.has_kicad_footprint).get_kicad_footprint(), ) def test_qfn_constraints(self): @@ -49,7 +49,7 @@ def test_qfn_constraints(self): # only thermal via if thermal pad cnt > 0 self.assertRaises( AssertionError, - lambda: QFN( + lambda: F.QFN( pin_cnt=20, exposed_thermal_pad_cnt=0, size_xy=(3.5 * P.mm, 3.5 * P.mm), @@ -62,7 +62,7 @@ def test_qfn_constraints(self): # pad has to be smaller than package self.assertRaises( AssertionError, - lambda: QFN( + lambda: F.QFN( pin_cnt=20, exposed_thermal_pad_cnt=1, size_xy=(3.5 * P.mm, 3.5 * P.mm),