Skip to content

Refactor core calculation out of buck / boost converters#407

Merged
ducky64 merged 16 commits intomasterfrom
mp2722
Jun 8, 2025
Merged

Refactor core calculation out of buck / boost converters#407
ducky64 merged 16 commits intomasterfrom
mp2722

Conversation

@ducky64
Copy link
Copy Markdown
Collaborator

@ducky64 ducky64 commented Jun 8, 2025

This makes the core component calculations more unit-testable and unifies the buck-boost converter (as well as allowing other variations-on-a-theme converters like forward-buck-reverse-boost as with some NVDC battery chargers with OTG with less code duplication)

Changes the boost inductor calculation to avoid double-counting output tolerance. The inductance formula appears monotonic.

Core infrastructural changes:

  • Refactor NumLikeExpr types (IntExpr, FloatExpr, RangeExpr) to centrally define castable-types and properly return NotImplemented on a type it cannot handle. This cleanly handles promotion of FloatLike / IntLike types to Range types.
  • Add hull and intersect to Range

TODO:

  • Add unit tests
  • Move FCML + scaling into its own block

Follow-on PRs will add coupled current/inductance support (#405) and the MP2722 converter which this is building towards.

@ducky64 ducky64 marked this pull request as ready for review June 8, 2025 03:30
@ducky64 ducky64 requested a review from Copilot June 8, 2025 03:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Refactors core buck/boost converter calculations into reusable calculate_parameters methods, adds range utilities, and introduces an FCML power path example with scaling support.

  • Centralize component sizing logic into BuckConverterPowerPath.Values and BoostConverterPowerPath.Values and update generate to use them
  • Extend Range/RangeExpr with hull and intersect and cover them with new tests
  • Add FcmlPowerPath example and update Simon/Fcml netlists to reference it

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
examples/test_fcml.py Added FcmlPowerPath example for inductor scaling
examples/Simon/Simon.ref.net Updated inductor value and part reference
examples/Simon/Simon.net Updated inductor value and part reference
examples/Fcml/Fcml.ref.net Pointed part source to FcmlPowerPath
examples/Fcml/Fcml.net Pointed part source to FcmlPowerPath
edg/core/test_range.py Renamed and expanded tests for intersects and intersect
edg/core/Range.py Implemented hull and intersect methods
edg/core/ConstraintExpr.py Unified arithmetic operator handling with _CASTABLE_TYPES
edg/abstract_parts/test_switching_converters.py New calculation tests for buck/boost converters
edg/abstract_parts/AbstractPowerConverters.py Introduced Values NamedTuples and calculate_parameters; refactored generate
Comments suppressed due to low confidence (4)

edg/core/test_range.py:59

  • [nitpick] There are two test methods: test_intersects and test_intersect, which may confuse their intent. Consider renaming them to test_intersects_boolean and test_intersect_result for clarity.
def test_intersect(self):

examples/test_fcml.py:177

  • [nitpick] Update or remove this TODO in the class docstring—either note the intended duplication or refactor to clarify why the code is duplicated.
 TODO: this basically completely duplicates BuckConverterPowerPath, but adds a scaling factor that doesn't exist there

edg/abstract_parts/AbstractPowerConverters.py:207

  • [nitpick] Add a docstring above the Values NamedTuple to explain each field and its units, improving discoverability for API consumers.
class Values(NamedTuple):

examples/test_fcml.py:175

  • Consider adding unit tests for FcmlPowerPath.calculate_parameters and its scaling factor logic to verify the new behavior.
class FcmlPowerPath(InternalSubcircuit, GeneratorBlock):


def intersect(self, other: 'Range') -> 'Range':
# TODO make behavior more consistent w/ compiler and returning empty that props as a unit
assert self.intersects(other), "Cannot intersect ranges that do not intersect"
Copy link

Copilot AI Jun 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an assert here will be skipped if Python is run with optimizations. Consider raising a ValueError for invalid intersection to ensure the check always runs.

Suggested change
assert self.intersects(other), "Cannot intersect ranges that do not intersect"
if not self.intersects(other):
raise ValueError("Cannot intersect ranges that do not intersect")

Copilot uses AI. Check for mistakes.
@ducky64 ducky64 merged commit c01d3e6 into master Jun 8, 2025
11 checks passed
@ducky64 ducky64 deleted the mp2722 branch June 8, 2025 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants