Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animate2D for OptimizationProblem #2186

Merged
merged 9 commits into from
Sep 1, 2022
18 changes: 13 additions & 5 deletions python/adjoint/optimization_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ def __init__(
minimum_run_time=0,
maximum_run_time=None,
finite_difference_step=utils.FD_DEFAULT,
step_funcs: list = None,
):

self.step_funcs = step_funcs if step_funcs is not None else []
self.sim = simulation

if isinstance(objective_functions, list):
Expand Down Expand Up @@ -184,15 +185,17 @@ def forward_run(self):
if any(isinstance(m, LDOS) for m in self.objective_arguments):
self.sim.run(
mp.dft_ldos(self.frequencies),
*self.step_funcs,
until_after_sources=mp.stop_when_dft_decayed(
self.decay_by, self.minimum_run_time, self.maximum_run_time
),
)
else:
self.sim.run(
*self.step_funcs,
until_after_sources=mp.stop_when_dft_decayed(
self.decay_by, self.minimum_run_time, self.maximum_run_time
)
),
)

# record objective quantities from user specified monitors
Expand Down Expand Up @@ -254,9 +257,10 @@ def adjoint_run(self):

# Adjoint run
self.sim.run(
*self.step_funcs,
until_after_sources=mp.stop_when_dft_decayed(
self.decay_by, self.minimum_run_time, self.maximum_run_time
)
),
)

# reset the m number
Expand Down Expand Up @@ -376,15 +380,17 @@ def calculate_fd_gradient(
if any(isinstance(m, LDOS) for m in self.objective_arguments):
self.sim.run(
mp.dft_ldos(self.frequencies),
*self.step_funcs,
until_after_sources=mp.stop_when_energy_decayed(
dt=1, decay_by=1e-11
),
)
else:
self.sim.run(
*self.step_funcs,
until_after_sources=mp.stop_when_dft_decayed(
self.decay_by, self.minimum_run_time, self.maximum_run_time
)
),
)

# record final objective function value
Expand All @@ -409,15 +415,17 @@ def calculate_fd_gradient(
if any(isinstance(m, LDOS) for m in self.objective_arguments):
self.sim.run(
mp.dft_ldos(self.frequencies),
*self.step_funcs,
until_after_sources=mp.stop_when_energy_decayed(
dt=1, decay_by=1e-11
),
)
else:
self.sim.run(
*self.step_funcs,
until_after_sources=mp.stop_when_dft_decayed(
self.decay_by, self.minimum_run_time, self.maximum_run_time
)
),
)

# record final objective function value
Expand Down
Loading