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 aa56d63 commit 14a2311
Show file tree
Hide file tree
Showing 20 changed files with 106 additions and 101 deletions.
55 changes: 30 additions & 25 deletions Luminescent_AI_docs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"metadata": {},
"source": [
"# FDTD Luminescent Simulation and Inverse Design\n",
"\n",
"**Undergoing maintenance. Check back in 2025 :D**\n",
"v0.2.12-beta\n",
"2024/12/06 \n",
"Paul Shen <pxshen@alumni.stanford.edu>"
Expand Down Expand Up @@ -279,14 +281,15 @@
"c = gf.components.bend_circular(radius=radius)\n",
"# c.plot()\n",
"\n",
"name = f\"bend_R{radius}\"\n",
"path = f\"bend_R{radius}\"\n",
"N = 3 #3D or 2D\n",
"wavelengths = 1.55\n",
"keys=[\"2,1\"] # same as keys=[\"o2@0,o1@0\"]\n",
"nres=40\n",
"\n",
"lumi.write_sparams(c, name=name, wavelengths=wavelengths, nres=nres, keys=keys, N=N)\n",
"sol = lumi.load_res(name=name)\n"
"lumi.make_pic_sim_prob(path, c, wavelengths=wavelengths, nres=nres, keys=keys, N=N)\n",
"lumi.solve(path)\n",
"sol = lumi.load_res(path)\n"
]
},
{
Expand Down Expand Up @@ -384,11 +387,12 @@
}
],
"source": [
"name = f\"bend_R{radius}_multi\"\n",
"path = f\"bend_R{radius}_multi\"\n",
"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_res(name=name)"
"lumi.make_pic_sim_prob(c, path, wavelengths=wavelengths, nres=nres, keys=keys, N=N)\n",
"lumi.solve(path)\n",
"sol = lumi.load_res(path)"
]
},
{
Expand Down Expand Up @@ -450,11 +454,12 @@
],
"source": [
"radius = 1.5\n",
"name = f\"bend_R{radius}\"\n",
"path = f\"bend_R{radius}\"\n",
"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_res(name=name)\n"
"lumi.make_pic_sim_prob(c, path, wavelengths=wavelengths, nres=nres, keys=keys, N=N)\n",
"lumi.solve(path)\n",
"sol = lumi.load_res(path)\n"
]
},
{
Expand Down Expand Up @@ -533,8 +538,8 @@
"\n",
"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_res(name=name)"
"lumi.make_pic_sim_prob(c,path, wavelengths=wavelengths, keys=keys,nres=nres, N=N, dtype=dtype, gpu=gpu)\n",
"lumi.load_res(path)"
]
},
{
Expand All @@ -556,9 +561,9 @@
"name=\"rib\"\n",
"keys=[\"2,1\"]\n",
"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",
"lumi.make_pic_sim_prob(c,path, wavelengths=wavelengths, keys=keys,nres=nres, N=N, dtype=dtype, gpu=gpu, \n",
" bbox_layer=bbox_layer)\n",
"sol = lumi.load_res(name=name)"
"sol = lumi.load_res(path)"
]
},
{
Expand All @@ -580,9 +585,9 @@
"core_layer=LAYER.WGN\n",
"c = gf.components.straight(length=2.0, width=1.0, layer=core_layer)\n",
"\n",
"lumi.write_sparams(c,name=name, wavelengths=wavelengths, keys=keys,nres=nres, N=N, dtype=dtype, gpu=gpu,\n",
"lumi.make_pic_sim_prob(c,path, wavelengths=wavelengths, keys=keys,nres=nres, N=N, dtype=dtype, gpu=gpu,\n",
" core_layer=core_layer)\n",
"sol = lumi.load_res(name=name)"
"sol = lumi.load_res(path)"
]
},
{
Expand Down Expand Up @@ -629,13 +634,13 @@
"# recommended RAM: >16G\n",
"import luminescent as lumi\n",
"\n",
"name = \"mode_converter\" # can be any string\n",
"path = \"mode_converter\" # can be any string\n",
"c = lumi.gcells.mimo(west=1, east=1, l=5.0, w=2.4,\n",
" wwg=.5, taper=.05)\n",
"targets = {\"tparams\": {1.55: {\"o2@1,o1@0\": 1.0}}}\n",
"\n",
"prob = lumi.gcell_problem(\n",
" c, targets, name=name,\n",
" c, targets, path,\n",
" N=2, nres=15,\n",
" lvoid=0.15, lsolid=.15,\n",
" iters=100, stoploss=.05, )\n",
Expand Down Expand Up @@ -720,7 +725,7 @@
],
"source": [
"name=\"mode_converter\"\n",
"sol=lumi.load_res(name=name)"
"sol=lumi.load_res(path)"
]
},
{
Expand Down Expand Up @@ -750,14 +755,14 @@
"from pprint import pprint\n",
"import luminescent as lumi\n",
"\n",
"name = \"splitter\"\n",
"path = \"splitter\"\n",
"c = lumi.gcells.mimo(west=1, east=2, l=4.0, w=2.0, wwg=.5, taper=.05, )\n",
"targets = {\n",
" \"tparams\": {1.55: {\"2,1\": 0.5}},\n",
"}\n",
"\n",
"prob = lumi.gcell_problem(\n",
" c, targets, name=name,\n",
" c, targets, path,\n",
" N=2, nres=15, symmetries=[1],\n",
" lvoid=0.15, lsolid=.15,\n",
" iters=50, stoploss=.05, )\n",
Expand Down Expand Up @@ -822,8 +827,8 @@
}
],
"source": [
"name = \"splitter\"\n",
"sol = lumi.load_res(name=name)"
"path = \"splitter\"\n",
"sol = lumi.load_res(path)"
]
},
{
Expand Down Expand Up @@ -858,7 +863,7 @@
"metadata": {},
"outputs": [],
"source": [
"# finetune(iters=10,name=name)\n",
"# finetune(iters=10,path)\n",
"sol = lumi.load_res(name)"
]
},
Expand Down Expand Up @@ -889,7 +894,7 @@
"}}\n",
"\n",
"prob = lumi.gcell_problem(\n",
" c, targets, name=name,\n",
" c, targets, path,\n",
" lvoid=0.15,lsolid=0.15, nres=15, \n",
" N=2, iters=50)\n",
"lumi.solve(prob)"
Expand Down Expand Up @@ -936,7 +941,7 @@
"targets = {\"tparams\":{1.55: {\"2,1\": 1.0}}}\n",
"\n",
"prob = lumi.gcell_problem(\n",
" c, targets, name=name,\n",
" c, targets, path,\n",
" lvoid=0.15,lsolid=0.15, nres=15, symmetries=[0,1],\n",
" N=2, iters=40)\n",
"lumi.solve(prob)"
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "Luminescent"
path = "Luminescent"
uuid = "60a98398-2d19-4130-ae20-63172a4a42f2"
authors = ["Paul Shen <pxshen@alumni.stanford.edu>"]
version = "1.0.0"
Expand Down
8 changes: 4 additions & 4 deletions luminescent/a/coupler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

c = gf.components.coupler(length=8, gap=.06, dx=10, dy=5)
c.plot()
sol = lumi.write_sparams(c, name="coupler2D", wavelengths=1.55, keys=["2,1", "3,1", "4,1"], # same as keys=["o2@0,o1@0"]
core_layer=LAYER.WG, bbox_layer=LAYER.WAFER, # defaults
layer_stack=LAYER_STACK, materials=MATERIALS, # defaults
dx=0.1, N=2, N=3)
sol = lumi.make_pic_sim_prob(c, name="coupler2D", wavelengths=1.55, keys=["2,1", "3,1", "4,1"], # same as keys=["o2@0,o1@0"]
core_layer=LAYER.WG, bbox_layer=LAYER.WAFER, # defaults
layer_stack=LAYER_STACK, materials=MATERIALS, # defaults
dx=0.1, N=2, N=3)
# lumi.show_solution()
2 changes: 1 addition & 1 deletion luminescent/a/crossing_inverse_design_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pprint import pprint
import luminescent as lumi

name = "crossing"
path = "crossing"
L = 4.0
c = lumi.gcells.mimo(1, 1, 1, 1, l=L, w=L, wwg=.5)
targets = {
Expand Down
4 changes: 2 additions & 2 deletions luminescent/a/demux_inverse_design_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from pprint import pprint
import luminescent as lumi

name = "demux"
c = lumi.gcells.mimo(west=1, east=2, l=5.0, w=3.0, wwg=.5, name=name)
path = "demux"
c = lumi.gcells.mimo(west=1, east=2, l=5.0, w=3.0, wwg=.5, path)
targets = {"tparams": {
1.55: {"2,1": 1.0},
1.10: {"3,1": 1.0},
Expand Down
8 changes: 4 additions & 4 deletions luminescent/a/maketest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
[None, ],
["f32"],
[[1.55], ]):
lumi.write_sparams(c, name=f"simtest{i}",
wavelengths=wavelengths, keys=["2,1"], nres=nres,
N=N, gpu=gpu, dtype=dtype,
wd=BUILD_RUNS, run=False)
lumi.make_pic_sim_prob(c, name=f"simtest{i}",
wavelengths=wavelengths, keys=["2,1"], nres=nres,
N=N, gpu=gpu, dtype=dtype,
wd=BUILD_RUNS, run=False)
i += 1
sleep(1)
4 changes: 2 additions & 2 deletions luminescent/a/mode_converter_inverse_design_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# recommended RAM: >16G
import luminescent as lumi

name = "mode_converter" # can be any string
path = "mode_converter" # can be any string
c = lumi.gcells.mimo(west=1, east=1, l=5.0, w=2.4,
wwg=.5, taper=.05)
targets = {"tparams": {1.55: {"o2@1,o1@0": 1.0}}}

prob = lumi.make_pic_inv_prob(
c, targets, name=name,
c, targets, path,
N=2, nres=15,
lvoid=0.15, lsolid=.15,
iters=100, stoploss=.05, )
Expand Down
8 changes: 4 additions & 4 deletions luminescent/a/splitter.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
from pprint import pprint
import luminescent as lumi

name = "splitter"
path = "splitter"
c = lumi.gcells.mimo(west=1, east=2, l=4.0, w=2.0, wwg=.5, taper=.05, )
targets = {
"tparams": {1.55: {"2,1": 0.5}},
}

prob = lumi.make_pic_inv_prob(
c, targets, name=name,
c, targets, path,
N=2, nres=15, symmetries=[1],
lvoid=0.15, lsolid=.15,
iters=50, stoploss=.05, )
lumi.solve(prob, run=False)
# name = "1x4_splitter"
# path = "1x4_splitter"
# c = lumi.gcells.mimo(west=1, east=4, l=6.0, w=6.0, wwg=.5, taper=.05, )
# targets = {
# "tparams": {1.55: {"2,1": 0.25, "3,1": 0.25}},
# "phasediff": {1.55: {"2,3": 0.0}},
# }

# prob = lumi.make_pic_inv_prob(
# c, targets, name=name,
# c, targets, path,
# symmetries=[1], lvoid=0.1, lsolid=0.1, dx=0.1,
# N=2, stoploss=.03, iters=40)
# sol = lumi.solve(prob)
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 @@ -5,7 +5,7 @@
from gdsfactory.generic_tech import LAYER


name = "tiny"
path = "tiny"
# lumi.load_res()
# raise NotImplementedError("This is a stub")
c = lumi.gcells.mimo(west=1, east=1, l=1, w=1, wwg=.5)
Expand All @@ -14,7 +14,7 @@
"2,1": 1.0
}}}
prob = lumi.make_pic_inv_prob(
c, targets, name=name,
c, targets, path,
lvoid=0.2, dx=0.1, iters=2,
N=2, gpu=None,)
sol = lumi.solve(prob, run=False)
10 changes: 5 additions & 5 deletions luminescent/bend.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@

# radius = 1.5
# wavelengths = 1.55
# name = f"bend_R{radius}"
# path = f"bend_R{radius}"

# radius = 2
# wavelengths = lumi.wavelength_range(center=1.35, bandwidth=.4, length=3)
# name = f"bend_R{radius}_multi"
# path = f"bend_R{radius}_multi"

N = 3 # 2D or 3D
radius = 5
wavelengths = 1.55
name = f"bend_R{radius}"
path = f"bend_R{radius}"

# N = 3
# radius = 5
# wavelengths = np.linspace(1.5, 1.6, 5) # number or list or array
# name = f"bend_R{radius}_multi"
# path = f"bend_R{radius}_multi"

# N = 2
# radius = 5
# wavelengths = np.linspace(1.5, 1.6, 5) # number or list or array
# nres = 20
# name = f"bend_R{radius}_multi_{N}D"
# path = 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)
Expand Down
10 changes: 5 additions & 5 deletions luminescent/luminescent/pic/gcells.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def mimo(west=0, east=0, south=0, north=0,
design = gf.Component()
c = gf.Component(**kwargs)
if name:
c.name = name
c.path = name
if lwg is None:
lwg = 4*wwg
p = [(0, 0), (l, 0), (l, w), (0, w)]
Expand Down Expand Up @@ -51,13 +51,13 @@ def mimo(west=0, east=0, south=0, north=0,
for wwg, v in zip(wwg, d):
center = (x, y+v) if i in [0, 1] else (x+v, y)
wwg2 = wwg+2*taper*lwg
name = "o"+str(n+1)
design.add_port(name=name, center=center, width=wwg2,
path = "o"+str(n+1)
design.add_port(path, center=center, width=wwg2,
orientation=a, layer=wwg_layer)
wg = c << gf.components.taper(
length=lwg, width1=wwg, width2=wwg2, layer=wwg_layer)
wg.connect("o2", design.ports[name])
c.add_port(name=name, port=wg.ports["o1"])
c.add_port(path, port=wg.ports["o1"])
n += 1

design = c << design
Expand All @@ -68,7 +68,7 @@ def mimo(west=0, east=0, south=0, north=0,
# wavelengths=1.55, dx=0.05,
# # ϵcore=ϵcore, ϵclad=ϵclad,
# dir="", init=None, lmin=0.1, LAYER=LAYER, **kwargs):
# name = "ubend"
# path = "ubend"
# design = gf.Component("design")
# device = gf.Component("ubend")
# λ = wavelength
Expand Down
4 changes: 2 additions & 2 deletions luminescent/luminescent/runs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def load_res(path, show=True):
sol["optimized_designs"] = l
print(f"loading optimized design regions at resolution {sol['dl']}")
# for i, a in enumerate(l):
# name = f"optimized_design_region_{i+1}.png"
# path = f"optimized_design_region_{i+1}.png"
# Image.fromarray(np.flip(np.uint8((1-a)) * 255, 0),
# 'L').save(os.path.join(path, name))
# pic2gds(os.path.join(
Expand Down Expand Up @@ -130,5 +130,5 @@ def make_training_movie(framerate=2, **kwargs):
# video.release()


def write_sparams(*args, run=True, **kwargs):
def make_pic_sim_prob(*args, run=True, **kwargs):
return solve(make_pic_sim_prob(*args, **kwargs), run=run)
2 changes: 1 addition & 1 deletion luminescent/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
name = "luminescent"
path = "luminescent"
version = "0.3.1"
description = "Lumi FDTD by Luminescent AI is a GPU and automatic differentiation (AD) compatible FDTD package for simulation and inverse design in semiconductor photonics. Create layout in gdsfactory. Then use the Lumi Python plugin for calculating sparams or perform inverse design on Lumi's Julia backend."
authors = ["Paul Shen"]
Expand Down
Loading

0 comments on commit 14a2311

Please sign in to comment.