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 30, 2024
1 parent c273e09 commit 1505e5d
Show file tree
Hide file tree
Showing 14 changed files with 372 additions and 50 deletions.
332 changes: 329 additions & 3 deletions Luminescent_AI_docs.ipynb

Large diffs are not rendered by default.

31 changes: 0 additions & 31 deletions luminescent/a/splitter.py

This file was deleted.

1 change: 1 addition & 0 deletions luminescent/luminescent/sol.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def run(cmd):
env = '0;'
# cmd = ["lumi", path]
gpu_backend = prob["gpu_backend"]
run(["julia", "-e", f'println(Base.active_project())'])
if not gpu_backend:
cmd = ["julia", "-e", f'{env}using Luminescent;picrun(raw"{path}")']
else:
Expand Down
13 changes: 13 additions & 0 deletions luminescent/tiny.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os
import luminescent as lumi
from gdsfactory.generic_tech import LAYER, LAYER_STACK
import gdsfactory as gf
import numpy as np

c = gf.components.straight(length=.1, width=0.5, layer=LAYER.WG)
wavelengths = 1.55
path = os.path.join("runs", "tiny")
lumi.make_pic_sim_prob(path, c, wavelengths=wavelengths, keys=[
"2,1"], nres=15, approx_2D_mode="TE", gpu="CUDA") # approx_2D_mode="TE")
# lumi.solve(path)
# sol = lumi.lumi_solution()
8 changes: 0 additions & 8 deletions src/core/gpu.jl

This file was deleted.

2 changes: 1 addition & 1 deletion src/core/monitors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct MonitorInstance <: AbstractMonitorInstance
λmodes
tags
end
@functor MonitorInstance (λmodes,)
@functor MonitorInstance (λmodes, deltas)
Base.ndims(m::MonitorInstance) = m.d
area(m::MonitorInstance) = m.v
wavelengths(m::MonitorInstance) = keys(m.λmodes)
Expand Down
2 changes: 2 additions & 0 deletions src/core/update.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ function update(u, p, t, dt, field_diffdeltas, field_diffpadvals, source_instanc
dHdt = -(∇ × E + H m) μ
H += dHdt * dt

@ignore_derivatives gc()
# @ignore_derivatives unsafe_free!.((Js, dEdt, dHdt))
# (; E, H, (Jkeys .=> Jm)..., (Pkeys .=> Pm)...)
namedtuple([:E => E, :H => H, (Jkeys .=> Jm)..., (Pkeys .=> Pm)...])
end
1 change: 1 addition & 0 deletions src/del.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function diffpad(a, vl, vr=vl; dims=1, diff=diff)
r = !isnothing(vr)

sz = Tuple(size(a) + (l + r - 1) * sel)
# b = similar(a, sz)
b = Buffer(a, sz)
b[range.(l * sel + 1, sz - r * sel)...] = diff(a; dims)
pad!(b, vl, l * sel, 0)
Expand Down
3 changes: 3 additions & 0 deletions src/gpu.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

unsafe_free!(a) = 0
unsafe_free!(a::CUDA.CuArray) = CUDA.unsafe_free!(a)
4 changes: 3 additions & 1 deletion src/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ include("pic/run.jl")

include("ops.jl")
include("del.jl")
# include("main.jl")
# include("main.jl")

include("gpu.jl")
5 changes: 3 additions & 2 deletions src/pic/run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function picrun(path; gpuarray=nothing, kw...)
frame = frame .>= 0.99maximum(frame)
# frame = nothing
start = round((bbox[1] - lb) / dl + 1)
b = Blob(szd; solid_frac=0.95, morph=false, lsolid=lsolid / dl, lvoid=lvoid / dl, symmetries, F, frame, start)
b = Blob(szd; solid_frac=0.99, morph=false, lsolid=lsolid / dl, lvoid=lvoid / dl, symmetries, F, frame, start)
display(heatmap(b.frame))

if !isnothing(sol) && !restart
Expand Down Expand Up @@ -182,8 +182,9 @@ function picrun(path; gpuarray=nothing, kw...)
end
t0 = time()
lb3 = (lb..., zmin)
# error("not implemented")
println("compiling simulation code...")
if study == "sparams"
println("simulating...")
@unpack S, sols = make_pic_sim_prob(runs, run_probs, lb, dl;
F, verbose=true, framerate, path)
plotsols(sols, run_probs, path)
Expand Down
4 changes: 3 additions & 1 deletion src/pictest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ ENV["JULIA_PKG_PRECOMPILE_AUTO"] = 0
# picrun(joinpath("runs", "straight");)# gpuarray=cu)
# picrun(joinpath("runs", "bend_R5"))
# picrun(joinpath("runs", "mode_converter"))
picrun(joinpath("runs", "demux"))
# picrun(joinpath("runs", "demux"))
# picrun(joinpath("runs", "splitter"))

using CUDA
picrun(joinpath("runs", "tiny"); gpuarray=cu)
1 change: 0 additions & 1 deletion src/sim/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ function setup(dl, boundaries, sources, monitors, deltas, mode_deltas;
geometry, _geometry, nmax, nmin, ϵeff,
is_field_on_lb, is_field_on_ub,
u0, dt, kw...) |> pairs |> OrderedDict

end
update = update
setup = setup
15 changes: 13 additions & 2 deletions src/sim/solve.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
function tidy(t, dt)
if round(t) > round(t - dt)
println("simulation time = $t, took $(timepassed()) seconds")
end
end

function f1(((u,), p, (dt, field_diffdeltas, field_diffpadvals, source_instances)), t)
u = update(u, p, t, dt, field_diffdeltas, field_diffpadvals, source_instances)
tidy(t, dt)
@time u = update(u, p, t, dt, field_diffdeltas, field_diffpadvals, source_instances)
((u,), p, (dt, field_diffdeltas, field_diffpadvals, source_instances))
end

function f2(((u, mf), p, (dt, field_diffdeltas, field_diffpadvals, source_instances), (t0, T, monitor_instances)), t)
u = update(u, p, t, dt, field_diffdeltas, field_diffpadvals, source_instances;)
tidy(t, dt)
@time u = update(u, p, t, dt, field_diffdeltas, field_diffpadvals, source_instances;)
mf += [[
begin
c = dt / T * cispi(-2(t - t0) / λ)
Expand Down Expand Up @@ -39,10 +47,12 @@ function solve(prob, ;
init = (us0, p, (dt, field_diffdeltas, field_diffpadvals, source_instances))

ts = 0:dt:T[1]-F(0.001)
nt = -1
if save_memory
(u,), = adjoint_reduce(f1, ts, init, ulims)
else
(u,), = reduce(ts; init) do us, t

ignore() do
if framerate > 0 && t > 0
if t % (1 / framerate) < dt
Expand All @@ -63,6 +73,7 @@ function solve(prob, ;
ts = ts[end]+dt:dt:T[2]-F(0.001)
init = ((u, 0), p, (dt, field_diffdeltas, field_diffpadvals, source_instances), (T[2], durations[2], monitor_instances))

println("accumulating dft fields")
if save_memory
(u, mf), = adjoint_reduce(f2, ts, init, ulims)
else
Expand Down

0 comments on commit 1505e5d

Please sign in to comment.