gdsfactory / kfactory

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

Euler bend pcells not snapping to grid #408

Closed akshat-ja closed 6 days ago

akshat-ja commented 1 week ago

Describe the bug Euler bend pcells bend_euler_factory and bend_s_euler_factory are breaking due to a raised exception width needs to be even to snap to grid. Got {width}.

Expected behavior There's a width snap to grid expected somewhere in these functions that is not happening and thus causing this violation.

Command line output

Traceback (most recent call last):
  File "...", line 313, in <module>
    <function>
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/kcell.py", line 3186, in wrapper_autocell
    _cell = wrapped_cell(**params)
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/cachetools/__init__.py", line 737, in wrapper
    v = func(*args, **kwargs)
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/kcell.py", line 3080, in wrapped_cell
    cell = f(**params)
  File "...", line 200, in <function>
    <function>
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/kcell.py", line 3186, in wrapper_autocell
    _cell = wrapped_cell(**params)
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/cachetools/__init__.py", line 737, in wrapper
    v = func(*args, **kwargs)
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/kcell.py", line 3080, in wrapped_cell
    cell = f(**params)
  File "...", line 478, in <function>
    <function>
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/kcell.py", line 3186, in wrapper_autocell
    _cell = wrapped_cell(**params)
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/cachetools/__init__.py", line 737, in wrapper
    v = func(*args, **kwargs)
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/kcell.py", line 3080, in wrapped_cell
    cell = f(**params)
  File "...", line 1192, in <function>
    <function>
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/kcell.py", line 3186, in wrapper_autocell
    _cell = wrapped_cell(**params)
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/cachetools/__init__.py", line 737, in wrapper
    v = func(*args, **kwargs)
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/kcell.py", line 3080, in wrapped_cell
    cell = f(**params)
  File "...", line 340, in <function>
    <function>
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/kcell.py", line 3186, in wrapper_autocell
    _cell = wrapped_cell(**params)
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/cachetools/__init__.py", line 737, in wrapper
    v = func(*args, **kwargs)
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/kcell.py", line 3080, in wrapped_cell
    cell = f(**params)
  File "...", line 194, in <function>
    <function>
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/kcell.py", line 3186, in wrapper_autocell
    _cell = wrapped_cell(**params)
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/cachetools/__init__.py", line 737, in wrapper
    v = func(*args, **kwargs)
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/kcell.py", line 3080, in wrapped_cell
    cell = f(**params)
  File "...", line 82, in <function>
    <function>
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/kcell.py", line 3186, in wrapper_autocell
    _cell = wrapped_cell(**params)
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/cachetools/__init__.py", line 737, in wrapper
    v = func(*args, **kwargs)
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/kcell.py", line 3080, in wrapped_cell
    cell = f(**params)
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/factories/euler.py", line 308, in bend_euler
    c.create_port(
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/kcell.py", line 1209, in create_port
    return self.ports.create_port(**kwargs)
  File "/opt/anaconda3/envs/projectvenv/lib/python3.10/site-packages/kfactory/kcell.py", line 6403, in create_port
    raise ValueError(f"width needs to be even to snap to grid. Got {width}")
ValueError: width needs to be even to snap to grid. Got 1
sebastian-goeldi commented 1 week ago

Are you by chance messing up the dbu/um conversion?

Your euler bend you are presenting here would have width == 1dbu (1nm in default). I assume you want something like 1000 (i.e. 1um).

The standard kfactory cell functions use um for bends and other path extruded cells

You can see this from the type annotations

https://github.com/gdsfactory/kfactory/blob/2e8612db42b7da756ff84eafd6ab9a667d695de8/src/kfactory/factories/euler.py#L389

It's a bit hard to see because it's factories of factories, but the new kf_types annotations should indicate what is expected as a unit

akshat-ja commented 6 days ago

Figured it out, there was a there was a width*1e-3 in the code. Closing issue.