From 799b479f174a1429ba64f4c93bdc4829e7ad2cd9 Mon Sep 17 00:00:00 2001 From: iopapamanoglou Date: Tue, 3 Sep 2024 17:55:51 +0200 Subject: [PATCH] Update syntax to faebryk 4.x --- examples/signal_processing.py | 27 +++----- src/faebryk/library/Filter.py | 26 ++----- src/faebryk/library/FilterElectricalLC.py | 69 ++++++------------- src/faebryk/library/SignalElectrical.py | 20 ++---- .../library/has_construction_dependency.py | 7 +- .../has_parameter_construction_dependency.py | 4 +- 6 files changed, 49 insertions(+), 104 deletions(-) diff --git a/examples/signal_processing.py b/examples/signal_processing.py index f6e0cf0b..65f93609 100644 --- a/examples/signal_processing.py +++ b/examples/signal_processing.py @@ -7,35 +7,30 @@ import logging -import faebryk.library._F as F import typer -from faebryk.core.core import Module + +import faebryk.library._F as F +from faebryk.core.module import Module from faebryk.core.util import specialize_module -from faebryk.libs.experiments.buildutil import ( - tag_and_export_module_to_netlist, -) +from faebryk.libs.examples.buildutil import apply_design_to_pcb from faebryk.libs.logging import setup_basic_logging +from faebryk.libs.units import P logger = logging.getLogger(__name__) class App(Module): - def __init__(self) -> None: - super().__init__() - - class _NODES(Module.NODES()): - lowpass = F.Filter() - - self.NODEs = _NODES(self) + lowpass: F.Filter + def __preinit__(self) -> None: # TODO actually do something with the filter # Parametrize - self.NODEs.lowpass.PARAMs.cutoff_frequency.merge(200) - self.NODEs.lowpass.PARAMs.response.merge(F.Filter.Response.LOWPASS) + self.lowpass.cutoff_frequency.merge(200 * P.hz) + self.lowpass.response.merge(F.Filter.Response.LOWPASS) # Specialize - specialize_module(self.NODEs.lowpass, F.FilterElectricalLC()) + specialize_module(self.lowpass, F.FilterElectricalLC()) def main(): @@ -43,7 +38,7 @@ def main(): app = App() logger.info("Export") - tag_and_export_module_to_netlist(app) + apply_design_to_pcb(app) if __name__ == "__main__": diff --git a/src/faebryk/library/Filter.py b/src/faebryk/library/Filter.py index 7e9bb8bc..fb348c1e 100644 --- a/src/faebryk/library/Filter.py +++ b/src/faebryk/library/Filter.py @@ -3,9 +3,8 @@ from enum import Enum, auto +import faebryk.library._F as F from faebryk.core.core import Module -from faebryk.library.Signal import Signal -from faebryk.library.TBD import TBD class Filter(Module): @@ -16,22 +15,9 @@ class Response(Enum): BANDSTOP = auto() OTHER = auto() - @classmethod - def PARAMS(cls): - class _PARAMs(super().PARAMS()): - cutoff_frequency = TBD[float]() - order = TBD[int]() - response = TBD[Filter.Response]() + cutoff_frequency: F.TBD[float] + order: F.TBD[int] + response: F.TBD[Response] - return _PARAMs - - def __init__(self): - super().__init__() - - self.PARAMs = self.PARAMS()(self) - - class _IFs(super().IFS()): - in_ = Signal() - out = Signal() - - self.IFs = _IFs(self) + in_: F.Signal + out: F.Signal diff --git a/src/faebryk/library/FilterElectricalLC.py b/src/faebryk/library/FilterElectricalLC.py index f7c81ca5..0301f063 100644 --- a/src/faebryk/library/FilterElectricalLC.py +++ b/src/faebryk/library/FilterElectricalLC.py @@ -3,65 +3,40 @@ import math -from faebryk.core.util import specialize_interface -from faebryk.library.Capacitor import Capacitor -from faebryk.library.Filter import Filter -from faebryk.library.has_parameter_construction_dependency import ( - has_parameter_construction_dependency, -) -from faebryk.library.Inductor import Inductor -from faebryk.library.SignalElectrical import SignalElectrical +import faebryk.library._F as F +from faebryk.libs.library import L -class FilterElectricalLC(Filter): - @classmethod - def PARAMS(cls): - class _PARAMs(super().PARAMS()): ... +class FilterElectricalLC(F.Filter): + in_: F.SignalElectrical + out: F.SignalElectrical + capacitor: F.Capacitor + inductor: F.Inductor - return _PARAMs - - def __init__(self): - super().__init__() - - self.PARAMs = self.PARAMS()(self) - - self.IFs_filter = self.IFs - - class _IFs(super().IFS()): - in_ = SignalElectrical() - out = SignalElectrical() - - self.IFs = _IFs(self) - - specialize_interface(self.IFs_filter.in_, self.IFs.in_) - specialize_interface(self.IFs_filter.out, self.IFs.out) - - class _NODES(super().NODES()): - capacitor = Capacitor() - inductor = Inductor() - - self.NODEs = _NODES(self) + def __preinit__(self) -> None: ... + @L.rt_field + def has_parameter_construction_dependency(self): class _has_parameter_construction_dependency( - has_parameter_construction_dependency.impl() + F.has_parameter_construction_dependency.impl() ): def construct(_self): if not self._construct(): return _self._fullfill() - self.add_trait(_has_parameter_construction_dependency()) + return _has_parameter_construction_dependency() def _construct(self): # TODO other responses - self.PARAMs.response.merge(Filter.Response.LOWPASS) + self.response.merge(F.Filter.Response.LOWPASS) # TODO other orders - self.PARAMs.order.merge(2) + self.order.merge(2) - L = self.NODEs.inductor.PARAMs.inductance - C = self.NODEs.capacitor.PARAMs.capacitance - fc = self.PARAMs.cutoff_frequency + L = self.inductor.inductance + C = self.capacitor.capacitance + fc = self.cutoff_frequency # TODO requires parameter constraint solving implemented # fc.merge(1 / (2 * math.pi * math.sqrt(C * L))) @@ -72,11 +47,9 @@ def _construct(self): # TODO consider splitting C / L in a typical way # low pass - self.IFs.in_.IFs.signal.connect_via( - (self.NODEs.inductor, self.NODEs.capacitor), - self.IFs.in_.IFs.reference.IFs.lv, + self.in_.signal.connect_via( + (self.inductor, self.capacitor), + self.in_.reference.lv, ) - self.IFs.in_.IFs.signal.connect_via( - self.NODEs.inductor, self.IFs.out.IFs.signal - ) + self.in_.signal.connect_via(self.inductor, self.out.signal) diff --git a/src/faebryk/library/SignalElectrical.py b/src/faebryk/library/SignalElectrical.py index 3bc6d3fb..a0048a21 100644 --- a/src/faebryk/library/SignalElectrical.py +++ b/src/faebryk/library/SignalElectrical.py @@ -1,19 +1,11 @@ # This file is part of the faebryk project # SPDX-License-Identifier: MIT -from faebryk.library.Electrical import Electrical -from faebryk.library.ElectricPower import ElectricPower -from faebryk.library.Signal import Signal +import faebryk.library._F as F -class SignalElectrical(Signal): - def __init__(self) -> None: - super().__init__() - - class _IFs(Signal.IFS()): - # line is a better name, but for compatibility with Logic we use signal - # might change in future - signal = Electrical() - reference = ElectricPower() - - self.IFs = _IFs(self) +class SignalElectrical(F.Signal): + # line is a better name, but for compatibility with Logic we use signal + # might change in future + signal: F.Electrical + reference: F.ElectricPower diff --git a/src/faebryk/library/has_construction_dependency.py b/src/faebryk/library/has_construction_dependency.py index 2748cda5..09650601 100644 --- a/src/faebryk/library/has_construction_dependency.py +++ b/src/faebryk/library/has_construction_dependency.py @@ -3,12 +3,11 @@ from abc import abstractmethod -from faebryk.core.core import NodeTrait +from faebryk.core.trait import Trait -class has_construction_dependency(NodeTrait): - def __init__(self) -> None: - super().__init__() +class has_construction_dependency(Trait): + def __preinit__(self) -> None: self.executed = False @abstractmethod diff --git a/src/faebryk/library/has_parameter_construction_dependency.py b/src/faebryk/library/has_parameter_construction_dependency.py index a76d506b..5bd5691f 100644 --- a/src/faebryk/library/has_parameter_construction_dependency.py +++ b/src/faebryk/library/has_parameter_construction_dependency.py @@ -1,7 +1,7 @@ # This file is part of the faebryk project # SPDX-License-Identifier: MIT -from faebryk.library.has_construction_dependency import has_construction_dependency +import faebryk.library._F as F -class has_parameter_construction_dependency(has_construction_dependency): ... +class has_parameter_construction_dependency(F.has_construction_dependency): ...