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

Fix fill_tiled segfault #521

Merged
merged 2 commits into from
Nov 21, 2024
Merged

Fix fill_tiled segfault #521

merged 2 commits into from
Nov 21, 2024

Conversation

sebastian-goeldi
Copy link
Collaborator

@sebastian-goeldi sebastian-goeldi commented Nov 21, 2024

fix KLayout/klayout#1929

Summary by Sourcery

Bug Fixes:

  • Fix a segmentation fault in the fill_tiled function by introducing temporary layout and cell handling.

Copy link
Contributor

sourcery-ai bot commented Nov 21, 2024

Reviewer's Guide by Sourcery

The PR fixes a segfault in the fill_tiled function by introducing a temporary layout and cell to handle fill operations. Instead of directly modifying the target cell during the filling process, the changes are first applied to a temporary cell and then transferred to the target cell in a controlled manner.

Sequence diagram for fill_tiled function changes

sequenceDiagram
    participant FillOperator
    participant temp_ly as Temporary Layout
    participant temp_tc as Temporary Cell
    participant top_cell as Top Cell
    participant fill_cell as Fill Cell

    fill_tiled->>FillOperator: Create FillOperator instance
    FillOperator->>temp_ly: Start changes
    FillOperator->>temp_tc: fill_region_multi or fill_region
    FillOperator->>temp_ly: End changes
    FillOperator->>temp_tc: Iterate each_inst
    temp_tc->>top_cell: Insert cell_inst_array
    fill_tiled->>FillOperator: insert_fill()
    FillOperator->>top_cell: Insert fill cell into regions
Loading

Class diagram for FillOperator changes

classDiagram
    class FillOperator {
        +list<kdb.Cell> filled_cells
        +kdb.Layout temp_ly
        +kdb.Cell temp_tc
        +kdb.Cell temp_fc
        +int temp_fc_ind
        +void insert_fill()
    }
    FillOperator : fill_region_multi(region, fill_cell_index, fc_bbox, row_step, column_step, fill_margin, glue_box)
    FillOperator : fill_region(region, fill_cell_index, fc_bbox, row_step, column_step, fill_margin, glue_box)
    note for FillOperator "New attributes and method added to handle temporary layout and cell operations"
Loading

File-Level Changes

Change Details Files
Introduce temporary layout and cell handling for fill operations
  • Add temporary layout and cell properties to FillOperator class
  • Create temporary copies of the top cell and fill cell
  • Initialize layout change tracking with start_changes()
  • Modify fill operations to work with temporary cells instead of target cells
src/kfactory/utils/fill.py
Add new method to safely transfer fill instances
  • Add insert_fill method to transfer instances from temporary to target cell
  • Update cell indices during transfer to maintain correct references
  • End layout changes after fill calculation
  • Call insert_fill after fill region calculation is complete
src/kfactory/utils/fill.py
Refactor fill_tiled function structure
  • Move FillOperator instantiation outside of tp.output call
  • Update logging message to be more accurate about the operation stage
  • Remove unnecessary parameters from fill_region_multi call
src/kfactory/utils/fill.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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.

cell_inst_array = inst.cell_inst
cell_inst_array.cell_index = self.fill_cell_index
self.top_cell.insert(cell_inst_array)


def fill_tiled(
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:


Explanation

The 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.

@github-actions github-actions bot added the bug Something isn't working label Nov 21, 2024
@sebastian-goeldi sebastian-goeldi merged commit bd38e04 into main Nov 21, 2024
13 checks passed
@sebastian-goeldi sebastian-goeldi deleted the fix-tiling-filling branch November 21, 2024 14:16
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.

Tiling processor segfaults when multithreading is enabled
1 participant