<jupyter_start><jupyter_text>Plugins Lumerical FDTD Sparametersgdsfactory provides you with a Lumerical FDTD interface to calculate Sparameters automatically (without you having to click around the Lumerical GUI)The function `gdsfactory.simulation.write_sparameters_lumerical` brings up a GUI, runs simulation and then writes the Sparameters both in .CSV and .DAT (Lumerical interconnect / simphony) file formats, as well as the simulation settings in YAML format.In the CSV format each Sparameter will have 2 columns, `S12m` where `m` stands for magnitude and `S12a` where `a` stands for angle in radians. (S11a, S11m, ...)For the simulation to work well, your components need to have ports, that will be extended automatically to go over the PML.![FDTD](https://i.imgur.com/dHAzZRw.png)The script calls internally the lumerical python API `lumapi` so you will need to make sure that you can run this from python.```pythonimport lumapisession = luampi.FDTD()```In linux that may require you to export the PYTHONPATH variable in your shell environment.You can add one line into your `.bashrc` in your Linux machine. This line will depend also on your Lumerical version. For example for Lumerical 2019b```bash[ -d "/opt/lumerical/2019b" ] && export PATH=$PATH:/opt/lumerical/2019b/bin && export PYTHONPATH=/opt/lumerical/2019b/api/python```And for 2021v212```bash[ -d "/opt/lumerical/v212" ] && export PATH=$PATH:/opt/lumerical/v212/api/python/bin && export PYTHONPATH=/opt/lumerical/v212/api/python``` I reccommend that you adapt this functions with your :- simulation settings (wavelength range, mesh)- LayerStack: GDS layer and thickness/material/zmin of each layer- dirpath: directory path to write and read the Sparameters<jupyter_code>import gdsfactory as gf
import gdsfactory.simulation as sim
import gdsfactory.samples.pdk.fab_c as pdk

write_sparameters_lumerical = gf.partial(
    sim.write_sparameters_lumerical,
    layer_stack=pdk.LAYER_STACK,
    dirpath=pdk.SPARAMETERS_PATH,
)

plot_sparameters = gf.partial(
    sim.plot.plot_sparameters,
    dirpath=pdk.SPARAMETERS_PATH,
    write_sparameters_function=write_sparameters_lumerical,
)

read_sparameters_pandas = gf.partial(
    sim.read_sparameters_pandas,
    layer_stack=pdk.LAYER_STACK,
    dirpath=pdk.SPARAMETERS_PATH,
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08186126669538991, 'fraction_numerical': 0.017664799655320983, 'mean_word_length': 5.3791208791208796, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '84721', 'license': 'MIT', 'n_tokens_mistral': 785, 'n_tokens_neox': 730, 'n_words': 239, 'path': 'docs/notebooks/09_plugins.ipynb', 'repo_name': 'tvt173/gdsfactory', 'size': '2321'}