gdsfactory / kfactory

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

module 'kfactory' has no attribute 'LayerEnum' #474

Closed whutwu closed 1 month ago

whutwu commented 1 month ago
import kfactory as kf

class LAYER(kf.LayerEnum):
    SI = (1, 0)
    SIEXCLUDE = (1, 1)

si_enc = kf.utils.LayerEnclosure([(LAYER.SIEXCLUDE, 2000)])

Traceback (most recent call last): File "e:\Develop\Python\gds_factory_test\test.py", line 12, in class LAYER(kf.LayerEnum): ^^^^^^^^^^^^ AttributeError: module 'kfactory' has no attribute 'LayerEnum'

sebastian-goeldi commented 1 month ago

Hi,

The syntax slightly changed for defining layers. Kfactory now recommends to define layers as kf.LayerInfos. I hid the LayerEnum as not directly exposed anymore, as the internal functions will not allow the usage through LayerEnum anymore.

New recommemded Way

# Define Layers

class LayerInfos(kf.LayerInfos):
    WG: kf.kdb.LayerInfo = kf.kdb.LayerInfo(1,0)
    WGEX: kf.kdb.LayerInfo = kf.kdb.LayerInfo(2,0) # WG Exclude
    CLAD: kf.kdb.LayerInfo = kf.kdb.LayerInfo(4,0) # cladding
    FLOORPLAN: kf.kdb.LayerInfo = kf.kdb.LayerInfo(10,0)

# Make the layout object aware of the new layers:
LAYER = LayerInfos()
kf.kcl.infos = LAYER

Kfactory provided cell functions (kf.cells. and by extension kf.factories will use c.kcl.find_layer(layer_info) to get the layer index. This allows to avoid using undefined layers in the layout (kfactory's overloaded find_layer will throw an error instead of return None). To define the layerinfos, one can either use the syntax mentioned above or define it in the initialization of the KCLayout by passing it to KCLayout(..., infos=MyLayerInfos)

The advantage of this change is persistence into the meta infos. So instead of something like kfactory:settings:layer with value 5 you will get an actual klayout klayout.dbcore.LayerInfo object which is defined something like this: WG (1/0)

Tutorials for kfactory are also available https://gdsfactory.github.io/kfactory/notebooks/00_geometry/ and might givea bit more explanation.

Keep usage of LayerEnum

You can still keep using the LayerEnum it is now just not exposed anymore. So you need to change kf.LayerEnum to kf.kcell.LayerEnum or use from kfactory.kcell import LayerEnum.

I realize now this was probably too drastic of a change. I will re-expose the LayerEnum and make it available as kf.LayerEnum, but it might take a few days. I am currently on vacation in China, so availability is lower than usual ;)

whutwu commented 1 month ago

Thanks for your reply, and welcome to China😁

sebastian-goeldi commented 1 month ago

Thanks, looking forward to it every year ^^

Let me know if you encounter other problems. I somewhat intentionally left a lot of the documentation rather short, mainly in order to not impose too much of my (biased) views. But I am happy to elaborate more on choices and quirks of kfactory.

sebastian-goeldi commented 1 month ago

Fixed in v0.20.6