Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
paulxshen committed Sep 25, 2024
1 parent 3c58e50 commit 984d9f2
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 50 deletions.
58 changes: 32 additions & 26 deletions Luminescent_AI_docs.ipynb

Large diffs are not rendered by default.

Binary file modified image.bmp
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 4 additions & 3 deletions lumi/src/luminescent/gplugins/luminescent/inverse_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@


def gcell_problem(c, targets, iters,
lmin=.1, symmetries=[],
lvoid=0, lsolid=0, symmetries=[],
weights=dict(),
eta=2, init=1, stoploss=.03,
eta=.1, init=1, stoploss=.03,
design_region_layer=DESIGN_LAYER,
# design_guess_layer=LAYER.GUESS,
fill_layer=LAYER.WG,
Expand Down Expand Up @@ -110,7 +110,8 @@ def _bbox(b):
"bbox": _bbox(p.bbox()),
"symmetries": s,
"init": init,
"lmin": lmin,
"lvoid": lvoid,
"lsolid": lsolid,
} for p, s in zip(list(polys.values())[0], symmetries)
]
epsmin = np.min(prob["eps_2D"])
Expand Down
4 changes: 2 additions & 2 deletions lumi/src/luminescent/gplugins/luminescent/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def setup(c, study, dx, margin,

prob["mode_height"] = h
# w = port_width+2*margin
w = 2*port_width
w = 2.5*port_width
neffmin = 1000000
wavelengths = []
# _c = add_bbox(c, layer=bbox_layer, nonport_margin=margin)
Expand Down Expand Up @@ -164,7 +164,7 @@ def setup(c, study, dx, margin,
wavelengths = sorted(set(wavelengths))
wl = np.median(wavelengths)
if port_source_offset == "auto":
port_source_offset = trim(2*wl/neffmin, dx)
port_source_offset = trim(2.6*wl/neffmin, dx)
prob["port_source_offset"] = port_source_offset
if source_margin == "auto":
source_margin = 2*dx
Expand Down
11 changes: 5 additions & 6 deletions lumi/src/scratch.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# recommended RAM: >16G
from pprint import pprint
import luminescent as lumi

name = "mode_converter" # can be any string
c = lumi.gcells.mimo(west=1, east=1, l=4.0, w=2.0, wwg=.5, name=name)
targets = {"tparams": {1.55: {"o2@0,o1@1": 1.0}}}
name = "1x2_splitter"
c = lumi.gcells.mimo(west=1, east=2, l=4.0, w=2.0, wwg=.5, name=name)
targets = {"tparams": {1.55: {"2,1": 0.5, "3,1": 0.5}}}

prob = lumi.gcell_problem(
c, targets,
lmin=0.1, dx=0.05,
approx_2D=True, iters=40, stoploss=.03)
symmetries=[1], lvoid=0.1, dx=0.05,
approx_2D=True, iters=30, stoploss=.03)
sol = lumi.solve(prob)
13 changes: 9 additions & 4 deletions src/gf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,14 @@ function gfrun(path; kw...)
# init = nothing
# end

lmin = round(d.lmin / dx)
lvoid = round(d.lvoid / dx)
lsolid = round(d.lsolid / dx)
lmin = max(lvoid, lsolid, 1)
frame = eps_2D[range.(o - lmin, o + szd + lmin - 1)...]
frame = frame .== maximum(frame)
display(heatmap(frame))
b = Blob(szd;
init, lmin, symmetries, F)
init, lvoid, lsolid, symmetries, F, frame)

if !isnothing(sol) && !restart
println("loading saved design...")
Expand Down Expand Up @@ -514,7 +519,7 @@ function gfrun(path; kw...)
= fmap(abs2, S)
end
ignore_derivatives() do
display(ŷ)
println(json(ŷ))
end
= [[(λ)(k) for k = keys(y[λ])] for λ = keys(y)]
= flatten(ŷ)
Expand Down Expand Up @@ -551,7 +556,7 @@ function gfrun(path; kw...)
# end
println("")

if i % 10 == 0 || stop
if i % 5 == 0 || stop
println("saving checkpoint...")
ckptpath = joinpath(path, "checkpoints", replace(string(now()), ':' => '_', '.' => '_'))
mkpath(ckptpath)
Expand Down
22 changes: 13 additions & 9 deletions src/monitors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,17 @@ function MonitorInstance(m::Monitor, dx, field_origin, common_left_pad_amount, s
L = ub - lb

roi = dict([k => begin
p = (c + lb - o) / dx + 1.5
i = floor(p)
w = 1 - mean(abs.(p - i))
w = (w, 1 - w)
i = [i .+ map(round(L / dx)) do n
n == 0 ? 0 : (0:sign(n):n-sign(n))
end for i = (i, i + 1)]
[(F(w), i) for (w, i) in zip(w, i) if w > 0]
a = (c + lb - o) / dx + 1.5

[l == 0 ? a : (a + (0:sign(l):l-sign(l))) for (a, l) in zip(a, round(L / dx))]
# p = (c + lb - o) / dx + 1.5
# i = floor(p)
# w = 1 - mean(abs.(p - i))
# w = (w, 1 - w)
# i = [i .+ map(round(L / dx)) do n
# n == 0 ? 0 : (0:sign(n):n-sign(n))
# end for i = (i, i + 1)]
# [(F(w), i) for (w, i) in zip(w, i) if w > 0]
end for (k, o) = pairs(field_origin)])
n = isnothing(n) ? n : F.(n |> normalize)
_center = round(c / dx) + 1 + common_left_pad_amount
Expand All @@ -111,7 +114,8 @@ Args
- `m`
"""
function field(a::AbstractArray, k, m)
sum([w * a[i...] for (w, i) = m.roi[k]])
# sum([w * a[i...] for (w, i) = m.roi[k]])
getindexf(a, m.roi[k]...)
end

function field(u::Dictlike, k, m)
Expand Down

0 comments on commit 984d9f2

Please sign in to comment.