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

fix for lucas/fields_in_mode_data #1368

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/notebooks
Submodule notebooks updated 108 files
15 changes: 7 additions & 8 deletions tests/test_plugins/test_adjoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1649,16 +1649,15 @@ def make_sim(eps):
if not has_adj_src:
monkeypatch.setattr(JaxModeData, "to_adjoint_sources", lambda *args, **kwargs: [])

def J(x):
sim = make_sim(eps=x)
data = run(sim, task_name="test", path=str(tmp_path / RUN_FILE))
x = 2.0
sim = make_sim(eps=x)
data = run(sim, task_name="test", path=str(tmp_path / RUN_FILE))

# check whether we got a warning for no sources?
with AssertLogLevel(log_capture, log_level_expected, contains_str="No adjoint sources"):
data.make_adjoint_simulation(fwidth=src.source_time.fwidth, run_time=sim.run_time)
power = jnp.sum(jnp.abs(jnp.array(data["mnt"].amps.values)) ** 2)
return power

grad_J = grad(J)
grad_J(2.0)
assert_log_level(log_capture, log_level_expected)
power = jnp.sum(jnp.abs(jnp.array(data["mnt"].amps.values)) ** 2)


def test_nonlinear_warn(log_capture):
Expand Down
7 changes: 6 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,12 @@ def make_mode_data(monitor: td.ModeMonitor) -> td.ModeData:
coords_amps = dict(direction=["+", "-"])
coords_amps.update(coords_ind)
amps = make_data(coords=coords_amps, data_array_type=td.ModeAmpsDataArray, is_complex=True)
return td.ModeData(monitor=monitor, n_complex=n_complex, amps=amps)
return td.ModeData(
monitor=monitor,
n_complex=n_complex,
amps=amps,
grid_expanded=simulation.discretize_monitor(monitor),
)

MONITOR_MAKER_MAP = {
td.FieldMonitor: make_field_data,
Expand Down