Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
paulxshen committed Dec 28, 2024
1 parent b574b6d commit aa56d63
Show file tree
Hide file tree
Showing 24 changed files with 156 additions and 149 deletions.
26 changes: 13 additions & 13 deletions Luminescent_AI_docs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"metadata": {},
"source": [
"## File workflow\n",
"Each simulation or design optimization run is saved to a folder named after `name` arg or (if unnamed) timestamp string. These run folders are inside working directory `wd=\"~/runs\"` which can be modified by passing to `write_sparams` or `gcell_problem`. Can access saved runs via `load_solution()`, `load_solution()`, `finetune()` which act on latest modified run folder inside `wd` if `name` not specified. "
"Each simulation or design optimization run is saved to a folder named after `name` arg or (if unnamed) timestamp string. These run folders are inside working directory `wd=\"~/runs\"` which can be modified by passing to `write_sparams` or `gcell_problem`. Can access saved runs via `load_res()`, `load_res()`, `finetune()` which act on latest modified run folder inside `wd` if `name` not specified. "
]
},
{
Expand Down Expand Up @@ -216,7 +216,7 @@
"metadata": {},
"source": [
"#### Single wavelength 3D\n",
"We characterize insertion loss (IL) of waveguide bends wrt radius. We set R=5.0um, the often cited minimum radius in silicon photonics. First, we use `gdsfactory` to make the bend (note `gdsfactory` uses inner radius). Next, `write_sparams` simulates and saves results, which are retrieved and visualized by `load_solution`. \n",
"We characterize insertion loss (IL) of waveguide bends wrt radius. We set R=5.0um, the often cited minimum radius in silicon photonics. First, we use `gdsfactory` to make the bend (note `gdsfactory` uses inner radius). Next, `write_sparams` simulates and saves results, which are retrieved and visualized by `load_res`. \n",
"\n",
"`nres` is the maximum resolution - the number of points per wavelength in free space. The grid is adaptive so border regions actually use a lower resolution for speed. Remember FDTD scales as O(n^4)! `nres` has a huge effect on simulation time! Here, `nres=40` is accurate but can take half hour on CPU. `nres=20` is 16x faster and offers a reasonable estimate. Finally, Because of reciprocity we only need S or T param keys of \"2,1\". \n"
]
Expand Down Expand Up @@ -286,7 +286,7 @@
"nres=40\n",
"\n",
"lumi.write_sparams(c, name=name, wavelengths=wavelengths, nres=nres, keys=keys, N=N)\n",
"sol = lumi.load_solution(name=name)\n"
"sol = lumi.load_res(name=name)\n"
]
},
{
Expand Down Expand Up @@ -388,7 +388,7 @@
"wavelengths = np.linspace(1.5, 1.6, 5) # number or list or array\n",
"\n",
"lumi.write_sparams(c, name=name, wavelengths=wavelengths, nres=nres, keys=keys, N=N)\n",
"sol = lumi.load_solution(name=name)"
"sol = lumi.load_res(name=name)"
]
},
{
Expand Down Expand Up @@ -454,7 +454,7 @@
"c = gf.components.bend_circular(radius=radius, allow_min_radius_violation=True)\n",
"\n",
"lumi.write_sparams(c, name=name, wavelengths=wavelengths, nres=nres, keys=keys, N=N)\n",
"sol = lumi.load_solution(name=name)\n"
"sol = lumi.load_res(name=name)\n"
]
},
{
Expand Down Expand Up @@ -534,7 +534,7 @@
"name=\"TE1\"\n",
"keys=[\"o2@1,o1@1\"]\n",
"lumi.write_sparams(c,name=name, wavelengths=wavelengths, keys=keys,nres=nres, N=N, dtype=dtype, gpu=gpu)\n",
"lumi.load_solution(name=name)"
"lumi.load_res(name=name)"
]
},
{
Expand All @@ -558,7 +558,7 @@
"bbox_layer=[LAYER.WAFER,LAYER.SLAB90]\n",
"lumi.write_sparams(c,name=name, wavelengths=wavelengths, keys=keys,nres=nres, N=N, dtype=dtype, gpu=gpu, \n",
" bbox_layer=bbox_layer)\n",
"sol = lumi.load_solution(name=name)"
"sol = lumi.load_res(name=name)"
]
},
{
Expand All @@ -582,7 +582,7 @@
"\n",
"lumi.write_sparams(c,name=name, wavelengths=wavelengths, keys=keys,nres=nres, N=N, dtype=dtype, gpu=gpu,\n",
" core_layer=core_layer)\n",
"sol = lumi.load_solution(name=name)"
"sol = lumi.load_res(name=name)"
]
},
{
Expand Down Expand Up @@ -720,7 +720,7 @@
],
"source": [
"name=\"mode_converter\"\n",
"sol=lumi.load_solution(name=name)"
"sol=lumi.load_res(name=name)"
]
},
{
Expand Down Expand Up @@ -823,7 +823,7 @@
],
"source": [
"name = \"splitter\"\n",
"sol = lumi.load_solution(name=name)"
"sol = lumi.load_res(name=name)"
]
},
{
Expand Down Expand Up @@ -859,7 +859,7 @@
"outputs": [],
"source": [
"# finetune(iters=10,name=name)\n",
"sol = lumi.load_solution(name)"
"sol = lumi.load_res(name)"
]
},
{
Expand Down Expand Up @@ -903,7 +903,7 @@
"outputs": [],
"source": [
"name=\"demux\"\n",
"sol = lumi.load_solution(name)"
"sol = lumi.load_res(name)"
]
},
{
Expand Down Expand Up @@ -949,7 +949,7 @@
"metadata": {},
"outputs": [],
"source": [
"sol = lumi.load_solution(name)"
"sol = lumi.load_res(name)"
]
},
{
Expand Down
24 changes: 12 additions & 12 deletions luminescent/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ version = "7.18.0"

[[deps.ArrayPadding]]
deps = ["Statistics"]
path = "C:\\Users\\pxshe\\OneDrive\\Desktop\\beans\\ArrayPadding.jl"
git-tree-sha1 = "77c679671a19c1c7be3101aa98513ff23817d58b"
uuid = "fe5ef43c-4912-423d-9170-4bd5cb6a013a"
version = "1.0.0"
version = "1.0.1"

[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
Expand Down Expand Up @@ -972,7 +972,7 @@ version = "0.21.4"

[[deps.Jello]]
deps = ["ArrayPadding", "FFTW", "Flux", "Functors", "ImageMorphology", "LinearAlgebra", "Optimisers", "Porcupine", "Random", "SparseArrays", "Statistics", "UnPack", "Zygote"]
path = "C:\\Users\\pxshe\\OneDrive\\Desktop\\beans\\Jello.jl"
git-tree-sha1 = "9ee079b713f0bf68d46bef47a74ea7d1fb796a3a"
uuid = "6872b481-e419-48a0-81d2-be4ee5684529"
version = "1.0.0"

Expand Down Expand Up @@ -1573,7 +1573,7 @@ version = "1.4.3"

[[deps.Porcupine]]
deps = ["ArrayPadding", "ChainRulesCore", "DataStructures", "Functors", "LinearAlgebra", "Statistics", "UnPack"]
path = "C:\\Users\\pxshe\\OneDrive\\Desktop\\beans\\Porcupine.jl"
git-tree-sha1 = "516169d336454ed6c14fec9856b585a5f58f2ed2"
uuid = "3b53a3d7-3f34-4bba-8df2-4717a8b1e972"
version = "1.0.1"

Expand Down Expand Up @@ -2114,9 +2114,9 @@ version = "5.6.3+1"

[[deps.Xorg_libX11_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Xorg_libxcb_jll", "Xorg_xtrans_jll"]
git-tree-sha1 = "9dafcee1d24c4f024e7edc92603cedba72118283"
git-tree-sha1 = "ff1fdd02e71717c7418deb1c42f487529d0b9574"
uuid = "4f6342f7-b3d2-589e-9d20-edeb45f2b2bc"
version = "1.8.6+1"
version = "1.8.6+2"

[[deps.Xorg_libXau_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
Expand All @@ -2132,9 +2132,9 @@ version = "1.1.4+2"

[[deps.Xorg_libXext_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Xorg_libX11_jll"]
git-tree-sha1 = "d7155fea91a4123ef59f42c4afb5ab3b4ca95058"
git-tree-sha1 = "fb3f116a4efb81aecf8c415e9423869c6ee0f21f"
uuid = "1082639a-0dae-5f34-9b06-72781eeb8cb3"
version = "1.3.6+1"
version = "1.3.6+2"

[[deps.Xorg_libXrender_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Xorg_libX11_jll"]
Expand All @@ -2150,9 +2150,9 @@ version = "0.1.1+2"

[[deps.Xorg_libxcb_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "XSLT_jll", "Xorg_libXau_jll", "Xorg_libXdmcp_jll", "Xorg_libpthread_stubs_jll"]
git-tree-sha1 = "1a74296303b6524a0472a8cb12d3d87a78eb3612"
git-tree-sha1 = "b4678b3c5ee394ae6422c415b231b8015c85542f"
uuid = "c7cfdc94-dc32-55de-ac96-5a1b8d977c5b"
version = "1.17.0+1"
version = "1.17.0+2"

[[deps.Xorg_xtrans_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
Expand All @@ -2179,9 +2179,9 @@ version = "1.5.6+2"

[[deps.Zygote]]
deps = ["AbstractFFTs", "ChainRules", "ChainRulesCore", "DiffRules", "Distributed", "FillArrays", "ForwardDiff", "GPUArrays", "GPUArraysCore", "IRTools", "InteractiveUtils", "LinearAlgebra", "LogExpFunctions", "MacroTools", "NaNMath", "PrecompileTools", "Random", "Requires", "SparseArrays", "SpecialFunctions", "Statistics", "ZygoteRules"]
git-tree-sha1 = "c7dc3148a64d1cd3768c29b3db5972d1c302661b"
git-tree-sha1 = "60269397d29dabf2ad08ec658e7f0d680c15f13c"
uuid = "e88e6eb3-aa80-5325-afca-941959d7151f"
version = "0.6.73"
version = "0.6.74"

[deps.Zygote.extensions]
ZygoteColorsExt = "Colors"
Expand Down
2 changes: 2 additions & 0 deletions luminescent/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Jello = "6872b481-e419-48a0-81d2-be4ee5684529"
Luminescent = "60a98398-2d19-4130-ae20-63172a4a42f2"
Porcupine = "3b53a3d7-3f34-4bba-8df2-4717a8b1e972"

[sources]
4 changes: 2 additions & 2 deletions luminescent/a/crossing_inverse_design_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"3,1": 1.0
}}

prob = lumi.pic_design_problem(
prob = lumi.make_pic_inv_prob(
c, tparam_targets=targets, symmetries=[0, 1, "diag"], lmin=0.2, dx=0.1,
stoploss=.03, iters=50, eta=10., N=2)
sol = lumi.solve(prob)

# sol = lumi.load_solution()
# sol = lumi.load_res()
lumi.show_solution()
print("post optim tparams:")
pprint(sol["tparams"])
2 changes: 1 addition & 1 deletion luminescent/a/demux_inverse_design_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
1.10: {"3,1": 1.0},
}}

prob = lumi.pic_design_problem(
prob = lumi.make_pic_inv_prob(
c, targets,
lvoid=0.1, lsolid=0.1, dx=0.1,
N=2, iters=50)
Expand Down
2 changes: 1 addition & 1 deletion luminescent/a/maketest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
["f32"],
# ["f32", "f16"],
):
prob = lumi.pic_design_problem(
prob = lumi.make_pic_inv_prob(
c, targets, name="invtest",
lvoid=0.2, lsolid=.2, nres=nres, iters=2,
N=2, gpu=gpu, dtype=dtype,) # wd=BUILD_RUNS)
Expand Down
2 changes: 1 addition & 1 deletion luminescent/a/mode_converter_inverse_design_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
wwg=.5, taper=.05)
targets = {"tparams": {1.55: {"o2@1,o1@0": 1.0}}}

prob = lumi.pic_design_problem(
prob = lumi.make_pic_inv_prob(
c, targets, name=name,
N=2, nres=15,
lvoid=0.15, lsolid=.15,
Expand Down
4 changes: 2 additions & 2 deletions luminescent/a/splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"tparams": {1.55: {"2,1": 0.5}},
}

prob = lumi.pic_design_problem(
prob = lumi.make_pic_inv_prob(
c, targets, name=name,
N=2, nres=15, symmetries=[1],
lvoid=0.15, lsolid=.15,
Expand All @@ -20,7 +20,7 @@
# "phasediff": {1.55: {"2,3": 0.0}},
# }

# prob = lumi.pic_design_problem(
# prob = lumi.make_pic_inv_prob(
# c, targets, name=name,
# symmetries=[1], lvoid=0.1, lsolid=0.1, dx=0.1,
# N=2, stoploss=.03, iters=40)
Expand Down
4 changes: 2 additions & 2 deletions luminescent/a/tiny_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@


name = "tiny"
# lumi.load_solution()
# lumi.load_res()
# raise NotImplementedError("This is a stub")
c = lumi.gcells.mimo(west=1, east=1, l=1, w=1, wwg=.5)
targets = {"tparams": {
1.55: {
"2,1": 1.0
}}}
prob = lumi.pic_design_problem(
prob = lumi.make_pic_inv_prob(
c, targets, name=name,
lvoid=0.2, dx=0.1, iters=2,
N=2, gpu=None,)
Expand Down
12 changes: 8 additions & 4 deletions luminescent/bend.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
import luminescent as lumi
import gdsfactory as gf
import numpy as np

N = 3 # 3D or 2D
keys = ["2,1"] # same as keys=["o2@0,o1@0"]
nres = 40
nres = 30

# radius = 1.5
# wavelengths = 1.55
Expand All @@ -30,7 +31,10 @@
# nres = 20
# name = f"bend_R{radius}_multi_{N}D"

path = os.path.join("runs", name)
c = gf.components.bend_circular(radius=radius, allow_min_radius_violation=True)
lumi.write_sparams(c, name=name, wavelengths=wavelengths,
nres=nres, keys=keys, N=N, run=False)
# sol = lumi.load_solution(name=name)
lumi.make_pic_sim_prob(path, c,
wavelengths=wavelengths,
nres=nres, keys=keys, N=N)
lumi.solve(path)
sol = lumi.load_res(path)
35 changes: 18 additions & 17 deletions luminescent/luminescent/pic/inverse_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
import json


def pic_design_problem(c, targets, iters,
lvoid=0, lsolid=0, symmetries=[],
weights=dict(),
eta=.4, init=1, stoploss=None,
design_region_layer=DESIGN_LAYER,
# design_guess_layer=LAYER.GUESS,
fill_layer=LAYER.WG,
void_layer=None,
layer_stack=LAYER_STACK,
plot=False, N=2,
restart=True, save_memory=False, **kwargs):
def make_pic_inv_prob(path, c, targets, iters,
lvoid=0, lsolid=0, symmetries=[],
weights=dict(),
eta=.4, init=1, stoploss=None,
design_region_layer=DESIGN_LAYER,
# design_guess_layer=LAYER.GUESS,
fill_layer=LAYER.WG,
void_layer=None,
layer_stack=LAYER_STACK,
plot=False, N=2,
restart=True, save_memory=False, **kwargs):
design_region_layer = tuple(design_region_layer)
# if not N:
# raise NotImplementedError(
Expand Down Expand Up @@ -78,12 +78,12 @@ def pic_design_problem(c, targets, iters,
print(keys)
wavelengths = list(wavelengths)

prob = sparams_problem(c,
layer_stack=layer_stack,
wavelengths=wavelengths,
study="inverse_design",
keys=keys,
N=N, approx=N == 2, ** kwargs)
prob = make_pic_sim_prob(c,
layer_stack=layer_stack,
wavelengths=wavelengths,
study="inverse_design",
keys=keys,
N=N, approx=N == 2, ** kwargs)

prob["restart"] = restart
prob["weights"] = {**{
Expand Down Expand Up @@ -137,6 +137,7 @@ def _bbox(b):

prob["design_config"]["design_region_layer"] = design_region_layer
prob["iters"] = iters
save_prob(prob, path)
return prob


Expand Down
6 changes: 1 addition & 5 deletions luminescent/luminescent/pic/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from gdsfactory.generic_tech import LAYER_STACK, LAYER


def setup(c, study, nres, wl,
def setup(path, c, study, nres, wl,
bbox_layer=LAYER.WAFER,
zmargin2=None, zlims=None, core_layer=LAYER.WG,
port_source_offset="auto", port_margin="auto",
Expand All @@ -36,10 +36,6 @@ def setup(c, study, nres, wl,
dl = dx/ratio
dz = 1 * dx

if not name:
l = [prob["timestamp"], study]
name = "#".join(l)
path = os.path.join(wd, name)
prob["path"] = path
prob["name"] = name
prob["wl"] = wl
Expand Down
Loading

0 comments on commit aa56d63

Please sign in to comment.