BYUCamachoLab / simphony

A simulator for photonic integrated circuits.
https://simphonyphotonics.rtfd.io
Other
117 stars 35 forks source link

Layout aware example fails. #83

Closed bartvpelt closed 1 year ago

bartvpelt commented 1 year ago

This example fails to run, console output shown below.

C:\**\simphony_tutorials>py layout_aware.py
2023-02-10 15:32:28.925 | INFO     | gdsfactory.config:<module>:51 - Load 'C:\\Program Files\\Python310\\lib\\site-packages\\gdsfactory' 6.36.1
2023-02-10 15:32:28.998 | INFO     | gdsfactory.technology.layer_views:__init__:779 - Importing LayerViews from KLayout layer properties file: C:\Program Files\Python310\lib\site-packages\gdsfactory\generic_tech\klayout\tech\layers.lyp.
Traceback (most recent call last):
  File "C:\**\simphony_tutorials\layout_aware.py", line 79, in <module>
    c = mzi()
  File "C:\Program Files\Python310\lib\site-packages\gdsfactory\cell.py", line 161, in _cell
    component = func(*args, **kwargs)
  File "pydantic\decorator.py", line 40, in pydantic.decorator.validate_arguments.validate.wrapper_function
    from contextlib import _GeneratorContextManager
  File "pydantic\decorator.py", line 134, in pydantic.decorator.ValidatedFunction.call

  File "pydantic\decorator.py", line 206, in pydantic.decorator.ValidatedFunction.execute

  File "C:\**\simphony_tutorials\layout_aware.py", line 37, in mzi
    ysplit = c << ysplitter.component
AttributeError: 'YBranch' object has no attribute 'component'

The issue seems to be that none of the defined siepic elements have a 'component' attribute. Looking at the source code the cause for this seems to be that _has_gf = False, this flag is set by the snippet below.

try:
    import gdsfactory as gf
    from gdsfactory.types import Route
    _has_gf = True
except ImportError:
    _has_gf = False

Manually running this snippet, I'm getting _has_gf = True, so I'm kind of confident that my gdsfactory setup works fine. Is there a bug in the current version of the example, or is my installation bugged?

Kind regards

bartvpelt commented 1 year ago

Well, this is embarrassing. After spending multiple hours on this and eventually posting this issue, it took me only five minutes to look at the pip install output again and notice that the gdspy built actually did fail. As a result, SiPANN also did not install, oops...

If this is the root cause of my error, it's weird that it surfaces as an AttributeError on ysplitter.component. An ImportError would have been more helpful here for those just setting up simphony, maybe there's room for improvement here.

I'll see if installing gdspy properly fixes the issue.

sequoiap commented 1 year ago

Thanks for the heads up, @bartvpelt. I'll take a look at the errors raised and see if I can make it more informative.

SkandanC commented 1 year ago

Hello,

Thanks for this issue, we can set it so that it throws an error if gdsfactory is not installed. Are you using the latest version of gdsfactory? Note that the latest version uses gdstk, and you shouldn't get errors installing that.

sequoiap commented 1 year ago

@SkandanC This file is simply a example file, correct? Because simphony doesn't depend on gdsfactory unless you want to use this feature, right? Perhaps the example script alone should do an import check. Also, in the "extras_require" in the setup script, perhaps we specify a minimum version of gdsfactory.

@bartvpelt One of the things about gdsfactory is that it is incredibly...unstable? It's constantly getting updates and moves so fast from version to version, it can sometimes be hard to keep up. (Just look at the release history on PyPI.) Great software, just in a constant state of flux.

bartvpelt commented 1 year ago

I'm using gdsfactory version 6.36.1 and gdstk version 0.9.36. I can import both just fine, as indicated by the _has_gf flag. Whether my missing SiPANN and gdspy are the root cause of the problem is still a question to me. When I get approval to compile gdspy from source I'll let you know whether it gets solved.

I could try reverting to an older version of gdsfactory, maybe an update broke something. What is the latest version that you've tested, 6.36.1?

SkandanC commented 1 year ago

This file is simply a example file, correct? Because simphony doesn't depend on gdsfactory unless you want to use this feature, right? Perhaps the example script alone should do an import check. Also, in the "extras_require" in the setup script, perhaps we specify a minimum version of gdsfactory

Yep, but I don't think we need to specify a minimum version, the recommended version to use is always the latest, and using an older version would be not ideal since its very different from the newer version.

Whether my missing SiPANN and gdspy are the root cause of the problem is still a question to me. Unless you are using SiPANN components, it's not.