Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve netlist format and extractor #2846

Merged
merged 17 commits into from
Jun 11, 2024
Merged

Improve netlist format and extractor #2846

merged 17 commits into from
Jun 11, 2024

Conversation

tvt173
Copy link
Collaborator

@tvt173 tvt173 commented Jun 10, 2024

This PR

  • adds the capability to extract cell arrays. ports on an array ref will be represented as my_array_ref<ia.ib>,port_name. note that i use a "." between ia and ib rather than a comma so that port parsing everywhere doesn't break
  • changes the extraction method to extract out "links" rather than "connections" (however, "connections" are still valid in the input yaml and "links" will have no influence when read)
  • fixes various components which had zero-length straights, which were causing extraction errors
  • fixes the Port constructor to allow width to be an optional attribute (and take the cross-section width if unspecified)

Partially resolves #2831

@joamatab joamatab added the bug Something isn't working label Jun 10, 2024
@tvt173
Copy link
Collaborator Author

tvt173 commented Jun 10, 2024

@joamatab this PR should be ready to go. it partially resolves #2831 and replaces #2833

for #2831 what still remains is

  • better handling of virtual instances
  • allow serialization of the layout only (no links)... if this is desired. in that case though, it is no longer really a netlist we are extracting... so maybe that option should just be a different function, if we decide to add it

one thing i notice is that the test_netlists[cross] case unpredictably fails. this appears to be due to problems in serializing the layer. it seems to unpredictably waver between serializing as a layer name vs a layer number (see screenshot below). not sure why this is, but i assume it's a kfactory issue @sebastian-goeldi . just having the tests run in a different order will cause this particular regression test to pass or fail
image

@tvt173
Copy link
Collaborator Author

tvt173 commented Jun 10, 2024

sorry, actually i should still add one more thing before merging... the capability to parse array-port specifications on the input yaml. i will do that before merging

@tvt173 tvt173 marked this pull request as ready for review June 11, 2024 05:20
Copy link
Contributor

sourcery-ai bot commented Jun 11, 2024

🧙 Sourcery is reviewing your pull request!


Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

We've reviewed this pull request using the Sourcery rules engine. If you would also like our AI-powered code review then let us know.

def _is_array_reference(ref: ComponentReference) -> bool:
return ref.na > 1 or ref.nb > 1


def get_netlist(
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Low code quality found in get_netlist - 7% (low-code-quality)


ExplanationThe quality score for this function is below the quality threshold of 25%.
This score is a combination of the method length, cognitive complexity and working memory.

How can you solve this?

It might be worth refactoring this function to make it shorter and more readable.

  • Reduce the function length by extracting pieces of functionality out into
    their own functions. This is the most important thing you can do - ideally a
    function should be less than 10 lines.
  • Reduce nesting, perhaps by introducing guard clauses to return early.
  • Ensure that variables are tightly scoped, so that code using related concepts
    sits together within the function rather than being scattered.

f"Too many angle brackets (<) in instance specification '{inst_spec}'. Array ref indices should end with <ia.ib>, and otherwise this character should be avoided."
)
if "<" in inst_spec and inst_spec.endswith(">"):
inst_name, array_spec = inst_spec.split("<")
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): We've found these issues:

instance_dst_name, port_dst_name = (
s.strip() for s in dst.split(",")
)
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Explicitly raise from a previous error [×5] (raise-from-previous-error)

@tvt173
Copy link
Collaborator Author

tvt173 commented Jun 11, 2024

an additional test (tests/read/test_component_from_yaml.py::test_gds_and_settings[sample_mirror_simple]) broke, related to gdsfactory/kfactory#392, since we now reference the port of the instance directly when connecting, rather than referencing it by name, and this currently gives unexpected behavior when a mirror is applied. otherwise i think this is good to go if you all are happy with it

Copy link

codecov bot commented Jun 11, 2024

Codecov Report

Attention: Patch coverage is 63.90977% with 48 lines in your changes missing coverage. Please review.

Project coverage is 68.90%. Comparing base (e5e1ee6) to head (ce93f3e).
Report is 1 commits behind head on main.

Files Patch % Lines
gdsfactory/read/from_yaml.py 51.06% 41 Missing and 5 partials ⚠️
gdsfactory/get_netlist.py 91.30% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2846      +/-   ##
==========================================
+ Coverage   68.67%   68.90%   +0.22%     
==========================================
  Files         298      298              
  Lines       15254    15359     +105     
  Branches     2229     2253      +24     
==========================================
+ Hits        10476    10583     +107     
+ Misses       4183     4178       -5     
- Partials      595      598       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@joamatab joamatab merged commit d901933 into main Jun 11, 2024
12 of 16 checks passed
@joamatab joamatab deleted the improve-netlist-format branch June 11, 2024 06:52
@tvt173 tvt173 mentioned this pull request Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better netlist format and extractor
3 participants