prefab 1.1.0__tar.gz → 1.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. {prefab-1.1.0 → prefab-1.1.2}/.github/workflows/docs-deploy.yml +1 -1
  2. {prefab-1.1.0 → prefab-1.1.2}/CHANGELOG.md +28 -1
  3. {prefab-1.1.0 → prefab-1.1.2}/PKG-INFO +12 -12
  4. prefab-1.1.2/README.md +73 -0
  5. prefab-1.1.2/docs/assets/blog-cards/python-for-photonics.png +0 -0
  6. prefab-1.1.2/docs/assets/logo.png +0 -0
  7. prefab-1.1.2/docs/assets/promo_c.png +0 -0
  8. prefab-1.1.2/docs/assets/promo_p.png +0 -0
  9. prefab-1.1.2/docs/blog/python-for-photonics.md +326 -0
  10. prefab-1.1.2/docs/examples/4_SEM_generation.ipynb +277 -0
  11. {prefab-1.1.0 → prefab-1.1.2}/docs/index.md +4 -1
  12. prefab-1.1.2/docs/reference/shapes.md +3 -0
  13. {prefab-1.1.0 → prefab-1.1.2}/mkdocs.yml +9 -5
  14. {prefab-1.1.0 → prefab-1.1.2}/prefab/__init__.py +1 -1
  15. {prefab-1.1.0 → prefab-1.1.2}/prefab/compare.py +17 -0
  16. {prefab-1.1.0 → prefab-1.1.2}/prefab/device.py +12 -13
  17. {prefab-1.1.0 → prefab-1.1.2}/prefab/geometry.py +43 -1
  18. {prefab-1.1.0 → prefab-1.1.2}/prefab/read.py +5 -1
  19. {prefab-1.1.0 → prefab-1.1.2}/prefab/shapes.py +208 -201
  20. {prefab-1.1.0 → prefab-1.1.2}/pyproject.toml +2 -2
  21. prefab-1.1.0/README.md +0 -73
  22. prefab-1.1.0/docs/assets/logo.png +0 -0
  23. prefab-1.1.0/site/assets/promo_c.png +0 -0
  24. prefab-1.1.0/site/assets/promo_p.png +0 -0
  25. {prefab-1.1.0 → prefab-1.1.2}/.gitattributes +0 -0
  26. {prefab-1.1.0 → prefab-1.1.2}/.github/workflows/python-publish.yml +0 -0
  27. {prefab-1.1.0 → prefab-1.1.2}/.gitignore +0 -0
  28. {prefab-1.1.0 → prefab-1.1.2}/LICENSE +0 -0
  29. {prefab-1.1.0 → prefab-1.1.2}/docs/CNAME +0 -0
  30. {prefab-1.1.0 → prefab-1.1.2}/docs/assets/favicon.ico +0 -0
  31. {prefab-1.1.0 → prefab-1.1.2}/docs/assets/prefab_logo_white.svg +0 -0
  32. /prefab-1.1.0/docs/blog/PreFab-v1.0.0.ipynb → /prefab-1.1.2/docs/blog/PreFab-v1.1.0.ipynb +0 -0
  33. {prefab-1.1.0 → prefab-1.1.2}/docs/examples/1_prediction.ipynb +0 -0
  34. {prefab-1.1.0 → prefab-1.1.2}/docs/examples/2_correction.ipynb +0 -0
  35. {prefab-1.1.0 → prefab-1.1.2}/docs/examples/3_sidewall_angle.ipynb +0 -0
  36. {prefab-1.1.0 → prefab-1.1.2}/docs/models.md +0 -0
  37. {prefab-1.1.0 → prefab-1.1.2}/docs/reference/compare.md +0 -0
  38. {prefab-1.1.0 → prefab-1.1.2}/docs/reference/device.md +0 -0
  39. {prefab-1.1.0 → prefab-1.1.2}/docs/reference/geometry.md +0 -0
  40. {prefab-1.1.0 → prefab-1.1.2}/docs/reference/models.md +0 -0
  41. {prefab-1.1.0 → prefab-1.1.2}/docs/reference/read.md +0 -0
  42. {prefab-1.1.0 → prefab-1.1.2}/prefab/__main__.py +0 -0
  43. {prefab-1.1.0 → prefab-1.1.2}/prefab/models.py +0 -0
  44. {prefab-1.1.0 → prefab-1.1.2}/site/404.html +0 -0
  45. {prefab-1.1.0 → prefab-1.1.2}/site/assets/_mkdocstrings.css +0 -0
  46. {prefab-1.1.0 → prefab-1.1.2}/site/assets/favicon.ico +0 -0
  47. {prefab-1.1.0 → prefab-1.1.2}/site/assets/images/favicon.png +0 -0
  48. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/bundle.a7c05c9e.min.js +0 -0
  49. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/bundle.a7c05c9e.min.js.map +0 -0
  50. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.ar.min.js +0 -0
  51. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.da.min.js +0 -0
  52. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.de.min.js +0 -0
  53. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.du.min.js +0 -0
  54. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.el.min.js +0 -0
  55. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.es.min.js +0 -0
  56. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.fi.min.js +0 -0
  57. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.fr.min.js +0 -0
  58. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.he.min.js +0 -0
  59. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.hi.min.js +0 -0
  60. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.hu.min.js +0 -0
  61. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.hy.min.js +0 -0
  62. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.it.min.js +0 -0
  63. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.ja.min.js +0 -0
  64. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.jp.min.js +0 -0
  65. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.kn.min.js +0 -0
  66. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.ko.min.js +0 -0
  67. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.multi.min.js +0 -0
  68. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.nl.min.js +0 -0
  69. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.no.min.js +0 -0
  70. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.pt.min.js +0 -0
  71. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.ro.min.js +0 -0
  72. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.ru.min.js +0 -0
  73. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.sa.min.js +0 -0
  74. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.stemmer.support.min.js +0 -0
  75. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.sv.min.js +0 -0
  76. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.ta.min.js +0 -0
  77. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.te.min.js +0 -0
  78. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.th.min.js +0 -0
  79. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.tr.min.js +0 -0
  80. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.vi.min.js +0 -0
  81. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/min/lunr.zh.min.js +0 -0
  82. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/tinyseg.js +0 -0
  83. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/lunr/wordcut.js +0 -0
  84. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/workers/search.b8dbb3d2.min.js +0 -0
  85. {prefab-1.1.0 → prefab-1.1.2}/site/assets/javascripts/workers/search.b8dbb3d2.min.js.map +0 -0
  86. {prefab-1.1.0 → prefab-1.1.2}/site/assets/logo.png +0 -0
  87. {prefab-1.1.0 → prefab-1.1.2}/site/assets/logo_neue.svg +0 -0
  88. {prefab-1.1.0/docs → prefab-1.1.2/site}/assets/promo_c.png +0 -0
  89. {prefab-1.1.0/docs → prefab-1.1.2/site}/assets/promo_p.png +0 -0
  90. {prefab-1.1.0 → prefab-1.1.2}/site/assets/stylesheets/main.66ac8b77.min.css +0 -0
  91. {prefab-1.1.0 → prefab-1.1.2}/site/assets/stylesheets/main.66ac8b77.min.css.map +0 -0
  92. {prefab-1.1.0 → prefab-1.1.2}/site/assets/stylesheets/palette.06af60db.min.css +0 -0
  93. {prefab-1.1.0 → prefab-1.1.2}/site/assets/stylesheets/palette.06af60db.min.css.map +0 -0
  94. {prefab-1.1.0 → prefab-1.1.2}/site/css/ansi-colours.css +0 -0
  95. {prefab-1.1.0 → prefab-1.1.2}/site/css/jupyter-cells.css +0 -0
  96. {prefab-1.1.0 → prefab-1.1.2}/site/css/pandas-dataframe.css +0 -0
  97. {prefab-1.1.0 → prefab-1.1.2}/site/examples/1_prediction/index.html +0 -0
  98. {prefab-1.1.0 → prefab-1.1.2}/site/examples/2_correction/index.html +0 -0
  99. {prefab-1.1.0 → prefab-1.1.2}/site/index.html +0 -0
  100. {prefab-1.1.0 → prefab-1.1.2}/site/models/index.html +0 -0
  101. {prefab-1.1.0 → prefab-1.1.2}/site/objects.inv +0 -0
  102. {prefab-1.1.0 → prefab-1.1.2}/site/reference/compare/index.html +0 -0
  103. {prefab-1.1.0 → prefab-1.1.2}/site/reference/device/index.html +0 -0
  104. {prefab-1.1.0 → prefab-1.1.2}/site/reference/geometry/index.html +0 -0
  105. {prefab-1.1.0 → prefab-1.1.2}/site/reference/models/index.html +0 -0
  106. {prefab-1.1.0 → prefab-1.1.2}/site/reference/read/index.html +0 -0
  107. {prefab-1.1.0 → prefab-1.1.2}/site/search/search_index.json +0 -0
  108. {prefab-1.1.0 → prefab-1.1.2}/site/sitemap.xml +0 -0
  109. {prefab-1.1.0 → prefab-1.1.2}/site/sitemap.xml.gz +0 -0
@@ -26,7 +26,7 @@ jobs:
26
26
  restore-keys: |
27
27
  mkdocs-material-
28
28
  - run: pip install mkdocs
29
- - run: pip install mkdocs-material
29
+ - run: pip install mkdocs-material[imaging]
30
30
  - run: pip install mkdocstrings[python]
31
31
  - run: pip install mknotebooks
32
32
  - name: Create CNAME file
@@ -1,6 +1,33 @@
1
1
  # Changelog
2
2
 
3
- ## 1.1.0 - 2024-09-23
3
+ ## 1.1.2 - 2024-10-10
4
+
5
+ ### Added
6
+
7
+ - User warning if `compare.intersection_over_union`, `compare.hamming_distance`, or `compare.dice_coefficient` are called with non-binarized devices.
8
+ - Added `height` parameter to many shape constructors in `prefab.shapes` to give more flexibility.
9
+
10
+ ### Changed
11
+
12
+ - Updates to the `README.md` to keep current.
13
+ - `Device.is_binary` is now a property.
14
+ - Moved `Device.enforce_feature_size` logic to `prefab.geometry` module.
15
+
16
+ ### Fixed
17
+
18
+ - Added required version of `gdstk` to `pyproject.toml`.
19
+ - Removed leftover return statement in `geometry.rotate`.
20
+
21
+ ## 1.1.1 - 2024-09-24
22
+
23
+ ### Changed
24
+
25
+ - Manually adding small random noise to the semulated images to better match the real data. This is ideally included in the model training, but for now this is a quick fix.
26
+ - Added z-padding to the device array before exporting to STL with `Device.to_stl` to ensure that the exported device is closed.
27
+
28
+ ### Fixed
29
+
30
+ - Removed buffer from `Device.device_array` before exporting to with `Device.to_gdsfactory`.
4
31
 
5
32
  ### Added
6
33
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: prefab
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: Artificial nanofabrication of integrated photonic circuits using deep learning
5
5
  Project-URL: Homepage, https://prefabphotonics.com
6
6
  Project-URL: Repository, https://github.com/PreFab-Photonics/PreFab
@@ -516,7 +516,7 @@ Classifier: License :: OSI Approved :: GNU Lesser General Public License v2 (LGP
516
516
  Classifier: Operating System :: OS Independent
517
517
  Classifier: Programming Language :: Python :: 3
518
518
  Requires-Python: >=3.9
519
- Requires-Dist: gdstk
519
+ Requires-Dist: gdstk>=0.9.55
520
520
  Requires-Dist: matplotlib
521
521
  Requires-Dist: numpy
522
522
  Requires-Dist: opencv-python-headless
@@ -533,23 +533,23 @@ Description-Content-Type: text/markdown
533
533
 
534
534
  ![PreFab logo](https://github.com/PreFab-Photonics/PreFab/blob/main/docs/assets/logo.png?raw=true)
535
535
 
536
- PreFab leverages **deep learning** to model fabrication-induced structural variations in integrated photonic devices. Through this _virtual nanofabrication environment_, we uncover valuable insights into nanofabrication processes and enhance device design accuracy.
536
+ PreFab is a _virtual nanofabrication environment_ that leverages **deep learning** and **computer vision** to predict and correct for structural variations in integrated photonic devices during nanofabrication.
537
537
 
538
538
  ## Prediction
539
539
 
540
- PreFab accurately predicts process-induced structural alterations such as corner rounding, washing away of small lines and islands, and filling of narrow holes in planar photonic devices. This enables designers to quickly prototype expected performance and rectify designs prior to nanofabrication.
540
+ PreFab predicts process-induced structural variations, including corner rounding, loss of small lines and islands, filling of narrow holes and channels, sidewall angle deviations, and stochastic effects. This allows designers to rapidly prototype and evaluate expected performance pre-fabrication.
541
541
 
542
542
  ![Example of PreFab prediction](https://github.com/PreFab-Photonics/PreFab/blob/main/docs/assets/promo_p.png?raw=true)
543
543
 
544
544
  ## Correction
545
545
 
546
- PreFab automates corrections to device designs, ensuring the fabricated outcome aligns with the original design. This results in reduced structural variation and performance disparity from simulation to experiment.
546
+ PreFab corrects device designs to ensure that the fabricated outcome closely matches the intended specifications. This minimizes structural variations and reduces performance discrepancies between simulations and actual experiments.
547
547
 
548
548
  ![Example of PreFab correction](https://github.com/PreFab-Photonics/PreFab/blob/main/docs/assets/promo_c.png?raw=true)
549
549
 
550
550
  ## Models
551
551
 
552
- PreFab accommodates unique _predictor_ and _corrector_ models for each photonic foundry, regularly updated based on recent fabrication data. Current models include (see full list on [`docs/models.md`](https://github.com/PreFab-Photonics/PreFab/blob/main/docs/models.md)):
552
+ Each photonic nanofabrication process requires unique models, which are regularly updated with the latest data. The current models include (see the full list in [`docs/models.md`](https://github.com/PreFab-Photonics/PreFab/blob/main/docs/models.md)):
553
553
 
554
554
  | Foundry | Process | Latest Version | Latest Dataset | Model Name |
555
555
  | ------- | ------- | ----------------- | ---------------- | ----------- |
@@ -557,7 +557,7 @@ PreFab accommodates unique _predictor_ and _corrector_ models for each photonic
557
557
  | ANT | SiN | ANF1 (May 6 2024) | d1 (Jan 31 2024) | ANT_SiN_ANF1_d1 |
558
558
  | Generic | DUV-SOI | ANF1 (May 6 2024) | d0 (Jul 30 2024) | generic_DUV_SOI_ANF1_d0 |
559
559
 
560
- > _New models and foundries are to be regularly added. Usage may change. For additional foundry and process models, feel free to contact us._
560
+ > _New models are to be regularly added. Usage may change. For additional foundry and process models, feel free to [contact us](mailto:hi@prefabphotonics.com) or raise an issue._
561
561
 
562
562
  ## Installation
563
563
 
@@ -581,7 +581,7 @@ pip install -e .
581
581
 
582
582
  Before you can make PreFab requests, you will need to [create an account](https://www.prefabphotonics.com/login).
583
583
 
584
- To link your account, you will need a token. You can do this by running the following command in your terminal. This will open a browser window where you can log in and authenticate your token.
584
+ To link your account, you will need an token. You can do this by running the following command in your terminal. This will open a browser window where you can log in and authenticate your token.
585
585
 
586
586
  ```sh
587
587
  python3 -m prefab setup
@@ -593,11 +593,11 @@ Visit [`/docs/examples`](https://github.com/PreFab-Photonics/PreFab/tree/main/do
593
593
 
594
594
  ## Performance and Usage
595
595
 
596
- PreFab models are served via a serverless cloud platform. Please note:
596
+ PreFab models are hosted on a [serverless cloud platform](https://modal.com/). Please keep in mind:
597
597
 
598
- - 🐢 CPU inference may result in slower performance. Future updates will introduce GPU inference.
599
- - 🥶 The first prediction may take longer due to cold start server loading. Subsequent predictions will be faster.
600
- - 😊 Be considerate of usage. Start small and limit usage during the initial stages. Thank you!
598
+ - 🐢 Default CPU inference may be slower.
599
+ - 🥶 The first prediction using optional GPU inference may take longer due to cold start server loading. Subsequent predictions will be faster.
600
+ - 😊 Please be considerate of usage. Start with small tasks and limit usage during the initial stages. Thank you!
601
601
 
602
602
  ## License
603
603
 
prefab-1.1.2/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # PreFab
2
+
3
+ ![PreFab logo](https://github.com/PreFab-Photonics/PreFab/blob/main/docs/assets/logo.png?raw=true)
4
+
5
+ PreFab is a _virtual nanofabrication environment_ that leverages **deep learning** and **computer vision** to predict and correct for structural variations in integrated photonic devices during nanofabrication.
6
+
7
+ ## Prediction
8
+
9
+ PreFab predicts process-induced structural variations, including corner rounding, loss of small lines and islands, filling of narrow holes and channels, sidewall angle deviations, and stochastic effects. This allows designers to rapidly prototype and evaluate expected performance pre-fabrication.
10
+
11
+ ![Example of PreFab prediction](https://github.com/PreFab-Photonics/PreFab/blob/main/docs/assets/promo_p.png?raw=true)
12
+
13
+ ## Correction
14
+
15
+ PreFab corrects device designs to ensure that the fabricated outcome closely matches the intended specifications. This minimizes structural variations and reduces performance discrepancies between simulations and actual experiments.
16
+
17
+ ![Example of PreFab correction](https://github.com/PreFab-Photonics/PreFab/blob/main/docs/assets/promo_c.png?raw=true)
18
+
19
+ ## Models
20
+
21
+ Each photonic nanofabrication process requires unique models, which are regularly updated with the latest data. The current models include (see the full list in [`docs/models.md`](https://github.com/PreFab-Photonics/PreFab/blob/main/docs/models.md)):
22
+
23
+ | Foundry | Process | Latest Version | Latest Dataset | Model Name |
24
+ | ------- | ------- | ----------------- | ---------------- | ----------- |
25
+ | ANT | NanoSOI | ANF1 (May 6 2024) | d10 (Jun 8 2024) | ANT_NanoSOI_ANF1_d10 |
26
+ | ANT | SiN | ANF1 (May 6 2024) | d1 (Jan 31 2024) | ANT_SiN_ANF1_d1 |
27
+ | Generic | DUV-SOI | ANF1 (May 6 2024) | d0 (Jul 30 2024) | generic_DUV_SOI_ANF1_d0 |
28
+
29
+ > _New models are to be regularly added. Usage may change. For additional foundry and process models, feel free to [contact us](mailto:hi@prefabphotonics.com) or raise an issue._
30
+
31
+ ## Installation
32
+
33
+ Install PreFab via pip:
34
+
35
+ ```sh
36
+ pip install prefab
37
+ ```
38
+
39
+ Or clone the repository and install in development mode:
40
+
41
+ ```sh
42
+ git clone https://github.com/PreFab-Photonics/PreFab.git
43
+ cd PreFab
44
+ pip install -e .
45
+ ```
46
+
47
+ ## Getting Started
48
+
49
+ ### Account setup
50
+
51
+ Before you can make PreFab requests, you will need to [create an account](https://www.prefabphotonics.com/login).
52
+
53
+ To link your account, you will need an token. You can do this by running the following command in your terminal. This will open a browser window where you can log in and authenticate your token.
54
+
55
+ ```sh
56
+ python3 -m prefab setup
57
+ ```
58
+
59
+ ### Guides
60
+
61
+ Visit [`/docs/examples`](https://github.com/PreFab-Photonics/PreFab/tree/main/docs/examples) or our [docs](https://docs.prefabphotonics.com/) to get started with your first predictions.
62
+
63
+ ## Performance and Usage
64
+
65
+ PreFab models are hosted on a [serverless cloud platform](https://modal.com/). Please keep in mind:
66
+
67
+ - 🐢 Default CPU inference may be slower.
68
+ - 🥶 The first prediction using optional GPU inference may take longer due to cold start server loading. Subsequent predictions will be faster.
69
+ - 😊 Please be considerate of usage. Start with small tasks and limit usage during the initial stages. Thank you!
70
+
71
+ ## License
72
+
73
+ This project is licensed under the LGPL-2.1 license. © 2024 PreFab Photonics.
Binary file
Binary file
Binary file
@@ -0,0 +1,326 @@
1
+ # Python for Photonics Development
2
+
3
+ [Python](https://www.python.org/) has become an indispensable tool in many technical fields, including ours. It gives researchers and engineers a versatile platform for simulating, modeling, and analyzing photonic systems, effectively streamlining the **entire development workflow.** With its extensive ecosystem of libraries and tools, Python enables efficient and innovative solutions in photonics that we think are worth exploring.
4
+
5
+ In this guide, we'll walk you through setting up your Python development environment, introduce essential libraries, explore cloud and remote tools to leverage computational resources, share valuable settings for an enhanced coding experience, and provide additional tips to elevate your photonics projects using Python.
6
+
7
+ !!! note "Note"
8
+
9
+ PreFab is developed using Python, and we leverage many Python packages to enhance our development process. This guide is a compilation of resources and insights that have been beneficial in *our* work. While it's not exhaustive, we hope it proves useful to you in your photonics development endeavors.
10
+
11
+ ## Essential Python Libraries for Photonics
12
+
13
+ The Python ecosystem offers a variety of powerful tools specifically designed for photonics design and development. Here are some of the most notable ones:
14
+
15
+ - **[Tidy3D](https://www.flexcompute.com/tidy3d/)**: A commercial cloud-based FDTD solver for simulating electromagnetic fields in photonic structures, offering ultrahigh-speed simulations, an intuitive Python API, and *incredible* documentation and tutorials.
16
+
17
+ - **[Meep](https://meep.readthedocs.io/en/latest/)**: An open-source software package for simulating electromagnetic systems using FDTD, with extensive Python bindings for scripting and automation. Meep also has fantastic documentation and tutorials to help you learn not just how to use the software, but also fundamentals of photonics and electromagnetics.
18
+
19
+ - **[gdsfactory](https://gdsfactory.github.io/gdsfactory/)**: An industry-leading, open-source Python library for designing and automating photonic integrated circuits, facilitating layout generation, verification, and integration with simulation tools. If you are designing photonic integrated circuits with Python, this is a fantastic starting point.
20
+
21
+ - **[KLayout](https://www.klayout.org/klayout-pypi/):** KLayout is a versatile 2D viewer and editor for mask layouts in chip manufacturing. The KLayout Python module extends its functionality, allowing for scripting and automation within the KLayout system.
22
+
23
+ - **[gdstk](https://heitzmann.github.io/gdstk/)**: A Python library for creating and manipulating GDS files, supporting complex geometric operations essential for photonic design.
24
+
25
+ - **[Awesome Photonics](https://github.com/joamatab/awesome_photonics)**: A curated GitHub repository compiling a comprehensive list of photonics tools and resources, many of which are Python-based or compatible with a Python-based workflow. This repository is an excellent starting point to discover new libraries, frameworks, and tools in the photonics domain.
26
+
27
+ ## Setting up Your Integrated Development Environment (IDE)
28
+
29
+ Choosing the right Integrated Development Environment (IDE) is crucial for an efficient and productive workflow in photonics development. Here are three excellent options to consider:
30
+
31
+ - **[Visual Studio Code (VS Code)](https://code.visualstudio.com/)**: Visual Studio Code is a free, open-source IDE developed by Microsoft. It's highly popular due to its versatility (much like Python) and extensive extension marketplace. VS Code offers powerful features like IntelliSense (smart code completion), debugging tools, Git integration, and customizable workspaces, making it an excellent choice for Python development.
32
+
33
+ - **[Cursor](https://cursor.sh/)**: Cursor is an enhanced version (fork) of VS Code, augmented with thoughtful AI tools that assist in code development. With integrated AI capabilities, Cursor can help you write, debug, and optimize your code more efficiently. It provides features like code autocompletion, intelligent code analysis, and automated code refactoring, making it a powerful tool for both beginners and experienced developers.
34
+
35
+ - **[Zed](https://zed.dev/)**: Zed is a new, ultra-fast IDE that focuses on performance and a responsive coding experience. While it is still under active development and may have limited functionality and operating system support, Zed aims to provide a sleek and efficient environment for developers. Its emphasis on speed and minimalism could make it a strong contender as it matures. We recommend keeping a close eye on this IDE as it evolves.
36
+
37
+ For the rest of this guide, we will use VS Code (and therefore Cursor).
38
+
39
+ ### Essential VS Code Extensions for Python Development
40
+
41
+ To further enhance your development experience in VS Code (or Cursor), add these essential extensions (see below for how to install them):
42
+
43
+ - **[Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python)**: The Python extension for VS Code provides rich support for the Python language, including features like IntelliSense, linting, debugging, code navigation, code formatting, and testing. It is maintained by Microsoft and is one of the most installed extensions for Python development.
44
+
45
+ - **[Jupyter](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter)**: The Jupyter extension for VS Code allows you to work with Jupyter Notebooks directly within VS Code, offering an interactive environment for data analysis, visualization, and computational experimentation. We love Jupyter for rapidly prototyping and exploring new ideas, and this extension makes working with them in VS Code a pleasure.
46
+
47
+ - **[Ruff](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff)**: The Ruff extension for VS Code is a fast, highly configurable linter (code quality check) and formatter for Python, designed to help you maintain code quality and adhere to coding standards. It is so fast that it can run in the background while you code, and it will notify you of any issues in your code as you save your file (which we will configure later in this guide). We also love Ruff because it is opinionated and enforces a consistent style guide, which can help you focus on what really matters and not waste precious development time on style choices.
48
+
49
+ - **[GitHub Theme](https://marketplace.visualstudio.com/items?itemName=GitHub.github-vscode-theme)**: The GitHub Theme (Dark) for VS Code is a visually appealing theme that enhances the appearance of your editor, making it easier on the eyes (especially in the evening) and more enjoyable to work with. Even if you don't like this theme, we think it's a good idea to browse the marketplace and find a theme that you do like, making for a more pleasant coding experience under long hours of work.
50
+
51
+ #### How to Install Extensions
52
+
53
+ 1. **Open VS Code**: Launch Visual Studio Code on your computer.
54
+
55
+ 2. **Access the Extensions View**: Click on the Extensions icon in the Activity Bar on the side of the window or press `Ctrl+Shift+X` (`Cmd+Shift+X` on macOS).
56
+
57
+ 3. **Search for Extensions**: In the Extensions view, type the name of the extension you want to install (e.g., "Python", "Jupyter", "Ruff") in the search bar.
58
+
59
+ 4. **Install the Extension**: Click the `Install` button next to the extension in the search results.
60
+
61
+ 5. **Reload if Necessary**: Some extensions may require you to reload VS Code to activate them. If prompted, click the `Reload` button.
62
+
63
+ ### Useful VS Code Settings
64
+
65
+ Optimizing your VS Code settings can enhance your coding efficiency and code quality. Below are some recommended settings tailored for Python development:
66
+
67
+ **Enable Format on Save for Python Files and Notebooks**: Automatically format your code every time you save a file, both in Python scripts and Jupyter Notebooks.
68
+
69
+ - Go to `File` > `Preferences` > `Settings` (or press `Ctrl+,` on Windows/Linux or `Cmd+,` on macOS).
70
+ - Search for `Format On Save`.
71
+ - Check the box for **`Editor: Format On Save`**.
72
+ - Search for `Notebook: Format On Save`.
73
+ - Check the box for **`Notebook: Format On Save`**.
74
+
75
+ **Set Ruff as the Default Formatter for Python and Notebooks**:
76
+
77
+ - Open your settings and search for `Editor: Default Formatter`.
78
+ - Select **`Ruff`** from the dropdown menu.
79
+ - Search for `Notebook: Default Formatter`.
80
+ - Set it to use **`Ruff`** for formatting code cells in Jupyter Notebooks.
81
+
82
+ !!! success "Success"
83
+ Now, with just a click of the save button, Ruff will automatically enhance the appearance and readability of your code.
84
+
85
+ **Configure Jupyter Startup Commands**:
86
+
87
+ - These commands ensure that your notebook automatically reloads modules before executing code, which is helpful during development. This one has saved us many headaches in the early days of working with Python.
88
+ - Add the following setting to your `settings.json` file:
89
+
90
+ ```json
91
+ "jupyter.runStartupCommands": [
92
+ "%load_ext autoreload",
93
+ "%autoreload 2"
94
+ ],
95
+ ```
96
+
97
+ **Accessing the `settings.json` File**:
98
+
99
+ - To open the `settings.json` file in VS Code:
100
+ - Go to `File` > `Preferences` > `Settings` (or press `Ctrl+,` on Windows/Linux or `Cmd+,` on macOS).
101
+ - In the Settings page, click on the **Open Settings (JSON)** icon (a document with a small arrow) in the upper-right corner. This will open the `settings.json` file where you can edit your settings directly.
102
+ - Alternatively, you can use the Command Palette:
103
+ - Press `Ctrl+Shift+P` (`Cmd+Shift+P` on macOS) to open the Command Palette.
104
+ - Type `**Open User Settings (JSON)**` and select it from the list.
105
+
106
+ **Example `settings.json` Entries**:
107
+
108
+ Replace or update your `settings.json` with the following entries:
109
+
110
+ ```json
111
+ {
112
+ "editor": {
113
+ "formatOnSave": true,
114
+ "codeActionsOnSave": {
115
+ "source.fixAll": "explicit",
116
+ "source.organizeImports": "explicit"
117
+ },
118
+ "defaultFormatter": "charliermarsh.ruff"
119
+ },
120
+ "notebook": {
121
+ "formatOnSave": {
122
+ "enabled": true
123
+ },
124
+ "codeActionsOnSave": {
125
+ "notebook.source.fixAll": true,
126
+ "notebook.source.organizeImports": true
127
+ },
128
+ "defaultFormatter": "charliermarsh.ruff"
129
+ },
130
+ "jupyter.runStartupCommands": [
131
+ "%load_ext autoreload",
132
+ "%autoreload 2"
133
+ ],
134
+ }
135
+ ```
136
+
137
+ !!! tip "Thought"
138
+ Customizing your IDE to suit your workflow—including setting up keyboard shortcuts that work best for you—can significantly improve your productivity and make your coding experience more enjoyable.
139
+
140
+ ## Setting Up Your Python Virtual Environment
141
+
142
+ Creating a Python virtual environment is essential for managing dependencies and ensuring a clean development setup. It allows you to isolate your project's packages and Python version from other projects and the system-wide Python installation.
143
+
144
+ > We think it's a good idea to use a virtual environment manager to keep your global Python installation clean and to avoid conflicts between different projects.
145
+
146
+ Here are three popular options for managing virtual environments:
147
+
148
+ - **[Conda](https://docs.conda.io/en/latest/)**: Conda is a cross-platform package and environment manager that can handle both Python and non-Python dependencies, making it ideal for complex projects in scientific computing and data science. It supports creating isolated environments and includes its own package repositories.
149
+
150
+ - **[venv](https://docs.python.org/3/library/venv.html)**: The venv module is the built-in tool for creating virtual environments in Python 3. It's simple to use and comes pre-installed with Python, making it a convenient choice for managing environments with different packages or Python versions.
151
+
152
+ - **[uv](https://astral.sh/uv/)**: uv is a high-performance virtual environment manager created by Astral (the creators of Ruff). It offers rapid environment creation and management, aiming to be a minimalistic and efficient alternative to existing tools. Although still in its early stages, uv is designed to push the boundaries of performance and development ergonomics. We get inspired just by using it, and we think you will too.
153
+
154
+ For the rest of this tutorial, we will use Conda due to its popularity and robust feature set.
155
+
156
+ ### Setting Up Conda
157
+
158
+ To set up a Python virtual environment using Conda, follow these steps:
159
+
160
+ **1. Install Conda**
161
+
162
+ If you don't have Conda installed, you can install either Anaconda or Miniconda. Miniconda is a minimal installer for Conda that includes only Conda and its dependencies.
163
+
164
+ - **Download Miniconda** from the [official website](https://docs.conda.io/en/latest/miniconda.html) suitable for your operating system.
165
+
166
+ - **Install Miniconda** by running the installer and following the on-screen instructions.
167
+
168
+ **2. Create a New Environment**
169
+
170
+ Open the integrated terminal in VS Code by going to `View` > `Terminal` (or pressing `` Ctrl+` `` on Windows/Linux or `` Cmd+` `` on macOS). Use the following command to create a new Conda environment. Replace `myenv` with your desired environment name and `3.11` with the Python version you need.
171
+
172
+ ```bash
173
+ conda create -n myenv python=3.11
174
+ ```
175
+
176
+ **3. Activate the Environment**
177
+
178
+ Activate your new environment with the following command:
179
+
180
+ ```bash
181
+ conda activate myenv
182
+ ```
183
+
184
+ **4. Install Necessary Packages**
185
+
186
+ You can now install any packages you need using Conda or `pip`. For example, to install NumPy and SciPy, use:
187
+
188
+ ```bash
189
+ conda install numpy scipy
190
+ ```
191
+
192
+ Or, to install a package via `pip`:
193
+
194
+ ```bash
195
+ pip install prefab
196
+ ```
197
+
198
+ ### Selecting the Conda Environment in VS Code
199
+
200
+ After setting up your Conda environment, you'll want to ensure that VS Code uses this environment for running and debugging your Python code and Jupyter Notebooks.
201
+
202
+ #### Choosing the Python Interpreter
203
+
204
+ **1. Open a Python File**:
205
+
206
+ - Open any Python file in VS Code or create a new one with the `.py` extension.
207
+
208
+ **2. Select the Interpreter**:
209
+
210
+ - Click on the Python version displayed in the bottom-right corner of the VS Code status bar. It might say something like `Python 3.x.x`.
211
+
212
+ - A list of available Python interpreters will appear. Look for your Conda environment in the list. It should be listed with the name you gave it (e.g., `myenv`) and the path to the Python executable.
213
+
214
+ - Select your Conda environment from the list.
215
+
216
+ **3. Verify the Interpreter**:
217
+
218
+ - Once selected, the status bar should update to reflect the interpreter from your Conda environment.
219
+
220
+ #### Choosing the Jupyter Kernel
221
+
222
+ When working with Jupyter Notebooks in VS Code, you need to select the appropriate kernel associated with your Conda environment.
223
+
224
+ **1. Open a Jupyter Notebook**:
225
+
226
+ - Open an existing `.ipynb` file or create a new one in VS Code.
227
+
228
+ **2. Select the Kernel**:
229
+
230
+ - At the top-right corner of the notebook editor, you will see the kernel name (e.g., `Python 3`). Click on it to change the kernel.
231
+
232
+ - In the kernel selection dialog, you should see a list of available kernels. Your Conda environment should be listed, often with the name of the environment and the Python version.
233
+
234
+ - Select the kernel corresponding to your Conda environment.
235
+
236
+ **3. Verify the Kernel**:
237
+
238
+ - The kernel name should update to reflect the selected Conda environment.
239
+
240
+ **Troubleshooting**:
241
+
242
+ If your Conda environment's kernel doesn't appear in the list, you may need to install the `ipykernel` package in your environment:
243
+
244
+ ```bash
245
+ conda activate myenv # or the name of your environment
246
+ conda install ipykernel
247
+ ```
248
+
249
+ Alternatively, you can register the environment's kernel manually:
250
+
251
+ ```bash
252
+ python -m ipykernel install --user --name=myenv
253
+ ```
254
+
255
+ After installing the kernel, restart VS Code, and it should recognize the new kernel associated with your Conda environment.
256
+
257
+ By selecting the correct Python interpreter and Jupyter kernel, you ensure that your code runs in the intended environment, using the packages and dependencies you've installed.
258
+
259
+ !!! info "Info"
260
+ And that's it! The rest of this guide will focus on additional tools and resources that can help you take your Python-based photonics development to the next level.
261
+
262
+ ## Leveraging Cloud and Remote Tools for Computational Resources
263
+
264
+ Photonics simulations and computations can be resource-intensive, often requiring significant computational power and specialized hardware. Leveraging cloud and remote tools allows you to access powerful computational resources without the need for expensive local hardware. Here are some platforms and tools that can help you take advantage of cloud computing:
265
+
266
+ - [Google Colab](https://colab.research.google.com/) is a free cloud service (with some paid options) provided by Google that enables you to write and execute Python code through a web browser. It offers free access to GPUs and TPUs, allowing you to accelerate your simulations and computations using powerful hardware.
267
+
268
+ - [GitHub Codespaces](https://github.com/features/codespaces) provides a full-fledged cloud-based development environment directly within GitHub. It allows you to develop in the cloud using a cloud-hosted VS Code environment that's configured for your project.
269
+
270
+ - [Modal](https://modal.com/) is a platform that allows you to run your code in the cloud with minimal setup. It provides serverless computing, enabling you to run functions and scripts without managing servers. We love Modal for how easy it is to leverage powerful compute without having to leave the local Python environment.
271
+
272
+ - [Lambda Labs](https://lambdalabs.com/) provides cloud GPU workstations and servers for deep learning and computational tasks. They offer powerful NVIDIA GPUs (though sometimes limited based on usage) and pre-configured environments with popular frameworks, saving setup time.
273
+
274
+ - [SSH VS Code Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh) allows you to develop remotely by connecting to remote servers in your organization or cloud instances (e.g., AWS, GCP, Lambda Labs) directly from your local VS Code editor.
275
+
276
+ ## Terminal Tools
277
+
278
+ In addition to a good IDE, having the right terminal tools can offer nice benefits. Here are some useful command-line tools you may want to install:
279
+
280
+ - [Git](https://git-scm.com/) is a distributed version control system that allows you to track changes in your code, collaborate with others, and manage different versions of your project. It's an indispensable tool for any developer, and we think it is an underrated tool for photonics development too. Although VS Code has a built-in Git client, using Git in the terminal can be more flexible. We recommend [this video](https://www.youtube.com/watch?v=K6Q31YkorUE) for a quick introduction on using Git.
281
+
282
+ - [htop](https://github.com/htop-dev/htop) is an interactive process viewer for Linux and macOS systems. It provides a real-time view of system processes, CPU, and memory usage, making it especially easy to monitor remote compute instances.
283
+
284
+ - [nvtop](https://github.com/Syllo/nvtop) is like `htop` for NVIDIA GPUs. There are also many other `top`-like tools out there, so pick the one that best fits your system and workflow.
285
+
286
+ - [Oh My Zsh](https://ohmyz.sh/) is a popular shell framework that enhances the capabilities of the Zsh shell (which we also recommend using). It provides a rich set of plugins that make using the terminal much more powerful. If you find yourself using the terminal even just a little bit, this is a great tool to have.
287
+
288
+ ## AI Coding Assistants
289
+
290
+ AI-powered coding assistants have become invaluable tools for developers, whether you're just starting with Python or exploring new concepts in any field. These assistants offer real-time help, explanations, and code suggestions, making them excellent learning aids and productivity boosters.
291
+
292
+ - **[ChatGPT](https://chat.openai.com/)**: Developed by OpenAI, ChatGPT is *the* widely recognized (large) language model. They make improvements to their models and user interface regularly, so we recommend staying updated with its latest features to ensure you're utilizing the most advanced tools available.
293
+
294
+ - **[Claude](https://www.anthropic.com/)**: Claude, developed by Anthropic, is a competitor to ChatGPT. While benchmarking language models can be challenging (many believe Claude offers superior capabilities at least in some contexts), using multiple models from different providers (there are many others!) can help you obtain the best possible answers.
295
+
296
+ - **[Cursor](https://cursor.sh/)**: As previously mentioned, Cursor is an AI-enhanced IDE based on VS Code. One of its unique features is the ability to choose from multiple language models, helping you get the most accurate and helpful responses at any given time.
297
+
298
+ - **[GitHub Copilot](https://github.com/features/copilot)**: GitHub Copilot integrates seamlessly into VS Code, providing AI-assisted code completion and suggestions. While we believe Cursor offers superior features as an AI coding assistant, Copilot is a strong option if you prefer VS Code as your IDE.
299
+
300
+ There has been considerable discussion surrounding AI assistants, with both positive and negative viewpoints. However, when used pragmatically, these tools can [enhance productivity](https://github.blog/news-insights/research/research-quantifying-github-copilots-impact-on-developer-productivity-and-happiness/). If you're not already using these tools, we strongly encourage you to consider doing so.
301
+
302
+ ## Other Resources
303
+
304
+ While AI coding assistants are a great starting point when you need help with code, there are numerous online communities and resources available to assist with more specialized problems that other developers may have already solved. Engaging with these communities can provide valuable insights and support.
305
+
306
+ - **[Stack Overflow](https://stackoverflow.com/)**: A premier platform for getting help with specific coding issues. You can ask questions, share knowledge, and learn from the experiences of other developers.
307
+
308
+ - **[GitHub](https://github.com/)**: Many photonics projects and libraries are hosted on GitHub. By engaging with repositories' issues and discussions, you can get direct support from developers and other users. Contributing to open-source projects or raising issues can also enhance your understanding and help improve the tools you use.
309
+
310
+ - **"Think Python: How to Think Like a Computer Scientist" by Allen B. Downey**: An excellent introduction to Python programming, focusing on developing a computational thinking mindset. Python is an evolving language, so older books might not cover everything you need. But this one is so elegantly organized and written that it's still a great resource.
311
+
312
+ - **"Effective Computation in Physics: Field Guide to Research with Python" by Anthony Scopatz and Kathryn D. Huff**: This guidebook covers Python in the context of scientific computing and physics research, making it particularly useful for photonics developers.
313
+
314
+ - **"Talk Python to Me"**: A podcast that explores various topics in the Python ecosystem through interviews with experts and contributors. There is more to a language than just the syntax and libraries, and this podcast offers a great perspective on the language from the people who help shape it.
315
+
316
+ ## What's Next
317
+
318
+ To further advance your photonics development journey with Python:
319
+
320
+ 1. **Explore Photonics Simulations**: Experiment with examples from [Meep](https://meep.readthedocs.io/en/latest/) and [Tidy3D](https://docs.flexcompute.com/projects/tidy3d/en/latest/) documentation to deepen your understanding of photonic simulations and computational electromagnetics.
321
+
322
+ 2. **Contribute to Open-Source Projects**: Get involved with projects like [gdsfactory](https://github.com/gdsfactory/gdsfactory) and [SiEPIC](https://github.com/lukasc-ubc/SiEPIC-Tools). Contributing allows you to collaborate with others, improve existing tools, and engage with the photonics community.
323
+
324
+ 3. **Develop Your Own Tools!**: We can't wait to see what you build.
325
+
326
+ And of course, you can run our [notebook examples](../examples/1_prediction.ipynb) on using virtual nanofabrication models to add fabrication-awareness to your photonics simulations and designs.