<jupyter_start><jupyter_text>Circuit simulations`get_netlist()` returns a dict with all the instance settings and connections for a ComponentThere is another repo [gdslib](https://github.com/gdsfactory/gdslib) that stores all gdsfactory Sparameters (from Lumerical 3D FDTD simulations) and compact models (from [SiPANN library](https://sipann.readthedocs.io/en/latest/)) and allows you to do circuit simulations with [Simphony](https://github.com/BYUCamachoLab/simphony) MZI<jupyter_code>import pp
import gdslib as gl
from simphony.netlist import Subcircuit

delta_length = 10
DL = delta_length/2
c = pp.c.mzi(DL=DL) 
pp.qp(c)

n = c.get_netlist()<jupyter_output><empty_output><jupyter_text>`gdslib` has also an MZI model. However we can make sure we get the exact cells from the component<jupyter_code>m = gl.components.mzi(DL=DL)
gl.plot_circuit(m)<jupyter_output><empty_output><jupyter_text>In this first case we are going to use Sparameters from Lumerical simulations stored in gdslib.Some simulations (such as waveguides with different lengths and bends with 10um bend radius) may be missing so we ignore all the settings and will use the defaults (bends with `radius = 5` and waveguides with `length = 10`<jupyter_code>component = pp.c.mzi()
circuit = Subcircuit(component.name)
n = component.get_netlist()

model_name_tuple = []
for i in n.instances.keys():
    component_type = n.instances[i]['component']
    component_settings = n.instances[i]['settings']
    c = pp.c.component_type2factory[component_type]() # ignore settings
    #c = pp.c.component_type2factory[component_type](**component_settings) # needs fix
    model = gl.model_from_gdsfactory(c)
    model_name_tuple.append((model, i))
    
e = circuit.add(model_name_tuple)

for k, v in n.connections.items():
    c1, p1 = k.split(',')
    c2, p2 = v.split(',')
    circuit.connect(c1, p1, c2, p2)

circuit.elements["mmi1x2_12_0"].pins["W0"] = "input"
circuit.elements["mmi1x2_88_0"].pins["W0"] = "output"

gl.plot_circuit(circuit)<jupyter_output><empty_output><jupyter_text>It is hard to capture all possible variations by doing lots of lumerical simulations. That is why component Compact models from `gdslib` are powerful.<jupyter_code>component = pp.c.mzi()
circuit = Subcircuit(component.name)
n = component.get_netlist()

model_name_tuple = []
for i in n.instances.keys():
    component_type = n.instances[i]['component']
    component_settings = n.instances[i]['settings']
    model = gl.component_type2factory[component_type](**component_settings)
    model_name_tuple.append((model, i))
    
e = circuit.add(model_name_tuple)

for k, v in n.connections.items():
    c1, p1 = k.split(',')
    c2, p2 = v.split(',')
    circuit.connect(c1, p1, c2, p2)

circuit.elements["mmi1x2_12_0"].pins["W0"] = "input"
circuit.elements["mmi1x2_88_0"].pins["W0"] = "output"

gl.plot_circuit(circuit)
delta_length = 100
DL = delta_length/2
c = pp.c.mzi(DL=DL) 
pp.qp(c)
m = gl.circuit_from_gdsfactory(c)
m.elements["mmi1x2_12_0"].pins["W0"] = "input"
m.elements["mmi1x2_88_0"].pins["W0"] = "output"
gl.plot_circuit(m)
for e in m.elements:
    print(e)<jupyter_output><empty_output><jupyter_text>Ring resonatorThis is work in progress and still has some issues. FIXME!<jupyter_code>import pp
import gdslib as gl
from simphony.netlist import Subcircuit

c = pp.c.ring_single(length_x=4, gap=0.2, bend_radius=5)
pp.qp(c)
m = gl.circuit_from_gdsfactory(c)
for e in m.elements:
    print(e)
m = gl.circuit_from_gdsfactory(c)
m.elements["coupler_ring_05cda304_-2_1"].pins["W0"] = "input"
m.elements["coupler_ring_05cda304_-2_1"].pins["E0"] = "output"
gl.plot_circuit(m)
component = c
circuit = Subcircuit(component.name)
n = component.get_netlist()

model_name_tuple = []
for i in n.instances.keys():
    component_type = n.instances[i]['component']
    component_settings = n.instances[i]['settings']
    print(component_type, component_settings)
    model = gl.component_type2factory[component_type](**component_settings)
    model_name_tuple.append((model, i))
    
e = circuit.add(model_name_tuple)

for k, v in n.connections.items():
    c1, p1 = k.split(',')
    c2, p2 = v.split(',')
    circuit.connect(c1, p1, c2, p2)

circuit.elements["coupler_ring_05cda304_-2_1"].pins["W0"] = "input"
circuit.elements["coupler_ring_05cda304_-2_1"].pins["E0"] = "output"
gl.plot_circuit(circuit)
import matplotlib.pyplot as plt

for e in m.elements:
    continue
    plt.figure()
    plt.title(e)
    gl.plot_model(e.model)
print(n.connections.pretty())
import pp
import gdslib as gl
from simphony.netlist import Subcircuit
#from pp.config import connections

#connections.clear()
c = pp.c.ring_double(length_y=10)
m = gl.circuit_from_gdsfactory(c)
for e in m.elements:
    print(e)
from pp.config import connections
connections
m.elements["coupler_ring_8a8f8eb7_-2_1"].pins["W0"] = "input"
m.elements["coupler_ring_8a8f8eb7_-2_1"].pins["E0"] = "output"
gl.plot_circuit(m)
m.netlist.nets<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1328769881216026, 'fraction_numerical': 0.025971411314676868, 'mean_word_length': 5.4941176470588236, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 3, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '80511', 'license': 'MIT', 'n_tokens_mistral': 1907, 'n_tokens_neox': 1812, 'n_words': 394, 'path': 'notebooks/07_circuit_simulations.ipynb', 'repo_name': 'PsiQ/gdsfactory', 'size': '4967'}