gdsfactory / kfactory

gdsfactory with a klayout backend
https://gdsfactory.github.io/kfactory/
MIT License
34 stars 13 forks source link

Fix fill_tiled segfault #521

Closed sebastian-goeldi closed 4 days ago

sebastian-goeldi commented 4 days ago

fix https://github.com/KLayout/klayout/issues/1929

Summary by Sourcery

Bug Fixes:

sourcery-ai[bot] commented 4 days ago

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

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"

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](https://app.sourcery.ai) 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 - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).