Skip to content

Fix fibre port placed off the fibre axis in get_simulation_grating_fiber - #776

Open
Alisama20 wants to merge 1 commit into
gdsfactory:mainfrom
Alisama20:fix/fiber-port-off-fiber-axis
Open

Fix fibre port placed off the fibre axis in get_simulation_grating_fiber#776
Alisama20 wants to merge 1 commit into
gdsfactory:mainfrom
Alisama20:fix/fiber-port-off-fiber-axis

Conversation

@Alisama20

@Alisama20 Alisama20 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

What

get_simulation_grating_fiber places the fibre port off the fibre.

fiber_port_x_offset_from_angle is computed from a fiber_port_y that omits
pml_thickness, substrate_thickness and box_thickness. Forty lines later
fiber_port_y is reassigned to the full sum and used for fiber_port_center,
but the x offset is never recomputed — so the port's x is the x of a height the
port is not at.

The fibre core block is built centred on x=0 and rotated by fiber_angle, so
its axis crosses height y at x = y*tan(fiber_angle). Getting y wrong
displaces the port along x by y_error * tan(fiber_angle), growing with the
fibre angle.

Evidence

Measured from the simulation's own epsilon, sampled along the fibre port line
(defaults, fiber_angle_deg=20):

x (um)
port centred at 0.3239
fibre core centre on that line 1.0701
fibre axis at that height predicts 1.0592
port offset from the core -0.7462

The measured core centre and the axis prediction agree to 0.011 um, which is
what confirms the port — not the geometry — is the thing that is misplaced.
The stale offset also feeds sxy, so the cell comes out narrower than the
xmargin that was asked for.

Fix

Compute fiber_port_y once, correctly, and delete the duplicate. Net effect is
three fewer lines of logic and one definition instead of two.

After the fix the port lands 0.0728 um from the core centre. That residue is
not error: it is the monitor's deliberate 0.2 um standoff in y, projected onto
the tilted axis, 0.2 * tan(20 deg) = 0.0728 — agreeing to four decimals.

Test

This adds the first test for this module. It finds the fibre core by probing
the built dielectric along the port line, so it reads no port variable and
cannot agree with a misplaced port by construction. The tolerance is derived,
not tuned: the monitor's y standoff projected on the axis, plus two pixels for
the resolution of the core edges.

Verified to fail on the unfixed code and pass on the fixed one, at two angles:

# before
E  AssertionError: fibre port centred at x=0.3239 um but the fibre core on that
   line is centred at x=1.0701 um (off by -0.7462 um, tolerance 0.2061 um)
FAILED test_get_simulation_grating_fiber.py::test_fiber_port_sits_on_the_fiber_axis[10.0]
FAILED test_get_simulation_grating_fiber.py::test_fiber_port_sits_on_the_fiber_axis[20.0]
2 failed in 5.07s

# after
test_get_simulation_grating_fiber.py::test_fiber_port_sits_on_the_fiber_axis[10.0] PASSED
test_get_simulation_grating_fiber.py::test_fiber_port_sits_on_the_fiber_axis[20.0] PASSED
2 passed in 6.15s

Run in the meep environment (meep 1.34.0, gdsfactory 9.34.2).

Scope

This does not touch the S-parameter extraction. It came up while investigating
the fibre port for a separate issue about s22, which I am filing separately.

Summary by Sourcery

Align the grating-fibre port with the fibre axis and add regression coverage for angled fibre configurations.

Bug Fixes:

  • Correct the fibre port placement so it remains aligned with the tilted fibre axis across the full simulation geometry.

Tests:

  • Add angle-parametrized geometry tests that verify the fibre port is centred on the simulated fibre core.

…_fiber

fiber_port_x_offset_from_angle was computed from a fiber_port_y that omitted
pml_thickness, substrate_thickness and box_thickness. A few lines later
fiber_port_y was reassigned to the full sum and used for the port centre, but
the x offset was never recomputed, so the fibre port was placed at the x of a
height it is not at.

With the library defaults that puts the port 0.746 um off the fibre core,
measured from the simulation's own epsilon along the port line: port centred at
x=0.3239 um, core centred at x=1.0701 um, while the fibre axis at that height
is at x=1.0592 um. The error is y_error * tan(fiber_angle), so it grows with
the fibre angle. It also feeds sxy, making the cell narrower than the requested
margin.

Fixed by computing fiber_port_y once, correctly, and deleting the duplicate.
After the fix the port lands 0.0728 um from the core centre, which is exactly
the monitor's deliberate 0.2 um y standoff projected on the tilted axis
(0.2 * tan(20 deg) = 0.0728).

Adds the first test for this module. It locates the fibre core by probing the
simulation's own dielectric along the port line, so it does not read any port
variable and cannot agree with a mis-placed port by construction. Verified to
fail on the unfixed code (off by -0.7462 um against a 0.2061 um tolerance) at
both 10 and 20 degrees, and to pass after.
@sourcery-ai

sourcery-ai Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Fixes fibre-port misalignment by calculating its vertical position once from the full layer stack before deriving the angle-dependent x offset, and adds independent epsilon-based regression coverage at two fibre angles.

Sequence diagram for fibre port axis regression test

sequenceDiagram
    participant Test
    participant Builder as get_simulation_grating_fiber
    participant Epsilon as Built dielectric
    Test->>Builder: get_simulation_grating_fiber(fiber_angle_deg)
    Builder-->>Test: Simulation with fibre port
    Test->>Epsilon: Probe dielectric along port line
    Epsilon-->>Test: Fibre core edge positions
    Test->>Test: Compare core centre with port centre
    alt within derived tolerance
        Test-->>Test: Pass at 10 and 20 degrees
    else outside tolerance
        Test-->>Test: Fail for stale port offset
    end
Loading

Flow diagram for corrected fibre port placement

flowchart TD
    A[Build full layer stack] --> B[Compute fiber_port_y once]
    B --> C[Compute fiber_port_x_offset_from_angle]
    C --> D[Create fiber_port_center]
    D --> E[Fibre port follows tilted fibre axis]
Loading

File-Level Changes

Change Details Files
Compute the fibre port height once using the complete stack below the port, ensuring the x offset and port center refer to the same physical height.
  • Includes PML, substrate, box, core, cladding, air gap, and port offset in the initial height calculation.
  • Removes the later duplicate height calculation so the existing angle-derived x offset remains consistent with the port position.
gplugins/gmeep/get_simulation_grating_fiber.py
Add an angle-parametrized geometry test that validates the port against the simulated fibre dielectric rather than port-construction variables.
  • Samples epsilon along the fibre monitor line to locate the core center independently.
  • Checks port alignment at 10° and 20° using a tolerance derived from monitor standoff and spatial resolution.
  • Initializes the simulation before probing its built geometry.
gplugins/gmeep/test_get_simulation_grating_fiber.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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@Alisama20

Copy link
Copy Markdown
Contributor Author

@joamatab could you add a label here when you get a chance? require_label
is the only failing check - it needs one of bug/enhancement/maintenance
and I do not have permission to set labels on this repo. bug seems right.

Everything else is green, including Test meep, which runs the new test this
PR adds.

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.

1 participant