<jupyter_start><jupyter_text>Find coupling vs gap<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import meep as mp
import gdsfactory.simulation.mods as gm
mode_solver = gm.get_mode_solver_coupler(wg_widths=(0.5, 0.5), gaps=(0.2,), ncore=3.47, nclad=1.44, wg_thickness=.22, res=20, sz=6, nmodes=4)
modes = gm.find_modes(mode_solver=mode_solver, parity=mp.NO_PARITY)
m1 = modes[1]
m2 = modes[2]
m3 = modes[3]
m1.plot_eps()
m1.plot_e()
m1.plot_ey()
m2.plot_ey()
df = gm.coupler.find_coupling_vs_gap_strip()
gm.plot_coupling_vs_gap(df)
plt.title('strip 500x200 coupling')
df = gm.coupler.find_coupling_vs_gap_nitride()
gm.plot_coupling_vs_gap(df)
plt.title('nitride 1000x400 nitride')<jupyter_output><empty_output><jupyter_text>What's going on under the hood?<jupyter_code>ne = []
no = []
gap_to_modes = {}

for gap in gaps:
    mode_solver = gm.get_mode_solver_coupler(wg_widths=(0.5, 0.5), gaps=(gap,), ncore=3.47, nclad=1.44, wg_thickness=.22, res=20, sz=6, nmodes=4)
    modes = gm.find_modes(mode_solver=mode_solver, parity=mp.NO_PARITY)
    ne.append(modes[1].neff)
    no.append(modes[2].neff)
    gap_to_modes[gap] = modes
gap_to_modes
import numpy as np

def coupling_length(
    neff1: float,
    neff2: float,
    power_ratio: float = 1.0,
    wavelength: float = 1.55,
) -> float:
    """
    Returns the coupling length (um) of the directional coupler
    to achieve power_ratio

    Args:
        wavelength: in um
        neff1: even supermode of the directional coupler.
        neff2: odd supermode of the directional coupler.
        power_ratio: p2/p1, where 1 means 100% power transfer

    """
    dneff = (neff1 - neff2).real
    return wavelength / (np.pi * dneff) * np.arcsin(np.sqrt(power_ratio))

lc = [coupling_length(neff1=neff1, neff2=neff2) for gap, neff1, neff2 in zip(gaps, ne, no)]
plt.plot(gaps, lc, '.-')
plt.ylabel('100% coupling length (um)')
plt.xlabel('gap (um)')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13470437017994857, 'fraction_numerical': 0.043701799485861184, 'mean_word_length': 4.591954022988506, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '230493', 'license': 'MIT', 'n_tokens_mistral': 876, 'n_tokens_neox': 798, 'n_words': 165, 'path': 'docs/notebooks/plugins/mpb/002_mpb_coupler.ipynb', 'repo_name': 'gdsfactory/gdsfactory', 'size': '1945'}